Backtesting and demo account algo doesn’t match live algo?
Forums › ProRealTime English forum › ProOrder support › Backtesting and demo account algo doesn’t match live algo?
- This topic has 2 replies, 2 voices, and was last updated 3 years ago by Nicolas.
-
-
08/19/2021 at 11:10 AM #175689
Hello, I have recently been screwed over by an algorithm for a reason that I cannot determine, I wonder whether anyone can help shed some light on the situation…
I am running an algorithm on both my live and demo accounts, mostly because I forgot to stop it on my demo account. When I backtest this algorithm it displays a small loss this morning, a large gain yesterday and a handful of other trades over the past few weeks. By contrast, the algorithm running on my demo account did not make any trades at all in the last couple of days, and the algorithm running on my live account made a big loss on a trade that ran both yesterday and today.
Is the platform broken? Why would a demo account and a live account make different trades using the same algorithm? Why would the backtest, even when running in tick-by-tick mode, show trades that didn’t happen, or not show trades that did happen? I am very confused about this whole thing, I know that a backtest isn’t 100% perfect but over 2 days it should be fairly accurate, right? Not showing a £300 gain when I actually made a £244 loss? Is there anything I can do to fix this that I might be missing?
I have attached the algorithm that I have been running on 30m GBP/USD. Disclaimer, I did not write it, I just ran a decent amount of tests against it and had it in a demo account for a few months.
08/19/2021 at 11:14 AM #175691I have not read your strategy code yet, but attached is a non-exhaustive list of the elements that can impact a live trading strategy and create differences with a demo account and/or backtests, that could help you:
- Spread
- Slippage
- Orders rejections due to one of the above reason, but also because of the allowed distance from current price to put pending orders (known as “minimal distance”)
- Different trading hours (ProOrder code launched in a different time zone / custom hours, by the user)
- Coding problem: division by zero error, null or negative periods for indicators, ..
- Lack of responsiveness of IG demo servers (if IG is the broker), although this has improved considerably since last year.
- Make backtests without tick-by-tick option
- “set stop trailing” instruction that give IG the total control of your stoploss, can be moved differently between accounts due to points above
- Limited risk accounts and their rules
- Guaranteed stoploss rules and fees
- Starting a strategy at a different time (1 hour or even 1 minute later): depending on the code of the strategy, the results of some calculations could be different.
- Margin required on the trading account (no demo or backtest tests are made on this subject)
- Overnight and overweekend fees
Because backtests are only tested on history *with no connection to live market* , you may encounter differences with real live trading environment subject to spread enlargement, slippage, etc. If your stop hasn’t move, there must be information of an error into your orders rejected list you can consult with CTRL+O.IG orders list history may be also helpful!08/19/2021 at 11:18 AM #175692Here is the full code for convenient read:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869// Definizione dei parametri del codiceDEFPARAM CumulateOrders = FalseTimeStart = time >= 000000TimeStop = time <= 240000// Le giornate come 1 maggio, 24, 25, 26, 30 e 31 dicembre, i sabati e le domeniche sono esclusiGiornoTrading= NOT((Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31) OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0))ONCE SIZE = 2 // nr. contrattiONCE NDBARLIMIT = 3 // NR. OF BARS ON WHICH THE ORDER STOP REMAINS VALIDONCE PXT = Pointsize // es. per EURUSD = 0.00001; per EURJPY = 0.001 per DAX = 1AA = period // PERIOD OF LINEAR REGRESSION AND 1° PERIOD OF STOCHASTIC --> OTTIMIZZARE FROM 20 TO 300 STEP 10SSTOC = SmoothedStochastic[AA,AA/4](Close)SUT = SuperTrend[3,10]// TREND - NO TRENDt=(LinearRegressionSlope[AA](close)-0)*SQRT(AA-2)/(STE[AA](close)/STD[AA](Barindex))if t<1.96 thenbeta=0elsebeta=1endif// Condizioni per entrare longC1 = SSTOC[1] <= 30 AND SSTOC[0] > SSTOC[1] AND beta = 0 // No Trend = SWINGIF C1 thenOPENBUY = HIGH[0]+ 2*PXTMYINDEX = BarindexENDIFIF Barindex >= MYINDEX + NDBARLIMIT THENOPENBUY = 0ENDIFIF OPENBUY > 0 AND NOT LONGONMARKET AND GiornoTrading and TimeStart and TimeStop THENBUY SIZE CONTRACTS AT OPENBUY STOP// si fissano stoploss e targetprofitST=((LOWEST[10](LOW))-OPENBUY)/PXTIF ST > 150 OR ST <=0 THEN // Max stoploss in pointST = 150ENDIFSET STOP pLOSS STENDIF// Condizioni per uscire da posizioni LongIF LongOnMarket AND (Close[1]>SUT[1] AND Close<SUT) then // change color of supertrend = close positionSELL at MarketENDIF// Condizioni per entrare shortC21 = SSTOC[1] >= 70 AND SSTOC[0] < SSTOC[1] AND beta = 0 // No Trend = SWINGIF C21 thenOPENSELL = LOW[0]- 2*PXTMYINDEX = BarindexENDIFIF Barindex >= MYINDEX + NDBARLIMIT THENOPENSELL = 0ENDIFIF OPENSELL > 0 AND NOT SHORTONMARKET AND GiornoTrading and TimeStart and TimeStop THENSELLSHORT SIZE CONTRACTS AT OPENSELL STOP// si fissano stoploss e targetprofitST=(OPENSELL-(HIGHEST[10](HIGH)))/PXTIF ST > 150 OR ST <= 0 THENST = 150ENDIFSET STOP pLOSS STENDIF//Condizioni per uscire da posizioni ShortIF ShortOnMarket AND (Close[1]<SUT[1] AND Close>SUT) then // change color of supertrend = close positionEXITSHORT at MarketENDIFTry to change line 13 with:
1SSTOC = SmoothedStochastic[AA,round(AA/4)](Close)to prevent period with decimal!
-
AuthorPosts
Find exclusive trading pro-tools on