using data2 with more data range then data1

Questions about MultiCharts and user contributed studies.
User avatar
muhaha2015
Posts: 4
Joined: Oct 20 2020
Has thanked: 1 time

Jul 03 2024

Hello, I have a question and I hope someone may have an answer. I want to accomplish a simple task in MultiCharts. All I want is to plot a 100-day moving average on the 1-minute chart.

I have data1 in a 1-minute timeframe with a 5-day data range. Additionally, I have data2 in a 1-day timeframe with a 300-day data range. However, I have noticed that MultiCharts only calculates the moving average starting from the beginning of data1.

Could someone please guide me on how to achieve this? I have been struggling with it for so long :( , and I hope someone can provide assistance. Thank you very much.

User avatar
Vlada MultiCharts
Posts: 301
Joined: Apr 22 2020
Has thanked: 8 times
Been thanked: 78 times

Jul 03 2024

Hello muhaha2015,

If you would like to base your indicator on Data 2, please go to Format - Study and click the gear icon next to Moving Average. Then go to Properties tab and in the Base Study On section select the necessary data series.

User avatar
muhaha2015
Posts: 4
Joined: Oct 20 2020
Has thanked: 1 time

Jul 03 2024

Hello muhaha2015,

If you would like to base your indicator on Data 2, please go to Format - Study and click the gear icon next to Moving Average. Then go to Properties tab and in the Base Study On section select the necessary data series.
Hello Vlada, thank you for the fast reply.
Following your method indeed works, but my problem is how to get the calculation of data2 before the first bar of data1 when data2 have more data range.

Code: Select all

var: var0(0); condition1 = close > close[1] and close[1] > close[2] ; if condition1 then var0 = close; plot1(var0,"var0");

Code: Select all

var: var0(0); condition1 = close data2 > close[1] data2 and close[1] data2 > close[2] data2; if condition1 then var0 = close data2; plot1(var0,"var0");
Data 1 is 1 min , 5 days range
Data 2 is 1 day , >10 days range

If I base the upper indicator on Data 2, var0 is calculated before bar1 of data1, so there will be value in var0 instead of 0 at bar1 of data1, but then I can't compare the value with other value of data1 cause it's a indicator base on data2.

If I write it like in the lower code and base on data1, the condition calculation start after bar1 of data1, and var0 will be 0 until condition1 happened after bar1 of data1.

So how can I get the value calculated on data2 before bar1 of data1, so I can use it with other value calculated base on data1?

Hope you may help, Many Thanks.

User avatar
Vlada MultiCharts
Posts: 301
Joined: Apr 22 2020
Has thanked: 8 times
Been thanked: 78 times

Jul 24 2024

muhaha2015,

If the indicator is applied to the first data series, it will be calculated on close of each bar of the first series.

If the indicator is applied to the second data series,it will be calculated on each bar of the second series.

In your case, you can apply the indicator to the second series.

Code: Select all

var: var0(0); condition1 = close data2 > close[1] data2 and close[1] data2 > close[2] data2; if condition1 then var0 = close data2; plot1(var0,"var0");
Attachments
image (2).png
(53.15 KiB) Not downloaded yet
image (1).png
(47.96 KiB) Not downloaded yet