[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] RT portfolio trading P/L



PureBytes Links

Trading Reference Links




Since we have no 
method currently in AB, via the quote window,  to actually track the P/L of our 
open positions I spent a few minutes today coding a custom indicator. Certainly 
not rocket science but some of you may find this handy. I coded for 3 positions 
but you can add as many as you wish. Place it in a pane of of an existing chart 
or open a small window and float it on your AB desk top. Hopefully TJ will 
invent a better solution but for now this works. 
Regards, 
Jayson 
 
 
 
stock1="Dis";<FONT color=#000000 
face=Arial>//Enter the ticker here...use " "<FONT 
color=#000000>
entry1=21;<FONT 
color=#008000>//Enter your Purchase 
price<FONT 
color=#000000>
shares1=1000;<FONT 
color=#008000>//set to 0 if not currently in a 
position<FONT 
face=Arial>
State1=0;<FONT 
color=#000000 face=Arial size=2>// 1==long,0==short
 <FONT 
color=#000000>
stock2="ORCL"<FONT 
color=#000000 face=Arial size=2>;<FONT 
color=#000000>
entry2=12.<FONT 
color=#000000 face=Arial size=2>;
shares2=<SPAN 
class=360582618-27082003>2<SPAN 
class=360582618-27082003>000<FONT 
color=#000000 face=Arial size=2>;<FONT 
color=#000000>
State2=1<FONT color=#000000 
face=Arial>;
 <FONT 
face=Arial>
stock3="HD"<FONT 
color=#282828>;<FONT 
size=2>
entry3=32.<FONT 
color=#282828>;<FONT 
size=2>
shares3=000<FONT 
color=#000000 face=Arial size=2>;<FONT 
color=#000000>
State3=0<FONT color=#000000 
face=Arial size=2>;
 
// * calculates profit loss *// 

 <FONT 
color=#000000>
x1=IIf(state1,(Foreign(stock1,"C")-entry1)*shares1,(entry1-Foreign(stock1,"C"<FONT 
color=#282828><FONT color=#000000 face=Arial 
size=2>))*shares1);<FONT 
face=Arial>
x2=IIf(state2,(Foreign(stock2,"C")-entry2)*shares2,(entry2-Foreign(stock2,"C"<FONT 
color=#282828><FONT color=#000000 face=Arial 
size=2>))*shares2);<FONT 
face=Arial>
x3=IIf(state3,(Foreign(stock3,"C")-entry3)*shares3,(entry3-Foreign(stock3,"C"<FONT 
color=#282828><FONT color=#000000 face=Arial 
size=2>))*shares3);
x4=x1+x2+x3;
 
//* sets colors * //
 <FONT 
color=#000000>
Colorup=colorBrightGreen<FONT 
color=#282828>;<FONT 
size=2>
Colordn=colorRed<FONT 
color=#282828>;<FONT 
size=2>
Colortitle=colorWhite<FONT 
color=#282828>;
 
Title=stock1+" 
"+WriteIf<FONT 
color=#282828>(x1>0<FONT 
color=#282828>,EncodeColor<FONT 
color=#282828>(colorup)+WriteVal<FONT 
color=#282828>(x1,1.2<FONT 
color=#282828>),EncodeColor<FONT 
color=#282828>(colordn)+WriteVal<FONT 
color=#282828>(x1,1.2<FONT 
color=#282828>))+"\n"+ 
EncodeColor<FONT 
color=#282828>(colortitle)+stock2+" "<FONT 
color=#282828>+WriteIf<FONT 
color=#282828>(x2>0<FONT 
color=#282828>,EncodeColor<FONT 
color=#282828>(colorup)+WriteVal<FONT 
color=#282828>(x2,1.2<FONT 
color=#282828>),EncodeColor<FONT 
color=#282828>(colordn)+WriteVal<FONT 
color=#282828>(x2,1.2))+ 
EncodeColor<FONT 
color=#282828>(colortitle)+"\n"<FONT 
color=#282828> +stock3+" "<FONT 
color=#282828>+WriteIf<FONT 
color=#282828>(x3>0<FONT 
color=#282828>,EncodeColor<FONT 
color=#282828>(colorup)+WriteVal<FONT 
color=#282828>(x3,1.2<FONT 
color=#282828>),EncodeColor<FONT 
color=#282828>(colordn)+WriteVal<FONT 
color=#282828>(x3,1.2<FONT 
color=#282828>))+EncodeColor<FONT 
color=#282828>(colortitle)+"\n Total "<FONT 
color=#282828>+WriteIf<FONT 
color=#282828>(x4>0<FONT 
color=#282828>,EncodeColor<FONT 
color=#282828>(colorup)+WriteVal<FONT 
color=#282828>(x4,1.2<FONT 
color=#282828>),EncodeColor<FONT 
color=#282828>(colordn)+WriteVal<FONT 
color=#282828>(x4,1.2<FONT 
color=#282828>)); 
 
 
 
 






Yahoo! Groups Sponsor


  ADVERTISEMENT









Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html



Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.