Discrepency between Backtest and visual observation

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #261915 quote
    reb
    Participant
    Master

    Hi

    I’m a bit confused because I tried to code a simple idea :

    If price reaches S4 day (normal PP), I buy


    Here is the code:

    DEFPARAM CumulateOrders = False


    ONCE TradeToday = 0


    IF Date <> Date[1] THEN

    TradeToday = 0

    ENDIF


    // Autoriser les nouvelles entrées sauf après 17h30 le vendredi

    AutorisationEntree = 1


    IF DayOfWeek = 5 AND Time >= 173000 THEN

    AutorisationEntree = 0

    ELSIF Time <= 020000 then

    AutorisationEntree = 0

    ENDIF

    TimeFrame(Daily)


    PP = (High[1] + Low[1] + Close[1]) / 3

    S3 = Low[1] – 2*(High[1] – PP)

    S4 = Low[1] – 3*(High[1] – PP)

    S5 = Low[1] – 4*(High[1] – PP)


    TimeFrame(Default)


    IF NOT LongOnMarket AND TradeToday = 0 AND AutorisationEntree = 1 AND Low <= S4 THEN

    BUY 1 CONTRACT AT S4 LIMIT

    ENDIF


    IF LongOnMarket THEN

    TradeToday = 1

    SELL AT S5 STOP

    SELL AT S3 LIMIT

    ENDIF


    In using the backtest function, I notice some trades which shouldn’t exist

    Here are 4 examples of trades taken in “the middle of nowhere” compared with the levels given by PRT

    In total , the backtest has 11 trades in 2026, visual observation has only 5


    Is there an issue with my PP, S4 calculation compared with the platform ?


    Thanks in advance,


    Reb


    PS: subsidiary question how to code a stop limit order (ordre à plage de déclenchement) ?

    ex-1st-Jun-2026.jpg ex-1st-Jun-2026.jpg ex-4th-May-2026.jpg ex-4th-May-2026.jpg ex-12th-Jan-2026.jpg ex-12th-Jan-2026.jpg ex-9th-Feb-2026.jpg ex-9th-Feb-2026.jpg
    #261916 quote
    Nicolas
    Keymaster
    Legend

    Your daily timeframe declaration has no ‘updateonclose’.

    Therefore each read of the code in the inferior timeframe takes the high/ low values of the current day, while it should be from the previous day.

    reb thanked this post
    #261917 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    To check your PP S4 calculations, you can add at the end of the backtest:


    graphonprice PP as “PP”

    graphonprice S4 as “S4”


    Discrepencies displayed will give you clues. Considering all the examples you gave are on a monday, and considering the time conditions you are using would imply you are probably using IG and its 24h cfd assets, including a little sunday night data, the most likely cause (or at least one of the causes in case it doesn’t solve everything) would be that your monday pivot calculation is based on sunday data, where the platform displays on monday pivots based on friday data.

    If what you see thanks to the added “graphonprice” lines shows that’s the case, then you can try to replace this:


    TimeFrame(Daily)

    PP = (High[1] + Low[1] + Close[1]) / 3

    S3 = Low[1] – 2*(High[1] – PP)

    S4 = Low[1] – 3*(High[1] – PP)

    S5 = Low[1] – 4*(High[1] – PP)


    with this:


    TimeFrame(Daily)
    if opendayofweek>1 then
     PP = (High[1] + Low[1] + Close[1]) / 3
     S3 = Low[1] - 2*(High[1] - PP)
     S4 = Low[1] - 3*(High[1] - PP)
     S5 = Low[1] - 4*(High[1] - PP)
    else
     PP = (High[2] + Low[2] + Close[2]) / 3
     S3 = Low[2] - 2*(High[2] - PP)
     S4 = Low[2] - 3*(High[2] - PP)
     S5 = Low[2] - 4*(High[2] - PP)
    endif
    


    and then, check again thanks to the graphonprice lines if it got rid of pivot calculations discrepencies between code and platform.

    reb thanked this post
    #261918 quote
    JC_Bywan
    Moderator
    Master

    I don’t think it’s an updateonclose case on this one, because although it was written without updateonclose, the HLC data used in calculation in the timeframe(daily) bloc were all with [1] so previous day data indeed. Yes it could have been written with updateonclose (and then, without the [1]), but it wouldn’t solve the monday issue with the “sunday instead of friday” data.

    #261920 quote
    reb
    Participant
    Master

    Well done, I forgot those sunday data

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

Discrepency between Backtest and visual observation


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
reb @reb Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by reb
6 days, 1 hour ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/13/2026
Status: Active
Attachments: 4 files
Logo Logo
Loading...