Hi to everyone, I´m coding a trading system based on the opening range (OR) breakout. The idea is to take the opening range for a given time and then enter long on the brek of the high of the OR or enter short on the break of the low of the OR. It just trades ONE time a day. So if I enter long that is the only trade for the day. Th stop is on the other side of the OR. And also if at the end of the session I have the position open i must close it. I´ve almost get the code but have a bit problem and i´m not able to solve it. The problem is the following: on a day when i´m stopped out before the end of the session, the system still closes a position ant EOD. I don´t see where the problem is, so I beg you help. You can see the code below.

Thanks a lot. ;-)

 

_SECTION_BEGIN("BREAKOUT_V1");

PositionSize = MarginDeposit = 1;

MarketOpen = Param("Market Open",153000,000000,235959,1);

MarketClose = Param("Market Close",215959,000000,235959,1);

OpenRangeEnd = Param("OpenRangeEnd",163000,000000,235959,1);

CerrarPosis = Param("Cerrar Posiciones",220000,000000,235959,1);

MarketHours = deFlagTimeRange(OpenRangeEnd, MarketClose);

cierrePosis = deFlagLastBarOfDay(CerrarPosis);

//Opening Range

ORHigh = deTimeRangeHHV(H,MarketOpen,OpenRangeEnd);

ORLow = deTimeRangeLLV(L,MarketOpen,OpenRangeEnd);

ORMedian = (ORHigh+ORLow)/2;

//opening range plot

ORHighClean = IIf(MarketHours,ORHigh,Null);

ORLowClean = IIf(MarketHours,ORLow,Null);

ORMedianClean = IIf(MarketHours,ORMedian,Null);

//how to open positions code

Buy = H > ORHigh AND MarketHours;

Short = L < ORLow AND MarketHours;

bought = Ref(deTimeRangeHHV(Buy,MarketOpen,MarketClose),-1);

shorted = Ref(deTimeRangeHHV(Short,MarketOpen,MarketClose),-1);

Buy = Buy AND !bought AND !shorted;

Short = Short AND !shorted AND !bought;

//how to close positions code

Sell = L < ORLow AND bought AND MarketHours;

Cover = H > ORHigh AND shorted AND MarketHours;

sold = Ref(deTimeRangeHHV(Sell,MarketOpen,MarketClose),-1);

covered = Ref(deTimeRangeHHV(Cover,MarketOpen,MarketClose),-1);

Sell = Sell AND !sold;

Cover = Cover AND !covered;

//close postions end of day if not closed before

Sell = IIf(bought AND cierrePosis AND bought AND !Sold, 1, Sell);

Cover = IIf(cierrePosis AND shorted AND !Covered, 1, Cover);

sold = Ref(deTimeRangeHHV(Sell,MarketOpen,CerrarPosis),-1);

covered = Ref(deTimeRangeHHV(Cover,MarketOpen,CerrarPosis),-1);

//plot range

Plot(ORMedianClean,"OR_M",ParamColor("color",colorRed),ParamStyle("estilo"));

Plot(ORHighClean,"OR_H",ParamColor("color",colorRed),ParamStyle("estilo"));

Plot(ORLowClean,"OR_L",ParamColor("color",colorRed),ParamStyle("estilo"));

//plot arrows

PlotShapes(IIf(Buy,shapeUpArrow,shapeNone) ,colorBrightGreen);

PlotShapes(IIf(Sell,shapeDownArrow,shapeNone) ,colorBlue);

PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed);

PlotShapes(IIf(Cover,shapeUpArrow,shapeNone),colorBlue);

_SECTION_END();

__._,_.___

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





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

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

__,_._,___

Reply via email to