problem with accessing old bars in other time frame  [SOLVED]

Questions about MultiCharts and user contributed studies.
Posts: 8
Joined: 19 Mar 2012
Been thanked: 1 time

problem with accessing old bars in other time frame

Postby Mats » 03 Aug 2012

Here is some code to illustrate the problem I am having. Maybe it is a bug, maybe I am doing something wrong.

Code: Select all

// data1 is 1min bars and data2 is daily
var closeopen(0);

if time = 1559 then
// some calculation on daily bars..
CloseOpen=(Open data2/Close data2-1)*100;

// lets write  to file for debugging...
Print(File("C:\test.txt")," closeopen=",closeopen*100, " closeopen[1]=",closeopen[1]*100, " closeopen[2]=",closeopen[2]*100);

So here is a line of the test.txt
closeopen= -6.59 closeopen[1]= 80.67 closeopen[2]= 80.67

closeopen[1] is always the previous value of closeopen (as it should be) but closeopen[2] is always equal to closeopen[1] (this should not be -- it should be equal to closeopen two bars back of course ).

What could be causing this? Is there always only one previous bar stored for the data series other than data1?

User avatar
Henry MultiСharts
Posts: 8636
Joined: 25 Aug 2011
Has thanked: 1218 times
Been thanked: 2783 times

Re: problem with accessing old bars in other time frame  [SOLVED]

Postby Henry MultiСharts » 06 Aug 2012

Hello Mats,

You need to create an array to store historical values of CloseOpen variable. Then you need to reference the value from this array.
These users thanked the author Henry MultiСharts for the post:

Return to “MultiCharts”