ProOrder / Indicator inconsistency

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #108641 quote
    tested4perfection
    Participant
    Average

    Dear forum members,

    I have been back-testing a strategy I’ve been working on and I’ve used the exact same code for the ProOrder as I have in my indicator.

    However, when I compare the trades with my indicator, I can clearly see inconsistencies here and there. They are not big, but they fail entries or create entries that should not have occured in my indicators. I can follow the problem by using Graph and comparing the outcome of the different parts of the back-test parameters with my indicators. As mentioned, they are identical in code.

    I have set the DEFPARAMPRELOADBARS = 0

    This is to make sure that the code in the backtest doesn’t preload any bars. I understand that the indicator shouldn’t preload either – at least it doesn’t look like it.

     

    Any idea why I get this inconsistency?

    Thanks

    #108644 quote
    Nicolas
    Keymaster
    Master

    What indicator please? What is the maximal period used in its calculation? Any picture of that difference you get?

    #108646 quote
    jebus89
    Participant
    Master

    Its more or less impossible to help/answer without more context.

     

    Please show code if possible so we can test it, or at least show indicator code and or photos of the failed/missed entries with more explanation.

    99% of the time i experience this, its my own fault and after posting in this forum ive been corrected. Feelsgoodman.jpeg

    #108671 quote
    tested4perfection
    Participant
    Average

    Hi,

    I looked at my code for hours till my eyes were bleeding early this morning. It’s a complex code that takes a lot of values at the first bars, and this affects everything, so I did a short test and found there IS A DIFFERENCE between indicators and back-testing. Namely – 1 bar difference.

    I have intentionally put in PreloadBars = 0 as I thought this was messing with my code. No difference. So I put a conditional BarIndex entry and found the culprit.

    Have a look:

    __________________________________________________________________

    IF BarIndex > 14 THEN
    ATR = AverageTrueRange[14](CLOSE)
    
    ENDIF
    
    RETURN ATR

     

    __________________________________________________________________

     

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    DEFPARAM PRELOADBARS = 0
    
    IF BarIndex > 14 THEN
    ATR = AverageTrueRange[14](CLOSE)
    Trange = TR(CLOSE)
    ENDIF
    
    IF Trange > ATR THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    IF Trange < ATR THEN
    SELL AT MARKET
    ENDIF
    
    GRAPH ATR

     

    __________________________________________________________________

    Compare the SNAFU indicator with FUBAR graph output.

    If I change the BarIndex > 13 in the Indicator SNAFU – then it all works out the same. But if I leave it at 14 on both, – I get one bar displacement. That means that my indicator would not show me the same exit / entry as I would expect in the ProOrder FUBAR at the early bars.

    I take it that the 0(zero) bar in BarIndex for indicator SNAFU is differently accounted for when relating to ProOrder back-test and that puts the whole calculation of bars one step later in indicator.

    Question is how this affects strategies relying on settings at the first bars? Everything will be skewed as the count of Bars is messed up. Maybe averages will even out over time, but for me counting close and open and relating to these, it is completely out of sync! I get totally different appearances on Indicator and ProOrder.

    #108674 quote
    Nicolas
    Keymaster
    Master

    What platform version? Did you try to remove (close) at the end of the ATR instruction?, if not please try.

    #108675 quote
    tested4perfection
    Participant
    Average

    Hi,

    I tried removing CLOSE command without success. I’m running on 10.3

    #108679 quote
    tested4perfection
    Participant
    Average

    I can confirm this is a discrepancy solely based on bars. BarIndex(0) is counted in the indicator as a bar, which it is not in Back-Testing as it is an incomplete bar I guess. So those are totally out of sync.

    This makes back-testing very odd when analysing the outcome! Unfortunately I see this as a bug! Especially as they are time-lined so that you should be able to follow what happens in the back-test versus your price AND indicators. And if you use the same indicator as a trigger for the action – you would expect the same outcome, which is extremely perplexing when you define PRELOADBARS = 0. I’m coding a ZeroBarCorrection of + 1 in everything that could cause this problem for now. It solves the problem for now…

    Surprised no one has reacted on this until now…

    Not sure if it is fixed in version 11.

    Regarding version 11…I can’t do back-testing as I have no IG connection… since it is not supported by IG… which… by the looks of it… won’t be happening for another… year???

    #108680 quote
    robertogozzi
    Moderator
    Master

    Your code above:

    IF BarIndex > 14 THEN
       ATR = AverageTrueRange[14](CLOSE)
       Trange = TR(CLOSE)
    ENDIF

    will calculate ATR when BarIndex = 15 (or greater), so it will scan the last 14 bars (2 through 15) to make the calculations, while replacing 14 with 13 will calculate it on bars 1-14.

    BarIndex starts from 0, so to calculate 14 bars starting from bars 0 you should replace > 14 with > 12.

    #108684 quote
    tested4perfection
    Participant
    Average

    Hi,

    I see your point. However the snippet of code is not part of the indicator, it is merely to show the inconsistency. My first line is actually an equaliser formula to be able to use ONCE command for variables.

    For simplicity, in my code I use ATRperiod as a value (14)

    ATRperiod = 14
    IF BarIndex = ATRperiod THEN
       ATR = AverageTrueRange[ATRperiod](CLOSE)
    ENDIF

    And in the ProOrder I use

    BarZeroCorrection = 1
    ATRperiod = 14
    IF BarIndex + BarZeroCorrection = ATRperiod THEN
         ATR = AverageTrueRange[ATRperiod](CLOSE)
    ENDIF

    I find this to be easier to address when reading the code as the problem is that BarIndex[0] that causes the problem!

    #108685 quote
    robertogozzi
    Moderator
    Master

    Try not using ONCE in your indicator.

    #108686 quote
    tested4perfection
    Participant
    Average

    Well… this specific indicator requires it  🙂

    #108687 quote
    robertogozzi
    Moderator
    Master

    Replace ONCE with:

    If barindex = 0 then
       MyVariable = ...
    Endif
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.

ProOrder / Indicator inconsistency


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by robertogozzi
6 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/27/2019
Status: Active
Attachments: No files
Logo Logo
Loading...