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

RE: [amibroker] apply n-bar stops



PureBytes Links

Trading Reference Links

Unfortunately you do have to program the exit price yourself for all 3 stops.  The n-bar exit price is over ridden by your calculated exit (sell) price just as AB support has advised.  It only works automatically if you are exiting on the open or close as defined in the AA settings.

 

It’s a bit annoying I agree but you can get around it with coding.  I would also like some sort of function included with the nbar stop to set the exit price, but until then lets try & code it.  (note Metastock is the same, it provides a time stop but the exit price must be calculated properly).  Actually I find it easier to program my own time stop anyway.

 

Try this as example…

// Trade delays all zero

 

EntryTrigger = Cross(ma(C,5), ma(C,50));   // Example only….

 

EntryPrice = High;  // entry if go above todays high, example of stop entry

 

Buy = ref(EntryTrigger,-1) and H >= ref(EntryPrice,-1);  // Stop entry code

 

BuyPrice = max(Open, EntryPrice); 

 

// Note, don’t forget to account for time difference between conditions & entry day

 

StopExit = LLV(L,3);  // Trailing stop ext, lowest low of 3 days

ExitatStop = L <= ref(StopExit,-1);   // Intraday exit

 

ProfitTarget = C + 1.5*atr(5);  //  Profit target based on yesterday’s close + delta

 

ProfitExit = H >= ref(ProfitTarget,-1);  // intraday exit

 

timeStop = 5;  //  time stop on 5th day, (exit day is day 5 & exit at open)

TimeExit = barssince(Buy) >= timestop;

 

Sell = ExitatStop or ProfitExit or TimeExit;

 

// now calculate the exit price, don’t forget to give preference to time exit first since I am assuming you will get out at open, then stop exit as worst case, then profit target last;

//  you could get trickier if you want & check which way the open starts, & exit at profit if open gaps above.  This code will be more conservative.  I’ll leave that to you to figure out.

 

SellPrice = IIF(TimeExit, Open, IIF(ExitatStop, min(Open, ref(StopExit,-1)), Max(Open, ref(ProfitTarget,-1)));

 

 

Hope that helps..

 

Regards, Dave

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___