Lookback period for data2

Questions about MultiCharts and user contributed studies.
joyjoy
Posts: 8
Joined: 05 May 2014
Has thanked: 2 times

Lookback period for data2

Postby joyjoy » 26 Apr 2018

In Multichart you need to specify the look back period for a futures chart, it seems the same look back period parameter applies to both data1 and data2. My problem is that I do not have long enough data2 data for live trading ( though for back testing it is not A concern as I can use continuous contract)

Say I need to use 100 bar moving average indicator in data1, which is 5-minute chart, this requires me to set the look back period parameter to at least 100, but I use daily bar as data2 in the same signal, data2 is daily bar and sometimes I have no more than 30 daily bars for a specific futures contact month in real-time trading, is it possible to let data2 ignore the look back period for data1, or use A different parameter for data2? (I only need 10 data2 bars here to calculate Atr)

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Lookback period for data2

Postby MAZINGUER » 26 Apr 2018

Hi joyjoy
Multiple data streams can be referenced with the keyword DATA.
If we do not put anything about the flow of data, the variables do calculations and store values referring to Data1. If you want the variables to make calculations and store values referring to another data flow, for example Data2, you must specify it
In the case that you indicate, if you want an average of the closures of 100 bars in the 5-minute chart and an average of the closures of 10 bars in the daily chart would be something like this:
Vars: Avg1 (0), Avg2 (0);
Avg1 = Average (close, 100) of Data1;
Avg2 = Average (close, 10) of Data2;

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Lookback period for data2

Postby TJ » 26 Apr 2018

Hi joyjoy
Multiple data streams can be referenced with the keyword DATA.
If we do not put anything about the flow of data, the variables do calculations and store values referring to Data1. If you want the variables to make calculations and store values referring to another data flow, for example Data2, you must specify it
In the case that you indicate, if you want an average of the closures of 100 bars in the 5-minute chart and an average of the closures of 10 bars in the daily chart would be something like this:
Vars: Avg1 (0), Avg2 (0);
Avg1 = Average (close, 100) of Data1;
Avg2 = Average (close, 10) of Data2;

See post #5
viewtopic.php?t=6929

You are missing one element in the variable declaration.



ps. he is asking about MaxBarsBack.

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Lookback period for data2

Postby MAZINGUER » 26 Apr 2018

Hi TJ,
you're right, I correct the error

Code: Select all

Vars: Avg1 (0,Data1), Avg2 (0,Data2);
Avg1 = Average (close, 100) of Data1;
Avg2 = Average (close, 10) of Data2;
Thanks

joyjoy
Posts: 8
Joined: 05 May 2014
Has thanked: 2 times

Re: Lookback period for data2

Postby joyjoy » 26 Apr 2018

Hi joyjoy

See post #5
viewtopic.php?t=6929

You are missing one element in the variable declaration.



ps. he is asking about MaxBarsBack.


TJ and Mazinguer, thanks for your reply.

Yes, I am talking about MaxBarsBack. I added data2 to the declaration as suggested, but it seems that the MaxBarsBack parameters (100) that I configured in the Strategy Properties window still applies to both Data1 and Data2, and I still get the same error as this: "Not enough series length. Bars reference value 100"

I hope to use 100 as MaxBarsBack for Data1 and a smaller value like 20 as MaxBarsBack for Data2, is this possible?

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Lookback period for data2

Postby MAZINGUER » 26 Apr 2018

Well I think you will not be able to solve this unless you get the daily bars needed to be at least equal to the maxbarsback
I found this in reference to maxbarsback (TS forum)
Look at point 5 and 6

