Pro order different from probacktest

Viewing 15 posts - 1 through 15 (of 42 total)
  • Author
    Posts
  • #189194 quote
    josward1
    Participant
    New

    hello, I have a discrepancy between pro backtest and pro order. They mostly seem synchronised but only on the loosing trades. the live code took a few loosing trades that the backtest didn’t take. And the live code hardly took any of  the winning trades that the backtest did take which which reduces a 45% accurate backtest down to 2% accurate on live. I overcompensated for the spread on the backtest to account for a bit of slippage here and there.

    The code is exactly the same I run a backtest and then from there prepare for automated trading and run them side by side to compare the difference.

    Is there anything I can do to resolve this? or are these codes not able to replicate a backtest on live money?

    I found it funny how the discrepancy was the live code only took loosing trades and not one winning trade and not the other way round.  is there anything behind this or is it just bad luck?

    #189197 quote

    Hi, you have ticked by tick mode

    Cat.png Cat.png
    #189207 quote
    josward1
    Participant
    New

    I have tested the results both with and without tick by tick mode there’s hardly any difference in results

    #189209 quote
    GraHal
    Participant
    Master

    Have you got both Longs and Shorts position size > minimum size for the Instrument you are trading?

    Have you got spread set in backtest engine at same value as the strategy will experience when trading live?

    #189214 quote
    josward1
    Participant
    New

    Thanks for your reply. Yes, i have checked the minimum trade size for the asset and set it to that. and i have backtested the code with a larger spread than it will be on live so if anything it should be better.

    The majority of the issue seems to be on execution, the live is taking all of the loosing trades the backtest takes but doesn’t get into the trades that win. Also the live code got stopped out of a few winning trades before they went on to win whereas the backtest code didn’t get stopped out and went on to win. The spread is higher on my backtest than on the live to make sure i am testing for the wort possible case scenario.

    #189215 quote
    GraHal
    Participant
    Master

    You’ve not said what is the Instrument?

    If it’s Forex then you may be getting a lot of flash (few milliseconds) widening of the spread and that is hitting your stop, whereas no such flash spread occurs in backtest.  Add the Indicator – Bid Ask band to yuor chart and you can see the flash wideing of the spread!

    If you post your code on here then I would run it on my platform and see if I come up with anything?

    But also the coding wizards on here would take a look at your code and advise any oddities likely to cause issues.

    #189216 quote
    PeterSt
    Participant
    Master

    Is there anything I can do to resolve this? or are these codes not able to replicate a backtest on live money?

    Hi there Jos,

    Please take it from me that a backtest can be equal to live for, say 95 out of the 100 trades. Thus, 95 out of 100 will be equal to the penny.
    BUT
    Those 5 not equal will create a completely different flow/sequence of the further trades. And this is the first you did not see through yet (with respect of course).
    Try this, in order to see what I mean : Start a Live system with little money, and start a Backtest with the same money and code. Take care that the first trade is synchronised in both (fiddle with the start time of the backtest in order to get there). The backtest will now run in “forward test” mode. Thus, just  let it be and see what it does. Now, according to yourself you *will* see that a next order (starting with the exit and otherwise a next entry) will not be synchronised any more in both Live and Forward-Backtest). This is the point where I want you to be, because from that point on you will see that all your arguments for “not the same result” are moot.

    All even includes you highering the spread in the backtest and expecting less profit from there. Eh, no; instead, all will be apples and oranges because the trade sequence is going to be different, and actually it is close to 50% whether you will make more or less money with the higher spread (on the very long term less for sure indeed).

    If you, as GraHal asked, would show us the code in full, you can bet that we will be working on it to give you the hints on what the culprits and pitfalls could theoretically be (we won’t be executing your code in Live). Also hand the timeframe of the chart and indeed the instrument you run it on.

    An almost infinite reasons exist allowing your backtest results to be be different from Live and this is mostly related to our perception of how markets are and react. You will undoubtedly see responses like “yea, no wonder, because you challenge for …” etc. (it is useless to give real examples at this moment). But … I am afraid that you will also see that whatever it exactly is that’s going off, mostly can’t be tackled by you. This is related to the enormous amount of time involved to get it right on one hand, and the required creativity and coding skills on the other. And we can’t demand from anyone that he can spend this time and has all the skills. And for example, possibly all people reading about my said “95 out of 100” will say, “yea sure !” (not believing that at all).

    As far as I can tell myself, there’s at least one area where the backtesting will be off compared to reality : accumulated orders. PRT’s backtesting engine lacks the proper features for maintaining the gain accurately so much so, that I can’t get it to “synchronise” with even a single trade (a first does not end up equal, therefore does not end up equally in time, and therefore the sequence hence trades are not the same from the start). Once could also attest that now my own creativity etc. has its limits, or I just did not find the way.

    Apologies for all the blathering, but I think it’s all good things to know for everyone, especially the mere beginners with AutoTrading.
    Regards,
    Peter

    GraHal thanked this post
    #189230 quote

    You always have to start the backtest with the same day and time as when you put in Live, only in this way you are able to evaluate if there are any problems.
    So for example, if you start the live on March 9, 2022 at 10.00 also the backtest you have to do everything the same.
    Hello
    Mauro

    #189252 quote
    josward1
    Participant
    New

    Thankyou  all for your replies I really appreciate the help. I paid for this code to be done so that I can turn on and off different indicators and change parameters over multiple timeframes so that I can easily tailor the code to different assets using a range of tools. So I will explain clearly on here what exactly this is supposed to be doing so that you can ignore the rest and hone in on the parts being used.

    Timeframe 3 minutes

    buy trade to be taken when:

    EMA 3 > EMA6 [by 2 pips]

    EMA6 > EMA9 [by 8 pips]

    Price crosses over upper bollingerband [period 5] [standard dev 1.0]

    sell trade to be taken

    EMA 3 < EMA6 [by 2 pips]

    EMA6 < EMA9 [by 8 pips]

    Price crosses under lower bollingerband [period 5] [standard dev 1.0]

    Stop loss – 9

     Trailing stop – 7

    Risk-reward – 10  [the strategy is to get taken out by the trailing stop]

    If the signal is larger than 20pips take trade on 50% retracement of next candle [only]

     

    It doesn’t actually take the trades exactly how I want it to, even on the backtest so I think something is wrong on there somewhere, however I figured if it produces good results then it will be good to use anyway.

    The idea behind the strategy is for the code to detect short term buying and selling pressure and take an entry around where price is pushing hence the use of the bollinger band or 1 or 2 period EMA also works. And I want the code to execute the trade as it’s pushing with a tight trailing stop loss. And choosing an asset such as the NASDAQ that moves a long way allows to make a larger pip gain with short moves than say a forex pair. also the Spread for the NASDAQ is 1-2 pips the majority of the time.

    The code doesn’t actually seem to be taking the trades I feel that it should be taking when I’m looking at the charts.  I thought maybe the “signal larger than” parameter what causing the issue I have tried it without and it’s still not right. If you could take a look for me that would be great and please ask any further questions you might have.

     

    Thanks

    Nasdaq-live.2.itf
    #189265 quote
    GraHal
    Participant
    Master

    This is better as then the coding wizards do not have to import to their platforms etc

    //v1.1 - the 2 RSi strategies and stochastic strategy to include the MA conditions
    
    defparam cumulateorders=false
    
    //timeframe(15 minutes,updateonclose)
    sma50d = exponentialaverage[5]
    sma90d = exponentialaverage[8]
    sma200d = exponentialaverage[13]
    ema90d = exponentialaverage[90]
    ema200d = exponentialaverage[200]
    dailybuyc = sma50d-sma90d>dailyMA50MA90Distance*pointsize and sma90d-sma200d>dailyMA90MA200Distance*pointsize
    dailysellc = sma90d-sma50d>dailyMA50MA90Distance*pointsize and sma200d-sma90d>dailyMA90MA200Distance*pointsize
    
    //timeframe(3 minutes,updateonclose)
    sma50h4 = exponentialaverage[3]
    sma90h4 = exponentialaverage[6]
    sma200h4 = exponentialaverage[9]
    ema90h4 = exponentialaverage[55]
    ema200h4 = exponentialaverage[89]
    h4buyc = sma50h4<sma90h4 and sma90h4<sma200h4
    h4sellc = sma50h4>sma90h4 and sma90h4>sma200h4
    
    //timeframe(3 minutes,updateonclose)
    sma50m15 = exponentialaverage[3]
    sma90m15 = exponentialaverage[6]
    sma200m15 = exponentialaverage[9]
    ema90m15 = exponentialaverage[55]
    ema200m15 = exponentialaverage[89]
    m15buyc = sma50m15-sma90m15>m15MA50MA90Distance*pointsize and sma90m15-sma200m15>m15MA90MA200Distance*pointsize
    m15sellc = sma90m15-sma50m15>m15MA50MA90Distance*pointsize and sma200m15-sma90m15>m15MA90MA200Distance*pointsize
    
    //timeframe(default)
    if rsistrategy then //rsi jump trade entry
    irsi = rsi[rsiperiod]
    buyc1 = (dailybuyc and h4buyc and m15buyc) and ((irsi[1]<RSIcross1Level1 and irsi>RSIcross1Level2) OR (irsi[1]<RSIcross2Level1 and irsi>RSIcross2Level2) OR (irsi[1]<RSIcross3Level1 and irsi>RSIcross3Level2) OR (irsi[1]<RSIcross4Level1 and irsi>RSIcross4Level2) OR (irsi[1]<RSIcross5Level1 and irsi>RSIcross5Level2))
    sellc1 = (dailysellc and h4sellc) and ((irsi[1]>RSIcross1Level2 and irsi<RSIcross1Level1) OR (irsi[1]>RSIcross2Level2 and irsi<RSIcross2Level1) OR (irsi[1]>RSIcross3Level2 and irsi<RSIcross3Level1) OR (irsi[1]>RSIcross4Level2 and irsi<RSIcross4Level1) OR (irsi[1]>RSIcross5Level2 and irsi<RSIcross5Level1))
    endif
    if mastrategy then  //moving average trade entry
    BB     = 5                                 //20   periods
    BBdev  = 1.0                                //2.0  standard deviation
    BBavg  = average[BB,0](close)               //BB mean (middle line)
    UPboll = BBavg + ((std[BB](close)) * BBdev) //BB Upper Band
    LOboll = BBavg - ((std[BB](close)) * BBdev) //BB Lower Band
    macrossbuy = open crosses over UPboll
    macrosssell = open crosses under LObolL
    buyc2 =  m15buyc and macrossbuy
    sellc2 = m15sellc and macrosssell
    endif
    if rsimultiplestrategy then //rsi multiple cross entry
    rsi1 = rsi[rsiper1]
    rsi2 = rsi[rsiper2]
    rsi3 = rsi[rsiper3]
    buyc3 = (dailybuyc and h4buyc) and ((rsi1 crosses over rsi1over1 and rsi2 crosses over rsi2over1 and rsi3 crosses over rsi3over1) or (rsi1 crosses over rsi1over2 and rsi2 crosses over rsi2over2 and rsi3 crosses over rsi3over2) or (rsi1 crosses over rsi1over3 and rsi2 crosses over rsi2over3 and rsi3 crosses over rsi3over3))
    sellc3 = (dailysellc and h4sellc) and ((rsi1 crosses under rsi1under1 and rsi2 crosses under rsi2under1 and rsi3 crosses under rsi3under1) or (rsi1 crosses under rsi1under2 and rsi2 crosses under rsi2under2 and rsi3 crosses under rsi3under2) or (rsi1 crosses under rsi1under3 and rsi2 crosses under rsi2under3 and rsi3 crosses under rsi3under3))
    endif
    if stochasticstrategy then //stochastic entry
    sto = Stochastic[stokperiod,stoksmoothing](close)
    buyc4 = (dailybuyc and h4buyc and m15buyc) and (sto crosses over stoover1 or sto crosses over stoover2 or sto crosses over stoover3)
    sellc4 = (dailysellc and h4sellc and m15sellc) and (sto crosses under stounder1 or sto crosses under stounder2 or sto crosses under stounder3)
    endif
    
    // --- orders
    lotsize = 1
    if not longonmarket and (buyc1 or buyc2 or buyc3 or buyc4) then
    if range>SignalLargerThan*pointsize then
    buy lotsize contract at high-range*.5 stop
    else
    buy lotsize contract at market
    endif
    endif
    if not shortonmarket and (sellc1 or sellc2 or sellc3 or sellc4) then
    if range>SignalLargerThan*pointsize then
    sellshort lotsize contract at low+range*.5 stop
    else
    sellshort lotsize contract at market
    endif
    endif
    
    // --- tp & sl
    if trailingstopenable then
    sl = trailingstopsize
    set stop ptrailing sl
    else
    sl = stoplossdistance
    set stop ploss sl
    endif
    set target pprofit sl*RiskRewardRatio
    
    //graph (dailybuyc and h4buyc and m15buyc)
    
    PeterSt thanked this post
    #189266 quote
    GraHal
    Participant
    Master

    I’m surpised it runs at all as lotsize, trailingstopsize and stoplossdistance (Lines 66 to 84) are not defined anywhere?

    When I click on above in the code editor, the highllighter only shows the one instance of above (4 in the case of lotsize).

    Am I missing a trick here?? 🙂

    #189268 quote
    GraHal
    Participant
    Master

    Note: I defined lotsize = 1 at Line 63.

    This weirder and weirder … ‘google find’ says there are 13 mentions of lotsize on the page, I can see 8 and 3 of those are in my text. Google find is not highlighting the other 5 anywhere!?

    Is above a new way of hiding code or should I have gone to specsavers!!?? 🙂

    #189269 quote
    GraHal
    Participant
    Master

    Is above a new way of hiding code

    Yes it is GraHal … they are hidden in the optimiser as variables!! doh to me!!! 🙂

    I’ve got so used to my variables names being Line numbers (A10, B26 … etc) I was blind to varables as names!

    Specsavers, ring ring  … appointment please!! 🙂

    #189285 quote
    josward1
    Participant
    New

    Yes the reason for this is why I attached the file because there is deeper coding that you can’t see on a simple copy and paste. If you import the code you will see all of the missing values in the variable optimisation tab

    #189286 quote
    GraHal
    Participant
    Master

    I have a discrepancy between pro backtest and pro order

    It be good if you post your backtests results then we can start investigations from the same baseline?

Viewing 15 posts - 1 through 15 (of 42 total)
  • You must be logged in to reply to this topic.

Pro order different from probacktest


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
josward1 @josward1 Participant
Summary

This topic contains 41 replies,
has 5 voices, and was last updated by PeterSt
3 years, 11 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/02/2022
Status: Active
Attachments: 23 files
Logo Logo
Loading...