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();


[Non-text portions of this message have been removed]




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker-ts/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker-ts/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to