Daily ATR calculations from minutes data is weird on mc v8.8

Questions about MultiCharts and user contributed studies.
ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Daily ATR calculations from minutes data is weird on mc v8.8

Postby ducktail » 06 Jul 2014

Hello, my code below is for calculating Daily Average True Range only from minutes data as Data1.

The code calculates properly on MC v8.0 & v8.5, but doesn't on MC v8.8.
Because of this issue, I haven't been able to upgrade latest version of MC for about a year.
I have no idea about this. Would you please help me.

Thank you for reading my poor code and poor english.

Ducktail
TR_ATR_DATA1.pla
TR_ATR_DATA1
(4.06 KiB) Downloaded 467 times

Code: Select all

{CountDays}
var:CountDays(1);
if date<>date[1] then
CountDays=CountDays+1;

{High_D / Low_D}
var:MarketOpening(900),MarketClosing(1520),High_D(0),Low_D(0);
If Time=MarketOpening+Barinterval then
begin
High_D=High;
Low_D=Low;
end
else If Time>MarketOpening+Barinterval and time<=MarketClosing then
begin
if High>High_D then High_D=High;
If Low<Low_D then Low_D=Low;
end;

{MarketClosing / Calc ATR}
var:ATR_Length(5),Close_D(0),ATR(0);
Arrays:TrueRangeArray[10](0);

If time=MarketClosing then
begin
Close_D=Close;
TrueRangeArray[1]=Maxlist(High_D-Low_D,High_D-Close_D[1],Close_D[1]-Low_D);
For Value99= 2 to ATR_Length
begin
TrueRangeArray[Value99]=TrueRangeArray[Value99-1][1];
end;
ATR=AverageArray(TrueRangeArray,ATR_Length);
end;

{Print Out}
if CountDays>ATR_Length and time=MarketClosing then
print(date:0:0,",ATR ",ATR:0:0,",TR1 ",TrueRangeArray[1]:0:0,",TR2 ",TrueRangeArray[2]:0:0,",TR3 ",TrueRangeArray[3]:0:0,",TR4 ",TrueRangeArray[4]:0:0,",TR5 ",TrueRangeArray[5]:0:0);
Last edited by ducktail on 08 Jul 2014, edited 1 time in total.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby Henry MultiСharts » 07 Jul 2014

Hello Ducktail,

Please specify what you mean exactly by "The code calculates properly on MC v8.0 & v8.5, but doesn't on MC v8.8".

ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby ducktail » 07 Jul 2014

Hello Henry,

Thanks for your reply and sorry for my poor english.

When I calculate Daily ATR from 5min chart by the code above on MC v8.5, calculated ATR is correct.
But when I do the same thing on MC v8.8, calculated ATR is totally incorrect.

I attached xls file. Please compare them.
CalcATR2.xls
Calculated ATR
(29 KiB) Downloaded 145 times
* the img below is capture of the CalcATR2.xls
Image

I use 5min chart of Nikkei 225 mini futures(I set MarketOpen=900 MarketClose=1520).
@N225M 5 Minutes.txt
Nikkei 225 mini 5min chart
(229.01 KiB) Downloaded 462 times
This time I use the code below to make the xls file. The change is only last line which starts from "print".

Thank you.

Ducktail
TR_ATR_DATA1_v2.pla
TR_ATR_DATA1_v2
(3.4 KiB) Downloaded 450 times

Code: Select all

{CountDays}
var:CountDays(1);
if date<>date[1] then
CountDays=CountDays+1;

{High_D / Low_D}
var:MarketOpening(900),MarketClosing(1520),High_D(0),Low_D(0);
If Time=MarketOpening+Barinterval then
begin
High_D=High;
Low_D=Low;
end
else If Time>MarketOpening+Barinterval and time<=MarketClosing then
begin
if High>High_D then High_D=High;
If Low<Low_D then Low_D=Low;
end;

{MarketClosing / Calc TR}
var:ATR_Length(5),Close_D(0),TrueRangeD(0),ATR(0);
Arrays:TrueRangeArray[10](0);

If time=MarketClosing then
begin
Close_D=Close;
TrueRangeArray[1]=Maxlist(High_D-Low_D,High_D-Close_D[1],Close_D[1]-Low_D);
For Value99= 2 to ATR_Length
begin
TrueRangeArray[Value99]=TrueRangeArray[Value99-1][1];
end;
ATR=AverageArray(TrueRangeArray,ATR_Length);
end;

if CountDays>ATR_Length and time=MarketClosing then
print(date:0:0,",",High_D:0:0,",",Low_D:0:0,",",Close_D:0:0,",",TrueRangeArray[1]:0:0,",",ATR);

ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby ducktail » 09 Jul 2014

My code "TR_ATR_DATA1" is doing...

[ From MarketOpening to MarketClosing ]
Trace High_D(Daily High) and Low_D(Daily Low).

[ On MarketClosing ]
1. Determine Close_D(Daily Close).
2. Calcurate TrueRangeArray[1](Daily True Range).
3. Replace TrueRangeArray[2]-[5] with new value.
TrueRangeArray[2]=TrueRangeArray[1][1](the previous day's True Range)
TrueRangeArray[3]=TrueRangeArray[2][1]
TrueRangeArray[4]=TrueRangeArray[3][1]
TrueRangeArray[5]=TrueRangeArray[4][1]
4. Calculate Average True Range.

This is the first code that I use array. So it might be strange or not smart.


Let me compare the out-put by my code between on MC v8.5 and on MC v8.8.

The below xls is the out-put by "TR_ATR_DATA1".
CalcATR.xls
Calculated ATR
(27 KiB) Downloaded 148 times
The out-put on MC v8.5 is correct.
The out-put on MC v8.8 is totally incorrect.

The img below is capture of the CalcATR.xls
See the numbers which are surrounded by yellow line.
The numbers on MC v8.8 are "TR2=0,TR3=0,TR4=0,TR5=0".
They must be "TR2=460,TR3=280,TR4=305,TR5=235".
* TRn means TrueRangeArray[n].
Image

I'd like to know why my code on MC v8.8 could not work fine.

Thank you

Ducktail

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby Henry MultiСharts » 09 Jul 2014

Ducktail, we are analyzing this behavior.

ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby ducktail » 09 Jul 2014

Henry, I appreciate that.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby Henry MultiСharts » 10 Jul 2014

Ducktail, our engineers have studied this behavior. Indeed there is a difference in calculation results when arrays are used in the code. The fix of the issue is targeted to MultiCharts 9.0 Release Candidate.

ducktail
Posts: 21
Joined: 21 Feb 2011
Has thanked: 22 times
Been thanked: 7 times

Re: Daily ATR calculations from minutes data is weird on mc

Postby ducktail » 10 Jul 2014

Henry, thank you. I look forward to that.


Return to “MultiCharts”