Possible to reference a variable's historical value based on higher data series?

Questions about MultiCharts and user contributed studies.
McGeorge
Posts: 49
Joined: 22 Jun 2018
Has thanked: 10 times
Been thanked: 6 times

Possible to reference a variable's historical value based on higher data series?

Postby McGeorge » 25 May 2021

Hi there,

When a strategy uses two time frames (E.g. 1 min and 5 min) of the same symbol, it is necessary to load two data series of price data into the same chart window. I wrote below codes to test the possibility of referencing a variable's value of each data series in the way like price data (OHLCV). Surprisingly, I found that such historical referencing works for each data series for price data but not variable data. Referencing a variable's historical value based on Data(2) has the same result of referencing based on Data (1).

Code: Select all

Variables: ABC (0), ABC = Time; If LastBarOnChart Then Begin Print ( DateTimeToString (DateTime), ", Time [0] of Data (1) = ", Time [0] of Data(1), ", Time [1] of Data(1) = ", Time [1] of Data(1) ); Print ( DateTimeToString (DateTime), ", Time [0] of Data (2) = ", Time [0] of Data(2), ", Time [1] of Data(2) = ", Time [1] of Data(2) ); Print ( "------------------------------------------------------------- --------------------------------------------------------------------" ); Print ( DateTimeToString (DateTime), ", ABC [0] of Data (1) = ", ABC [0] of Data(1), ", ABC [1] of Data(1) = ", ABC [1] of Data(1) ); Print ( DateTimeToString (DateTime), ", ABC [0] of Data (2) = ", ABC [0] of Data(2), ", ABC [1] of Data(2) = ", ABC [1] of Data(2) ); Print ( "===================================================================== ============================================================" ); End;
Below is an example showing the difference in value between price data and variable:

9/18/2020 8:29:00 AM, Time [0] of Data (1) = 829.00, Time [1] of Data(1) = 828.00
9/18/2020 8:29:00 AM, Time [0] of Data (2) = 825.00, Time [1] of Data(2) = 820.00
---------------------------------------------------------------------------------------------------------------------------------
9/18/2020 8:29:00 AM, ABC [0] of Data (1) = 829.00, ABC [1] of Data(1) = 828.00
9/18/2020 8:29:00 AM, ABC [0] of Data (2) = 829.00, ABC [1] of Data(2) = 828.00
=================================================================================================================================

Did I do anything wrong or referencing a variable's historical value based on a higher data series simply does not work?

Thanks,
McGeorge

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Possible to reference a variable's historical value based on higher data series?

Postby rrams » 25 May 2021

Hi McGeorge,
What you did wrong was assign the current time of data1 to a variable and then try to reference it as if it was from data2. There is no data series associated with a variable other than the one you assign it to. If you want the time from data2 in a variable, then assign it to a different one. ABC2 = Time of Data2;
Last edited by rrams on 26 May 2021, edited 1 time in total.

McGeorge
Posts: 49
Joined: 22 Jun 2018
Has thanked: 10 times
Been thanked: 6 times

Re: Possible to reference a variable's historical value based on higher data series?

Postby McGeorge » 25 May 2021

Thanks Rrams. Welcome comments from other experts who have different views.


Return to “MultiCharts”