Some facts about MaxBarsBack
1-During the MaxBarsBack period no calculations take place.
2-Indicators have an Auto-Detect option for MaxBarsBack, whereas strategies do not.
3-The default MaxBarsBack setting for indicators is Auto-Detect. The default MaxBarsBack setting for strategies is 50.
4-The Auto-Detect MaxBarsBack setting in indicators adds 1 to the required number of MaxBarsBack (with one exception). For instance, if you use Close, which requires a MaxBarsBack setting of 0, the Auto-Detect setting will set MaxBarsBack to 1. The one exception is when the MaxBarsBack requirement is 1, then Auto-Detect leaves it at 1 i.e. Close[0] sets MBB to 1, Close[1] sets MBB to 1, Close[2] sets MBB to 3, Close[3] sets MBB to 4 etc.
5-MaxBarsBack cannot be set from within EasyLanguage code. But its value can be detected using the MaxBarsBack reserved word.
6-On multi-datastream charts, it is necessary for ALL datastreams to meet the MaxBarsBack requirements before calculations start. So, for example, if DATA1 is 1 minute and DATA2 is daily, then a MaxBarsBack of 50 means we have to wait 50 days before calculations start. In this instance, many thousands of 1 minute bars have passed, but no calculations can take place until MaxBarsBack has been met on the daily (DATA2) chart.
7-Each indicator applied to a chart has its own MaxBarsBack setting. But all strategies applied to a chart share a single MaxBarsBack setting. For example, if you apply three strategies to a chart - one with a MaxBarsBack setting of 20, one with 40 and one with 200 - then a MaxBarsBack of 200 will be used for all three strategies.
8-When indicators are run with the Auto-Detect setting, they will first run through the code with a MaxBarsBack value of 1. This first 'run' is used to detect a correct MaxBarsBack value. After this first run, MaxBarsBack is changed and the indicator is started again from scratch. For example, the following code is run in an indicator with a MaxBarsBack setting of Auto-Detect.

joyjoy
Posts: 8
Joined: 05 May 2014
Has thanked: 2 times

Re: Lookback period for data2

Postby joyjoy » 26 Apr 2018

Yes I understand now that data2 need to meet the same MaxBarsBack requirements as data1.

But it is really not very convenient if you are trading a front month futures contract which may have just been listed for 15 trading days, you need to check the highest/lowerest price of last 5 days in Data2 (Daily chart) and trade the contract with a MA100 in Data1 ( M1 chart), as the MaxBarsBack should be 100 in this case, and you need to wait for 100 days to get the Data2 meet the MaxBarsBack requirement which actually makes trading this strategy not practical.
Hope this can be changed .

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Lookback period for data2

Postby MAZINGUER » 26 Apr 2018

I also found this:

Some calculations do require large lookbacks. For instance, if you are calculating a 200 period simple moving average then you will need a lookback (and hence a MaxBarsBack setting) of 200. However, it is an easy mistake (and quite common) to write code that looks back further than is necessary and hence creates huge MaxBarsBack settings. Remember that indicators will not display and strategies will not trade during the MaxBarsBack period so having very large MaxBarsBack values can be very wasteful. If your code needs a large MaxBarsBack period then you should post in the Support Forum for ideas on how to reduce its value. Even if you do need lots of historical data, it is usually possible to reduce the MaxBarsBack requirement by using Arrays

That is, it may be possible to solve your problem using Arrays, but the truth is, I can not think of how to do it

MAZINGUER
Posts: 75
Joined: 06 Jan 2017
Has thanked: 9 times
Been thanked: 25 times

Re: Lookback period for data2

Postby MAZINGUER » 26 Apr 2018

I think something like this:
You create an array of one dimension with ten elements.

Code: Select all

Vars: AVG1(0, Data1);
Array: MyArray[9](0);

AVG1 = Average (close, 10) of data 1;
MiArray[0] = AVG1; // (in the first element of the array I put the average of the first ten bars)

If currentbar = 10 then
MiArray[1] = AVG1; // (in the second element I put the average of the second ten bars)

if Currentbar = 20 then
MiArray[2]= AVG1 ; // (in the third element of the array I put the average of the third ten bars)

.../...
and so on until you get to currentbar = 90

Then you take the Average of all the elements of the Array

For this you only need a maxbarsback of 10 bars in data1 .. but I really do not know if it is correct. It would have to do it and try

But of course ¿what happens when you have more currentbar of 90? I think the Array would stay fixed and would not add correct and new elements.
Then another way could be:
Load 100 bars in data 1 and then in element 0 of the array you put the average of ten bars, 90 bars ago, that is, MiArray [0] = AVG1 (close, 10) [90].
In the second element of the array you put the average of ten bars, 80 bars ago, that is, MyArray [1] = AVG1 (close, 10) [80] and so on up to the cero bar
Then you make the average of the elements of the Array.
In this way I think the average will be updated as new bars come
They are two ideas that should be tried, but I am inclined to the second

joyjoy
Posts: 8
Joined: 05 May 2014
Has thanked: 2 times

Re: Lookback period for data2

Postby joyjoy » 27 Apr 2018

They are two ideas that should be tried, but I am inclined to the second
Thanks Mazinguer, but array is beyond my level of MC coding. For the time being I adopted a simple method: I pull out a separate daily chart, draw an indicator on it, and manually input the indicator values from the daily chart to the M5 chart every day before market open. This is an affordable method of mine :lol:


Return to “MultiCharts”