I believe there are many problems with this code. To your specific question, time bars are marked with the beginning of the time or the end of the time, but not both. So, if you are setting the variable CerrarPosis == 155959 then code will never see that time if your database is set to display beginning of bar time.
As to the other problems, Amibroker is an array processing system and you cannot set an array based on the same array. It just doesn't work right. Example: Short = Short AND !shorted AND !bought; I suggest you build a loop and use temporary variables (myBuy, mySell, etc.) to get setup since you can changed values as above using a loop. Then after all your conditions are checked assign the "real" Buy after the loop. Buy = myBuy; Sell = MySell, It is also my understanding that you cannot have multiple Buy = statements (same for Sell, Short, Cover) since these trigger an internal backtest procedure. By setting them more than once, you are calling the backtest procedure multiple times. I really don't know what happens if you do this, but I have found it not to work. -- Terry -----Original Message----- From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Roberto Martinez Sent: Saturday, October 28, 2006 10:15 To: [email protected]; [email protected] Subject: [amibroker-ts] Need help with this code pls 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("estil o")); 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] [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/
