Problem with data series calculations  [SOLVED]

Questions about MultiCharts and user contributed studies.
trader101
Posts: 15
Joined: 30 Nov 2012
Has thanked: 8 times
Been thanked: 1 time

Problem with data series calculations

Postby trader101 » 19 Dec 2012

Hello, below is the code that is giving me troubles. When I look at the data output (txt file) for the variable " Atr " it changes depending of the time frame I select for data1. But my calculations are specifically defined to be done of the data2 series which must always be on a Daily time frame.

What could be my mistake ? Thank, you.

I am using a chart with 2 data series on the following instrument SPY, using Interactive Brokers data feed. But I guess it could be used on any instrument and feed and give the same ouput...

Code: Select all

variables: Atr (0), tHigh (0), tLow (0) ;


if Close[3] of data2 > High[2] of data2 then
tHigh = Close[3] of data2
else
tHigh = High[2] of data2 ;


if Close[3] of data2 < Low[2] of data2 then
tLow = Close[3] of data2
else
tLow = Low[2] of data2 ;



Atr = Average(tHigh - tLow,5) ;


print (File("c:\ATR_TEST.txt")," Date ", Date, " Time ", time_s,
" Atr ", Atr:10:5, " tHigh", tHigh:10:5, " tLow", tLow:10:5


) ;
Output using the following chart parameters :

data1 = 1 hour
data2 = 1 day

Date 1121218.00 Time 90000.00 Atr 1.36400 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 100000.00 Atr 1.42600 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 110000.00 Atr 1.48800 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 120000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 130000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 140000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 150000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 160000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 170000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 180000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 183000.00 Atr 1.40200 tHigh 142.69000 tLow 141.88000

Output using the following chart parameters :

data1 = 30 minutes
data2 = 1 day

Date 1121218.00 Time 83000.00 Atr 1.36400 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 90000.00 Atr 1.42600 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 93000.00 Atr 1.48800 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 100000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 103000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 110000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 113000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 120000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 123000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 130000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 133000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 140000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 143000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 150000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 153000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 160000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 163000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 170000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 173000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 180000.00 Atr 1.55000 tHigh 143.83000 tLow 142.28000
Date 1121218.00 Time 183000.00 Atr 1.40200 tHigh 142.69000 tLow 141.88000

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

Re: Problem with data series calculations

Postby Henry MultiСharts » 21 Dec 2012

Hello trader101,

We are testing your inquiry in our environment. I will keep you updated.

trader101
Posts: 15
Joined: 30 Nov 2012
Has thanked: 8 times
Been thanked: 1 time

Re: Problem with data series calculations

Postby trader101 » 21 Dec 2012

OK thank you for the heads up.

here is the version I am using if it might be a version related problem...

MultiCharts Version 8.0 Release (Build 5620)

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

Re: Problem with data series calculations  [SOLVED]

Postby Henry MultiСharts » 24 Dec 2012

Hello trader101,

The code works as expected. The calculation results are correct.
Atr values on the first bars of calcualtion differ because there are no historical values yet.
On the last bar of the day the value is different from intraday values because the script references the closed bars.
For example: When you reference High[2] of data2 on November, 30 3pm your current bar is considered to be the closed bar of November, 29. High[2]=High of November 27.
High[2] of data2 on November, 30 6.30 pm (session close) uses the current closed bar for November,30 as the zero point, High[2]=High of November,28

You can use the print statement below to check the calculations:

Code: Select all

print (File("c:\ATR_TEST.txt")," Date= ", Date, " Time= ", time_s,
" DateD2= ", Date of data2, " TimeD2= ", time_s of data2,
" Atr= ", Atr:10:5, " tHigh=", tHigh:10:5, " tLow=", tLow:10:5,
" tHigh[1]= ", tHigh[1]:10:5, " tHigh[2]= ", tHigh[2]:10:5, " tHigh[3]= ", tHigh[3]:10:5,
" tLow[1]= ",tLow[1]:10:5, " tLow[2]= ",tLow[2]:10:5, " tLow[3]= ",tLow[3]:10:5,
"((tHigh - tLow)[1])=",((tHigh - tLow)[1]):10:5, "((tHigh - tLow)[2])=",
((tHigh - tLow)[2]):10:5, "((tHigh - tLow)[3])=",((tHigh - tLow)[3]):10:5);


Return to “MultiCharts”