MaxBarsBack for multi data series

Questions about MultiCharts and user contributed studies.
ragdoll
Posts: 49
Joined: 04 Apr 2019
Has thanked: 4 times

MaxBarsBack for multi data series

Postby ragdoll » 11 Nov 2020

Hi,

In my study, there are 3-min bars for data1 and daily bars for data2. One daily bar corresponds to 120 3-min bars. If I want to get the 5-day moving average, what MaxBarsBack should I set? 5 or 600? If I set it to 600, then seems both data series share the same MaxBarsBack and the study starts after 600 days from the beginning. Any ideas please?

Thanks.

Zheka
Posts: 225
Joined: 13 Jan 2016
Has thanked: 8 times
Been thanked: 53 times

Re: MaxBarsBack for multi data series

Postby Zheka » 12 Nov 2020

This is a known (and very annoying) "feature" of MC.

Assuming you want to calculate a 600-bar average of 3-min bars, then the walk-arounds could be:

1) set the start date of data2 600 days back and indeed use 600 for MaxBarsBack....Simplest, assuming you have the data (you can create/add some dummy back data if you don't)
2) use Exponential moving average (xaverage() ) - which internally needs only the latest data point for calculations.

If you need a 5-day MA of daily closes, then:
var: sma(0,data2);
sma=average(close,5) data(2);

..and the MaxBarsBack setting is to be set as per the max you need in your other calculations.

P.S.: there is a way to address prior values of a variable farther away than set by MaxBarsBack - by using Symbol_Close[ago].
so, you can either try passing this in average() ( most probably will not work) or creating your own MA function that will use symbol_close[x] for calculations.

ragdoll
Posts: 49
Joined: 04 Apr 2019
Has thanked: 4 times

Re: MaxBarsBack for multi data series

Postby ragdoll » 12 Nov 2020

If you need a 5-day MA of daily closes, then:
var: sma(0,data2);
sma=average(close,5) data(2);

If I do this, seems it still needs MaxBarsBack to be set to 600.
This is a known (and very annoying) "feature" of MC.

Assuming you want to calculate a 600-bar average of 3-min bars, then the walk-arounds could be:

1) set the start date of data2 600 days back and indeed use 600 for MaxBarsBack....Simplest, assuming you have the data (you can create/add some dummy back data if you don't)
2) use Exponential moving average (xaverage() ) - which internally needs only the latest data point for calculations.

If you need a 5-day MA of daily closes, then:
var: sma(0,data2);
sma=average(close,5) data(2);

..and the MaxBarsBack setting is to be set as per the max you need in your other calculations.

P.S.: there is a way to address prior values of a variable farther away than set by MaxBarsBack - by using Symbol_Close[ago].
so, you can either try passing this in average() ( most probably will not work) or creating your own MA function that will use symbol_close[x] for calculations.


Return to “MultiCharts”