I noticed an inconsistency before and wrote something relating to it, but I have now figured out specifically what it is and I would appreciate any input on this problem I’m dealing with.
When I backtest, I want to compare the entries and exits between my ProOrder code and the Indicator to make sure everything works as planned. However, I’ve noticed that some of these transactions occur when it shouldn’t have happened at all according to the indicator!
It seems that this is a problem between the counting of bars and specific commands.
When counting BarIndex in the Indicator, it starts with 0 (zero)
When counting BarIndex in ProOrder (for instance by using GRAPH command) it starts with 1!
This has a direct impact on for instance ATR and TR commands. TR won’t calculate on Bar 0 in Indicator, but will do so on Bar 1 in ProOrder – I have used DEFPARAM Preloadbars=0 !
Please see the picture enclosed.
The picture has 3 graphs. The red in the picture is the TR
1) Backtest – ATR is White
2) Normal result on Indicator – ATR is green
3) Modified coding for Indicator – ATR is blue
Please note how the TR (RED), and ATR green forms one bar later in the normal Indicator output.
How do you guys deal with such inconsistencies? This may be very specific for certain functions, but causes a huge difference for specific indicators in the beginning of the calculation.
Please note, in order to understand what was going on, I have used the true formula (with simplification) of calculating TR and ATR, and not the proprietary one. However, both 1) BackTest and 2) Indicator show exact same results using the default one.
ProOrder Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//Setting this to 0 to have same startup condition as Indicator
DEFPARAMPRELOADBARS=0
//Simplified Mathematical formula. Similar to TR function in PRC
TRM=MAX(HIGH,CLOSE[1])-MIN(LOW,CLOSE[1])
//Mathematical formula. Similar to AverageTrueRange function in PRC
ATR=AVERAGE[5,3](TRM)
GRAPHTRMCOLOURED(255,0,0)AS"TRM"
GRAPHATRCOLOURED(255,255,255)AS"ATR"
//EVERYTHING BELOW IS MOCK TO INITIATE BACKTESTING
BARCOUNT=BarIndex
IFNOTLongOnMarketANDBarCount>100000THEN
BUY1CONTRACTSATMARKET
ENDIF
IfLongOnMarketANDBarcount>200000THEN
SELLATMARKET
ENDIF
Indicator – Normal output
1
2
3
4
5
6
7
8
9
10
11
//Simplified Mathematical formula. Similar to TR function in PRC
TRM=MAX(HIGH,CLOSE[1])-MIN(LOW,CLOSE[1])
//Mathematical formula. Similar to AverageTrueRange function in PRC
To help us continually offer you the best experience on ProRealCode, we use cookies. By clicking on "Continue" you are agreeing to our use of them. You can also check our "privacy policy" page for more information.Continue