difference limit order backtest and live
Forums › ProRealTime English forum › ProOrder support › difference limit order backtest and live
- This topic has 19 replies, 4 voices, and was last updated 6 years ago by
Paul.
-
-
09/09/2018 at 7:05 PM #80039
Hi,
It’s about the dax 30 cash €1,- at a 1 minute timeframe and the Big Line Strategy Code.
To this code I’ve made small modifications compared to the one published in the library.
The code of the Big Line Strategy, it works using a market order.
But if you use a limit order then it works correctly in a live trading environment, but not in a back test.
Tick mode on or off don’t show a difference.
So why does the back test with a limit order not work correctly?
More specific, i.e. why does the back test skip a trade at 5 September 2018 at 11.24, but the same code in a live trading environment gets correctly activated?
Maybe I missed something and hope for some feedback.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199//-------------------------------------------------------------------------// Main code : Big Line Strategy//-------------------------------------------------------------------------// common rulesDEFPARAM CUMULATEORDERS = falseDEFPARAM PRELOADBARS = 10000// optionalBreakEvenStop = 0 // BreakEvenStop and BreakEvenStop Minimum GainMFETrailing = 1 // MFETrailing// time rulesONCE entertime = 090000 //ONCE lasttime = 133000ONCE closetime = 240000 // greater then 23.59 means it continues position overnightONCE closetimeFriday=173000tt1 = time >= entertimett2 = time <= lasttimetradetime = tt1 and tt2DayForbidden = 5 // no new entry on Fridaydf = dayofweek <> dayforbidden// positionsize and stopspositionsize = 1sl = 1.00 // % Stoplosspt = 1.50 // % Profit Targetts = 1.20 // % MFETrailingbs = 1.00 // % BreakEvenStopbsm= 0.00 // % BreakEvenStop Minimum Gain// setup number of trades intradayif IntradayBarIndex = 0 thenlongtradecounter = 0Shorttradecounter = 0endif// general criteriaGeneralCriteria = tradetime and df and (barindex > tradeindex+1)// trade criteriatcLong = countoflongshares < 1 and longtradecounter < 1tcShort = countofshortshares < 1 and shorttradecounter < 1// line criteriaCurrentPrice = round(dclose(1))MPmod = 100Factor = 100 // defines linesAboveLevel0 = CurrentPrice mod MPmodStartLevel = CurrentPrice - AboveLevel0Level00Up = StartlevelLevel10Up = StartLevel + (1*Factor)Level20Up = StartLevel + (2*Factor)Level30Up = StartLevel + (3*Factor)Level40Up = StartLevel + (4*Factor)Level50Up = StartLevel + (5*Factor)Level60Up = StartLevel + (6*Factor)Level70Up = StartLevel + (7*Factor)Level80Up = StartLevel + (8*Factor)Level90Up = StartLevel + (9*Factor)Level00Down = StartlevelLevell0Down = StartLevel - (1*Factor)Level20Down = StartLevel - (2*Factor)Level30Down = StartLevel - (3*Factor)Level40Down = StartLevel - (4*Factor)Level50Down = StartLevel - (5*Factor)Level60Down = StartLevel - (6*Factor)Level70Down = StartLevel - (7*Factor)Level80Down = StartLevel - (8*Factor)Level90Down = StartLevel - (9*Factor)l0 = close crosses over Level00Up or close crosses over Level00Downl1 = close crosses over Level10Up or close crosses over Levell0Downl2 = close crosses over Level20Up or close crosses over Level20Downl3 = close crosses over Level30Up or close crosses over Level30Downl4 = close crosses over Level40Up or close crosses over Level40Downl5 = close crosses over Level50Up or close crosses over Level50Downl6 = close crosses over Level60Up or close crosses over Level60Downl7 = close crosses over Level70Up or close crosses over Level70Downl8 = close crosses over Level80Up or close crosses over Level80Downl9 = close crosses over Level90Up or close crosses over Level90Downs0 = close crosses under Level00Down or close crosses under Level00Ups1 = close crosses under Levell0Down or close crosses under Level10Ups2 = close crosses under Level20Down or close crosses under Level20Ups3 = close crosses under Level30Down or close crosses under Level30Ups4 = close crosses under Level40Down or close crosses under Level40Ups5 = close crosses under Level50Down or close crosses under Level50Ups6 = close crosses under Level60Down or close crosses under Level60Ups7 = close crosses under Level70Down or close crosses under Level70Ups8 = close crosses under Level80Down or close crosses under Level80Ups9 = close crosses under Level90Down or close crosses under Level90Up// trade criteria extramin1 = MIN(dhigh(0),dhigh(1))min2 = MIN(dhigh(1),dhigh(2))max1 = MAX(dlow(0),dlow(1))max2 = MAX(dlow(1),dlow(2))tcxLong = high < MIN(min1,min2)tcxShort = low > MAX(max1,max2)// long entryIf GeneralCriteria thenIf tcLong and tcxLong thenif (l0 or l1 or l2 or l3 or l4 or l5 or l6 or l7 or l8 or l9) thenlongtradecounter=longtradecounter + 1buy positionsize contract at high[1] limitendifendifendif// short entryIf GeneralCriteria thenif tcShort and tcxShort thenif (s0 or s1 or s2 or s3 or s4 or s5 or s6 or s7 or s8 or s9) thenshorttradecounter=shorttradecounter + 1sellshort positionsize contract at low[1] limitendifendifendif// BreakEvenStopIf BreakEvenStop thenif not onmarket thennewSL=0endifIf longonmarket and close-tradeprice(1)>=((tradeprice/100)*bs)*pipsize thennewSL = tradeprice(1)+((tradeprice/100)*bsm)*pipsizeendifIf shortonmarket and tradeprice(1)-close>=((tradeprice/100)*bs)*pipsize thennewSL = tradeprice(1)-((tradeprice/100)*bsm)*pipsizeendifIf newSL>0 thensell at newSL Stopexitshort at newSL Stopendifendif// MFETrailingIf MFETrailing thentrailingstop = (tradeprice/100)*tsif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endifif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=trailingstop*pipsize thenpriceexit = MAXPRICE-trailingstop*pipsizeendifendifif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=trailingstop*pipsize thenpriceexit = MINPRICE+trailingstop*pipsizeendifendifIf onmarket and priceexit>0 thensell at marketexitshort at marketendifendif// exit at closetimeIf onmarket thenif time >= closetime thensell at marketexitshort at marketendifendif// exit friday at set closetimeif onmarket thenif (CurrentDayOfWeek=5 and time>=closetimefriday) thensell at marketexitshort at marketendifendif// build-in exitif BreakEvenStop=0 thenSET STOP %LOSS slelsif BreakEvenStop=1 thenSET STOP %LOSS bsmendifSET TARGET %PROFIT pt//GRAPH 0 coloured(300,0,0) AS "zeroline"//GRAPH (positionperf*100)coloured(0,0,0,255) AS "PositionPerformance"09/09/2018 at 7:26 PM #8004009/09/2018 at 8:24 PM #8004409/09/2018 at 8:52 PM #8004709/09/2018 at 9:01 PM #8004909/09/2018 at 9:08 PM #8005009/09/2018 at 9:37 PM #8005209/10/2018 at 7:53 AM #8006109/10/2018 at 3:14 PM #80115Thanks for the help guys.
I ‘am running version v10.3 – 1.8.0_45 on a Mac (last update 30 july 2018)
That’s the version which does the backtest and the live trading.
The code has 1 point spread and tickmode is activated.
@GraHal
For 30 sec TF, I got the same as you, it entered a trade.
Also on 5 minutes it entered a trade at 11.25 my time on 5 sept.
But how’ is the 1 minute 10.24 your time zone?
Of this code interesting timeframes are 1, 3 and 30 minutes with 200k backtest. I attached the screenshot. The 30min is a bit zoomed in.
Also attached a screenshot of the 1 minute bar which is has my focus in this case.
I need to understand why the trade got skipped in backtest and get’s activated correctly live. It renders the back-test useless otherwise.
09/10/2018 at 4:09 PM #8012009/11/2018 at 1:55 AM #80137Correct
The order in a back test does not get triggered only on the 1-minute TF when it’s a limit order. (5 September 2018 11:24:00)
details;
Close crosses the big line at 11.23 and meets all criteria
The limit order refers to high[1] which at 11.22 is 12.100,2.
The low at 11.24 is 12.100,2
A limit high[1] means buy at 12.100,2 or lower at the 11.24 bar, which traded 12.100.2
09/11/2018 at 7:22 AM #80140The spread on the DAX (DFB) is normally 1.0 at the time of the trade so this is the most likely reason that the trade did not open. The prices shown on the chart are mid prices (i.e halfway between the buy and sell prices). The mid price would need to have reached 12099.7 for a buy trade to have opened at 12100.2
09/11/2018 at 7:25 AM #8014109/11/2018 at 8:11 AM #80151What about a backtest without spread?
Sorry – too early and not enough coffee yet. I just re-read the posts and now see that the problem is ‘the trade got skipped in backtest and get’s activated correctly live’ and that the OP tested with a 1.0 pip spread. A back test without spread should open the trade and so would be a nice test to try.
09/11/2018 at 1:49 PM #80166 -
AuthorPosts
Find exclusive trading pro-tools on