Yes , I am backtesting futures , to precise FW20 ( WIG20 FUT - warsaw index ). I 've insert afl code and than I 've done everything as you said.
--- In [email protected], "Edward Pottasch" <empotta...@...> wrote: > > are you backtesting futures? > > maybe have a look at this settings window. Maybe you need to set Min. Shares > to 1, round lot size to 1. > > > > > From: mateusz.krysiak > Sent: Tuesday, April 06, 2010 6:32 PM > To: [email protected] > Subject: [amibroker] Re: Bernstein's CTOD as daytrading system- help with afl > code > > > > I've already fill information window but still backtesting doesn't work > properly. Only "Scan" option gives any result, but they are completly > different from that what system shows. > > Regards > Mateusz > > --- In [email protected], "Edward Pottasch" <empottasch@> wrote: > > > > the code is setup to backtest futures a single future or a portfolio of > > single futures. What you need to do is fill in the "information" window for > > each symbol. > > > > For instance for the ES future you need: > > TickSize = 0.25; > > PointValue = 50; > > MarginDeposit = 5000; > > RoundLotSize = 1; > > > > you can put this information inside the code or in the information window, > > see: http://www.amibroker.com/guide/h_fundamental.html > > > > if you want to backtest stocks you basicly only have to make some changes > > in the following: > > > > for instance: > > > > SetBarsRequired(sbrAll,sbrAll); > > SetOption("CommissionMode", 3); > > SetOption("MaxOpenPositions", 100 ); > > PositionSize = -100; > > SetTradeDelays(0,0,0,0); > > SetOption("CommissionAmount", 0.005); > > > > instead of: > > > > SetBarsRequired(sbrAll,sbrAll); > > SetTradeDelays(0,0,0,0); > > SetOption("CommissionMode", 3); > > SetOption("FuturesMode",True); > > NumContracts = 1; > > PositionSize = NumContracts * MarginDeposit; > > SetOption("MaxOpenPositions", 10); > > SetOption("CommissionAmount", 2.4); > > > > and check the settings window of the Automatic Analysis window. > > > > regards, Ed > > > > > > > > > > From: mateusz.krysiak > > Sent: Tuesday, April 06, 2010 5:11 PM > > To: [email protected] > > Subject: [amibroker] Re: Bernstein's CTOD as daytrading system- help with > > afl code > > > > > > > > Great, but something is wrong during backtest. There number of transactions > > is 0. I would be pleased if you could help me with preparing the code to > > make backtest :) > > > > Greetings > > Mateusz > > > > --- In [email protected], "Edward Pottasch" <empottasch@> wrote: > > > > > > ok no problem. Added small correction to code. This code is for intraday > > > data, supposed to use 5 minute timeframe. I assume the opening hour is > > > 093000 and closing hour is 160000, rgds, Ed > > > > > > > > > procedure > > > buySellShortCover_proc(Buy,BuyPrice,Short,ShortPrice,lowLastHour,highLastHour,rsiPer,timearr,endtime) > > > { > > > > > > global BuyAdjusted; > > > global BuyPriceAdjusted; > > > global ShortAdjusted; > > > global ShortPriceAdjusted; > > > global SellAdjusted; > > > global SellPriceAdjusted; > > > global CoverAdjusted; > > > global CoverPriceAdjusted; > > > > > > BuyAdjusted = 0; > > > BuyPriceAdjusted = 0; > > > ShortAdjusted = 0; > > > ShortPriceAdjusted = 0; > > > SellAdjusted = 0; > > > SellPriceAdjusted = 0; > > > CoverAdjusted = 0; > > > CoverPriceAdjusted = 0; > > > > > > delay = 1; > > > slip = TickSize * 0; > > > > > > for( i = 1; i < BarCount; i++ ) > > > { > > > > > > if (Buy[ i ]) > > > { > > > > > > BuyAdjusted[ i ] = 1; > > > BuyPriceAdjusted[ i ] = BuyPrice[ i ] + slip; > > > > > > for (j = i + delay; j < BarCount; j++) > > > { > > > > > > // exit at end of day > > > if (timearr[ j - 1 ] >= endtime) > > > { > > > > > > SellAdjusted[ j ] = 1; > > > SellPriceAdjusted[ j ] = O[ j ] - slip; > > > i = j; > > > break; > > > > > > } > > > // stop exit > > > else if (Short[ j ]) > > > { > > > > > > SellAdjusted[ j ] = 1; > > > SellPriceAdjusted[ j ] = O[ j ] - slip; > > > i = j - 1; > > > break; > > > > > > } > > > // stop exit > > > else if (C[ j - 1 ] < lowLastHour[ j - 1 ]) > > > { > > > > > > SellAdjusted[ j ] = 1; > > > SellPriceAdjusted[ j ] = O[ j ] - slip; > > > i = j; > > > break; > > > > > > } > > > // stop exit > > > else if (rsiPer[ j - 1 ] < 20) > > > { > > > > > > SellAdjusted[ j ] = 1; > > > SellPriceAdjusted[ j ] = O[ j ] - slip; > > > i = j; > > > break; > > > > > > } > > > // to avoid problems at the end of the array > > > else if (j == BarCount - 1) > > > { > > > > > > i = BarCount; > > > > > > } > > > } > > > } > > > else if (Short[ i ]) > > > { > > > > > > ShortAdjusted[ i ] = 1; > > > ShortPriceAdjusted[ i ] = ShortPrice[ i ] - slip; > > > > > > for (j = i + delay; j < BarCount; j++) > > > { > > > > > > // exit at end of day > > > if (timearr[ j - 1 ] >= endtime) > > > { > > > > > > CoverAdjusted[ j ] = 1; > > > CoverPriceAdjusted[ j ] = O[ j ] + slip; > > > i = j; > > > break; > > > > > > } > > > // stop exit > > > else if (Buy[ j ]) > > > { > > > > > > CoverAdjusted[ j ] = 1; > > > CoverPriceAdjusted[ j ] = O[ j ] + slip; > > > i = j - 1; > > > break; > > > > > > } > > > // stop exit > > > else if (C[ j - 1 ] > highLastHour[ j - 1 ] ) > > > { > > > > > > CoverAdjusted[ j ] = 1; > > > CoverPriceAdjusted[ j ] = O[ j ] + slip; > > > i = j; > > > break; > > > > > > } > > > // stop exit > > > else if (rsiPer[ j - 1 ] > 80) > > > { > > > > > > CoverAdjusted[ j ] = 1; > > > CoverPriceAdjusted[ j ] = O[ j ] + slip; > > > i = j; > > > break; > > > > > > } > > > // to avoid problems at the end of the array > > > else if (j == BarCount - 1) > > > { > > > > > > i = BarCount; > > > > > > } > > > } > > > } > > > } > > > > > > } > > > > > > // http://www.scribd.com/doc/7408934/the-compleat-day-trader-vol-i > > > // start and end time of the range over which to calculate the max and > > > min price > > > startTimeRange = 093000; > > > endTimeRange = 113000; > > > > > > // start and end time for trading > > > startTradeTime = endTimeRange; > > > endTradeTime = 160000; > > > > > > timeWindowRange = TimeNum() >= startTimeRange AND TimeNum() <= > > > endTimeRange; > > > timeWindowTrade = TimeNum() >= startTradeTime AND TimeNum() <= > > > endTradeTime; > > > > > > firstBarOfRange = TimeNum() >= startTimeRange ;firstBarOfRange = > > > firstBarOfRange - Ref(firstBarOfRange,-1); > > > lastBarOfDay = TimeNum() >= endtimeRange;lastBarOfDay = lastBarOfDay - > > > Ref(lastBarOfDay,-1); > > > > > > DH = ValueWhen(timeWindowRange,HighestSince(firstBarOfRange,High)); > > > DL = ValueWhen(timeWindowRange,LowestSince(firstBarOfRange,Low)); > > > > > > // the next 4 lines may be commented out. They are just added for visual > > > purpose > > > DH = TimeFrameCompress(DH, inDaily, compressLast); > > > DL = TimeFrameCompress(DL, inDaily, compressLast); > > > DH = TimeFrameExpand( DH, inDaily, expandFirst ); > > > DL = TimeFrameExpand( DL, inDaily, expandFirst ); > > > > > > Buy = Cross(C,DH) * timeWindowTrade; Buy = Ref(Buy,-1); BuyPrice = O; > > > Short = Cross(DL,C) * timeWindowTrade; Short = Ref(Short,-1); ShortPrice > > > = O; > > > > > > // high / low of the last hour. In the 5 min chart 1 hour is 12 bars > > > lowLastHour = Ref(LLV(L,12),-1); > > > highLastHour = Ref(HHV(H,12),-1); > > > > > > // rsi(15) > > > rsiPer = RSI(15); > > > > > > buySellShortCover_proc(Buy,BuyPrice,Short,ShortPrice,lowLastHour,highLastHour,rsiPer,TimeNum(),endTradeTime); > > > > > > Buy = BuyAdjusted; > > > BuyPrice = BuyPriceAdjusted; > > > Short = ShortAdjusted; > > > ShortPrice = ShortPriceAdjusted; > > > Sell = SellAdjusted; > > > SellPrice = SellPriceAdjusted; > > > Cover = CoverAdjusted; > > > CoverPrice = CoverPriceAdjusted; > > > > > > SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) ); > > > SetChartOptions(0, chartShowDates); > > > Plot(C,"\nC",ParamColor("ColorC", ColorRGB( 254, 255, 255 ) > > > ),styleCandle); > > > > > > Plot(IIf(timeWindowRange,DH,Null),"\nDH Window > > > Range",ParamColor("ColorDHr",ColorRGB(255,0,0)),styleThick); > > > Plot(IIf(timeWindowRange,DL,Null),"\nDL WIndow > > > Range",ParamColor("ColorDLr",ColorRGB(0,255,0)),styleThick); > > > Plot(IIf(timeWindowTrade,DH,Null),"\nDH Window > > > Trade",ParamColor("ColorDHt",ColorRGB(255,100,0)),styleDashed); > > > Plot(IIf(timeWindowTrade,DL,Null),"\nDL Window > > > Trade",ParamColor("ColorDLt",ColorRGB(100,255,0)),styleDashed); > > > > > > Plot(lowLastHour,"\nlowLastHour",ParamColor("ColorLLH",ColorRGB(30,144,255)),styleDashed); > > > Plot(highLastHour,"\nhighLastHour",ParamColor("ColorHLH",ColorRGB(255,127,36)),styleDashed); > > > > > > PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorGreen,0,L,-15); > > > PlotShapes(IIf(Buy,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15); > > > PlotShapes(IIf(Buy,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0); > > > > > > PlotShapes(IIf(Sell,shapeDownArrow,shapeNone),colorRed,0,H,-15); > > > PlotShapes(IIf(Sell,shapeHollowDownArrow,shapeNone),colorWhite,0,H,-15); > > > PlotShapes(IIf(Sell,shapeHollowSmallCircle,shapeNone),colorWhite,0,SellPrice,0); > > > > > > PlotShapes(IIf(Short,shapeDownTriangle,shapeNone),colorYellow,0,H,IIf(Short > > > AND Sell,-30,-15)); > > > PlotShapes(IIf(Short,shapeHollowDownTriangle,shapeNone),colorWhite,0,H,IIf(Short > > > AND Sell,-30,-15)); > > > PlotShapes(IIf(Short,shapeHollowCircle,shapeNone),colorWhite,0,ShortPrice,0); > > > > > > PlotShapes(IIf(Cover,shapeUpTriangle,shapeNone),colorLightBlue,0,L,IIf(Cover > > > AND Buy,-30,-15)); > > > PlotShapes(IIf(Cover,shapeHollowUpTriangle,shapeNone),colorWhite,0,L,IIf(Cover > > > AND Buy,-30,-15)); > > > PlotShapes(IIf(Cover,shapeHollowCircle,shapeNone),colorWhite,0,CoverPrice,0); > > > > > > Plot(timeWindowRange,"",ParamColor("ColorWindowRange",ColorRGB(35,35,35)),styleArea|styleOwnScale,0,1); > > > > > > > > > SetBarsRequired(sbrAll,sbrAll); > > > SetTradeDelays(0,0,0,0); > > > SetOption("CommissionMode", 3); > > > SetOption("FuturesMode",True); > > > NumContracts = 1; > > > PositionSize = NumContracts * MarginDeposit; > > > SetOption("MaxOpenPositions", 10); > > > SetOption("CommissionAmount", 2.4); > > > > > > > > > > > > > > > From: MarkK > > > Sent: Tuesday, April 06, 2010 1:08 PM > > > To: [email protected] > > > Subject: RE: [amibroker] Bernstein's CTOD as daytrading system- help with > > > afl code > > > > > > > > > > > > > > > Thank you for posting the AFL > > > > > > It does not come through as a cohesive afl though. Is it possible for you > > > for copy and paste it in the text? It looks as if Yahoo did something to > > > your original afl when you put it as an attachment > > > > > > > > > > > > Thank you > > > > > > > > > > > > Mark > > > > > > > > > > > > > > > > > > From: [email protected] [mailto:[email protected]] On > > > Behalf Of Edward Pottasch > > > Sent: Tuesday, April 06, 2010 6:30 AM > > > To: [email protected] > > > Subject: Re: [amibroker] Bernstein's CTOD as daytrading system- help with > > > afl code [1 Attachment] > > > > > > > > > > > > > > > > > > [Attachment(s) from Edward Pottasch included below] > > > > > > hi, > > > > > > > > > > > > you are on the right track but there are multiple ways to solve such a > > > problem in Amibroker. I have some standard codes for these type of > > > problems. The problem seems simple but with all the exit contraints I > > > find it easiest to use an exit loop. I add my code but again there are > > > other ways to solve it that might look easier. I tested this setup on > > > futures but it does not seem to be profitable. > > > > > > > > > > > > regards, Ed > > > > > > > > > > > > chart how it looks like > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > From: mateusz.krysiak > > > > > > Sent: Sunday, April 04, 2010 1:20 PM > > > > > > To: [email protected] > > > > > > Subject: [amibroker] Bernstein's CTOD as daytrading system- help with afl > > > code > > > > > > > > > > > > > > > > > > hello > > > I' am a amibroker beginner. I 've spend a lot of time looking through the > > > internet , but I didn't find nothing similar to this. So i gave up and > > > decided to ask for help. Of the point: > > > I want to create a afl code which would reflect CTOD intraday system ( > > > Critical time of day)- p. > > > 186[http://www.scribd.com/doc/7408934/the-compleat-day-trader-vol-i] . > > > The assumtions of system : > > > > > > - buy if 5 minute bar close above max from 2 hours after session start ( > > > 5 minute close) > > > > > > - short if 5 minute bar close below max from 2 hours after session start > > > (5 minute close) > > > > > > - buy works as both cover and opens new postiion > > > - short works as sell and opens new postions > > > > > > Two different ways in two different systems closing positions > > > > > > 1) Close postion = time 16.06. ( few minutes before session close) or if > > > RSI (15) cross "20" (sell) and "80" (cover) > > > > > > 2) Close if 5min bar close below/ above max/min from last one Hour. > > > > > > I have only something like this : > > > > > > // > > > > > > ForceCloseTradesAfter = 160600; > > > > > > Buy=Cross(C,Ref(HHV(C,24),-1)); // It should be better to replace HHV by > > > Bar since or Value when ? > > > > > > Sell=Cross(Ref(LLV(C,24),-1),C) OR (TimeNum() > ForceCloseTradesAfter); > > > // > > > > > > greetings > > > > > > Mateusz > > > > > >
