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

[amibroker] average profit bar (%)



PureBytes Links

Trading Reference Links





I am sharing my code that calculates 
average profit bar (%) during a trade.
This can be used as a trailing stop. 
Any improvement or new ideas will be appreciated.
J

SetTradeDelays(<FONT color=#ff00ff 
size=1>1,1<FONT 
size=1>,1,<FONT 
color=#ff00ff size=1>1);<FONT 
color=#008000 size=1>
//STATE
InLong = Flip( 
Buy, Sell OR Short );
InShort = Flip( 
Short, Buy OR Cover );
State = IIf( InLong, 
1, <FONT 
color=#0000ff size=1>IIf( InShort, -<FONT 
color=#ff00ff size=1>1, <FONT color=#ff00ff 
size=1>0 ));
//TRAILING STOP - MAE
Elong=<FONT 
face="Courier New" color=#0000ff size=1>IIf<FONT face="Courier New" 
size=1>(Ref<FONT 
face="Courier New" size=1>(state,-<FONT face="Courier New" color=#ff00ff 
size=1>1)==<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>,ValueWhen<FONT 
size=1>(Ref<FONT 
face="Courier New" size=1>(Buy,-<FONT face="Courier New" 
color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>),O),<FONT face="Courier New" color=#ff00ff 
size=1>0);
Eshort=IIf<FONT 
face="Courier New" size=1>(<FONT face="Courier New" color=#0000ff 
size=1>Ref(state,-<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>)==-1<FONT 
face="Courier New" size=1>,<FONT face="Courier New" color=#0000ff 
size=1>ValueWhen(<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(Short,-<FONT face="Courier New" color=#ff00ff 
size=1>1),O),<FONT 
face="Courier New" color=#ff00ff size=1>0<FONT face="Courier New" 
size=1>);
zz=IIf<FONT 
face="Courier New" size=1>(<FONT face="Courier New" color=#0000ff 
size=1>Ref(state==<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>,-1<FONT 
face="Courier New" size=1>),(O-elong)*<FONT face="Courier New" 
color=#ff00ff size=1>50,<FONT 
face="Courier New" color=#0000ff size=1>IIf<FONT face="Courier New" 
size=1>(Ref<FONT 
face="Courier New" size=1>(Sell,-<FONT face="Courier New" 
color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>),(O-<FONT face="Courier New" color=#0000ff 
size=1>Ref(elong,-<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>))*50<FONT 
face="Courier New" size=1>,<FONT face="Courier New" color=#ff00ff 
size=1>0));
ss=IIf<FONT 
face="Courier New" size=1>(<FONT face="Courier New" color=#0000ff 
size=1>Ref(state==-<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>,-1<FONT 
face="Courier New" size=1>),(eshort-O)*<FONT face="Courier New" 
color=#ff00ff size=1>50,<FONT 
face="Courier New" color=#0000ff size=1>IIf<FONT face="Courier New" 
size=1>(Ref<FONT 
face="Courier New" size=1>(Cover,-<FONT face="Courier New" 
color=#ff00ff size=1>1),(<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(eshort,-<FONT face="Courier New" color=#ff00ff 
size=1>1)-O)*<FONT 
face="Courier New" color=#ff00ff size=1>50<FONT face="Courier New" 
size=1>,0<FONT 
face="Courier New" size=1>));
MAEL=IIf<FONT 
face="Courier New" size=1>(<FONT face="Courier New" color=#0000ff 
size=1>Ref(Sell,-<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>),((zz/<FONT face="Courier New" color=#0000ff 
size=1>BarsSince(<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(Buy,-<FONT face="Courier New" color=#ff00ff 
size=1>1)))/<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(elong,-<FONT face="Courier New" color=#ff00ff 
size=1>1))*<FONT 
face="Courier New" color=#ff00ff size=1>100<FONT face="Courier New" 
size=1>,((zz/<FONT face="Courier New" color=#0000ff 
size=1>BarsSince(<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(Buy,-<FONT face="Courier New" color=#ff00ff 
size=1>1)))/elong)*<FONT 
face="Courier New" color=#ff00ff size=1>100<FONT face="Courier New" 
size=1>);
MAES=IIf<FONT 
face="Courier New" size=1>(<FONT face="Courier New" color=#0000ff 
size=1>Ref(Cover,-<FONT 
face="Courier New" color=#ff00ff size=1>1<FONT face="Courier New" 
size=1>),((ss/<FONT face="Courier New" color=#0000ff 
size=1>BarsSince(<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(Short,-<FONT face="Courier New" color=#ff00ff 
size=1>1)))/<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(eshort,-<FONT face="Courier New" color=#ff00ff 
size=1>1))*<FONT 
face="Courier New" color=#ff00ff size=1>100<FONT face="Courier New" 
size=1>,((ss/<FONT face="Courier New" color=#0000ff 
size=1>BarsSince(<FONT 
face="Courier New" color=#0000ff size=1>Ref<FONT face="Courier New" 
size=1>(Short,-<FONT face="Courier New" color=#ff00ff 
size=1>1)))/eshort)*<FONT 
face="Courier New" color=#ff00ff size=1>100<FONT face="Courier New" 
size=1>);
Plot(<FONT face="Courier New" 
size=1>MAes,<FONT color=#ff00ff 
size=1>"lb",<FONT face="Courier New" 
size=1>colorRed,<FONT face="Courier New" 
size=1>styleHistogram);<FONT color=#0000ff 
size=1>
Plot(<FONT face="Courier New" 
size=1>MAEL,<FONT color=#ff00ff 
size=1>"lb",21<FONT 
size=1>,styleHistogram<FONT 
size=1>);






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.