Multiple Data Series | MaxBarsBack Problem (no problem)

Questions about MultiCharts and user contributed studies.
User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Multiple Data Series | MaxBarsBack Problem (no problem)

Postby master.aurora » 04 Oct 2013

Hello Support,

I am running into an issue here while using a second timeseries of data in my code. My strategy and all its calculations are based on one time frame eg. 1 hour. But i just want to calculate the ATR on daily data. This is how i am trying to use it in my code:

Code: Select all

atr = average(truerange of data2, length);
For testing i am using length = 20. Here are my data settings:

Image

Also, a screenshot of the chart, the ATR indicator is also attached:

Image

The ATR indicator (yellow line) starts building on bar number 22 of the daily instrument series. But when i attach my strategy, this is the error i get:

Image

I fail to understand that if i have 20 daily bars available and the ATR indicator on the chart is working as well, then why does the strategy give me the error? Am i missing something here?

Please advise.

Regards
Umer

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

Re: Multiple Data Series | MaxBarsBack Problem

Postby TJ » 04 Oct 2013

Hello Support,
I am running into an issue here while using a second timeseries of data in my code. My strategy and all its calculations are based on one time frame eg. 1 hour. But i just want to calculate the ATR on daily data. This is how i am trying to use it in my code:

Code: Select all

atr = average(truerange of data2, length);
::
Regards
Umer
see post #5
viewtopic.php?f=16&t=6929

User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Re: Multiple Data Series | MaxBarsBack Problem

Postby master.aurora » 04 Oct 2013

It still doesnt work. I guess we also need to have 50 bars of daily data available. If i do that, it runs fine.

Thanks anyways.

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

Re: Multiple Data Series | MaxBarsBack Problem

Postby TJ » 04 Oct 2013

It still doesnt work. I guess we also need to have 50 bars of daily data available. If i do that, it runs fine.
Thanks anyways.
Look up MaxBarsBack.
https://www.multicharts.com/trading-sof ... /Main_Page

User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Re: Multiple Data Series | MaxBarsBack Problem

Postby master.aurora » 25 Oct 2013

Hello Support,

I was able to run it by making sure i have maxbarsback data available for both the time series. But, i have another issue that is pretty strange. I am running the strategy on 5 min bars & using daily ATR as well. So, i need maxbarsback of both 5 min & daily. The maxbarsback for the smaller timeframe is obviously achieved earlier, so we have to wait for maxbarsback daily bars. While reviewing the logs, i see that when the maxbarsback number of daily bars arrive, the MC strategy starts calculating by taking into account one 5 min bar from the previous day. Now, the strange thing here is that it just doesn't simply pick up the last bar from the previous day. Please look at the following screenshot:

Image

In this set of data, the strategy should have started on the first bar of the 21st (boxed in red), but it took the highlighted bar (blue) first, and then started the first bar of the 24th. This messes up the calculations.

Now that i have explained it, i would list down some questions as you guy are more comfortable with direct questions. Please answer the following:

1. Are there any setting which govern this behaviour? If so which ones and how should they be used?
2. Is there something wrong with the way i am calling the ATR on the daily data? The code is in my original post.
3. What is your opinion is the best way to understand the use of session information in backtesting? Is there any MC guide which we can refer to in these kind of situations?


I am intently looking forward to you reply on this. This is a bit critical so i would be hoping to get a reply as soon as possible.

Thanks

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Multiple Data Series | MaxBarsBack Problem

Postby Andrew MultiCharts » 25 Oct 2013

Code: Select all

atr = average(truerange of data2, length);
Should be:

Code: Select all

var: atr(data2,0);
atr = average(truerange, length) of data2;
Hello Support,

I was able to run it by making sure i have maxbarsback data available for both the time series. But, i have another issue that is pretty strange. I am running the strategy on 5 min bars & using daily ATR as well. So, i need maxbarsback of both 5 min & daily. The maxbarsback for the smaller timeframe is obviously achieved earlier, so we have to wait for maxbarsback daily bars. While reviewing the logs, i see that when the maxbarsback number of daily bars arrive, the MC strategy starts calculating by taking into account one 5 min bar from the previous day. Now, the strange thing here is that it just doesn't simply pick up the last bar from the previous day. Please look at the following screenshot:

Image

In this set of data, the strategy should have started on the first bar of the 21st (boxed in red), but it took the highlighted bar (blue) first, and then started the first bar of the 24th. This messes up the calculations.

Now that i have explained it, i would list down some questions as you guy are more comfortable with direct questions. Please answer the following:

1. Are there any setting which govern this behaviour? If so which ones and how should they be used?
2. Is there something wrong with the way i am calling the ATR on the daily data? The code is in my original post.
3. What is your opinion is the best way to understand the use of session information in backtesting? Is there any MC guide which we can refer to in these kind of situations?


I am intently looking forward to you reply on this. This is a bit critical so i would be hoping to get a reply as soon as possible.

Thanks
I am afraid i don't understand what exactly is the problem? Script calculation skips something on data1/data2? Would you be able to elaborate, please?

User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Re: Multiple Data Series | MaxBarsBack Problem

Postby master.aurora » 28 Oct 2013

I am disappointed that even after explaining my problem in detail, i have not had a reply and you do not understand the issue. Please go through my original post once again, and also the explanation that i am giving below as well.

I have a very simple script using which i just print out the data that the strategy will be running on.

Code: Select all

print("New bar Arrived : Date = ", FormatDate("M/d/yyyy", ELDateToDateTime(Date)), " | Time = ", Time,
" | Open = ", NumToStr(Open[0], 5), " | High = ", NumToStr(High[0], 5), " | Low = ", NumToStr(Low[0], 5), " | Close = ", NumToStr(Close[0], 5));
Now, i run this code in backtest on:

Image

The MaxBarsBack is set to 55.

Here are the logs from this run:

Code: Select all

New bar Arrived : Date = 3/22/2013 | Time = 1700.00 | Open = 1607.50000 | High = 1608.50000 | Low = 1607.50000 | Close = 1607.50000
New bar Arrived : Date = 3/25/2013 | Time = 100.00 | Open = 1609.30000 | High = 1610.00000 | Low = 1609.30000 | Close = 1609.80000
New bar Arrived : Date = 3/25/2013 | Time = 200.00 | Open = 1609.80000 | High = 1611.00000 | Low = 1607.90000 | Close = 1608.00000
New bar Arrived : Date = 3/25/2013 | Time = 300.00 | Open = 1608.10000 | High = 1608.30000 | Low = 1605.40000 | Close = 1605.90000
New bar Arrived : Date = 3/25/2013 | Time = 400.00 | Open = 1605.90000 | High = 1606.90000 | Low = 1604.20000 | Close = 1604.60000
New bar Arrived : Date = 3/25/2013 | Time = 500.00 | Open = 1604.60000 | High = 1605.30000 | Low = 1600.70000 | Close = 1602.20000
New bar Arrived : Date = 3/25/2013 | Time = 600.00 | Open = 1602.20000 | High = 1603.00000 | Low = 1601.30000 | Close = 1601.90000
New bar Arrived : Date = 3/25/2013 | Time = 700.00 | Open = 1601.90000 | High = 1602.50000 | Low = 1597.10000 | Close = 1598.10000
New bar Arrived : Date = 3/25/2013 | Time = 800.00 | Open = 1598.00000 | High = 1598.20000 | Low = 1588.40000 | Close = 1592.60000
New bar Arrived : Date = 3/25/2013 | Time = 900.00 | Open = 1592.50000 | High = 1598.40000 | Low = 1592.10000 | Close = 1595.40000
New bar Arrived : Date = 3/25/2013 | Time = 1000.00 | Open = 1595.30000 | High = 1599.60000 | Low = 1594.30000 | Close = 1597.80000
New bar Arrived : Date = 3/25/2013 | Time = 1100.00 | Open = 1597.90000 | High = 1605.80000 | Low = 1597.60000 | Close = 1599.80000
New bar Arrived : Date = 3/25/2013 | Time = 1200.00 | Open = 1599.70000 | High = 1603.30000 | Low = 1599.10000 | Close = 1602.80000
New bar Arrived : Date = 3/25/2013 | Time = 1300.00 | Open = 1602.80000 | High = 1606.80000 | Low = 1601.50000 | Close = 1602.00000
New bar Arrived : Date = 3/25/2013 | Time = 1400.00 | Open = 1602.00000 | High = 1604.30000 | Low = 1601.00000 | Close = 1603.10000
New bar Arrived : Date = 3/25/2013 | Time = 1500.00 | Open = 1603.10000 | High = 1604.60000 | Low = 1602.80000 | Close = 1603.50000
New bar Arrived : Date = 3/25/2013 | Time = 1600.00 | Open = 1603.40000 | High = 1604.20000 | Low = 1602.60000 | Close = 1604.10000
New bar Arrived : Date = 3/25/2013 | Time = 1700.00 | Open = 1604.10000 | High = 1604.50000 | Low = 1603.80000 | Close = 1604.20000
New bar Arrived : Date = 3/25/2013 | Time = 1800.00 | Open = 1604.50000 | High = 1604.60000 | Low = 1602.30000 | Close = 1602.90000
New bar Arrived : Date = 3/25/2013 | Time = 1900.00 | Open = 1603.00000 | High = 1604.60000 | Low = 1602.70000 | Close = 1604.60000
The related daily data:

Image

The related hourly data:

Image

The session information:

Image

Leave all my other questions, but can you just please answer one question:

Why does the calculations start on the hourly bar of 3/22/2013 1700.00 rather than the first bar of the 25th?

I hope i have made myself clear this time. This really has been a pain and i would like to get some sort of reference as to how MC decides which data it is going to run on.

Thanks

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Multiple Data Series | MaxBarsBack Problem

Postby Andrew MultiCharts » 28 Oct 2013

Why does the calculations start on the hourly bar of 3/22/2013 1700.00 rather than the first bar of the 25th?

I hope i have made myself clear this time. This really has been a pain and i would like to get some sort of reference as to how MC decides which data it is going to run on.
Thank you, Master.Aurora. Your last post made it much clearer indeed.
Portfolio Backtester works different in this case from MultiCharts:
  • MC: 2 data series; strategy references only data1; X bars are skipped for strategy calculation of data 1, where X = MaxBarsBack; 0 bars are skipped of data2.
  • MC: 2 data series; strategy references both data1 and data2; X bars are skipped for strategy calculation of data 1, where X = MaxBarsBack; X bars are skipped of data2, where X = MaxBarsBack.
  • PB: 2 data series; strategy references only data1; X bars are skipped for strategy calculation of data 1, where X = MaxBarsBack; X bars are skipped of data2, where X = MaxBarsBack.
  • PB: 2 data series; strategy references both data1 and data2; X bars are skipped for strategy calculation of data 1, where X = MaxBarsBack; X bars are skipped of data2, where X = MaxBarsBack.
This is a designed limitation of Portfolio Backtester. The workaround: if data 2 is not referenced by a strategy in Portfolio Backtester, the data 2 should be removed from the PB workspace in order not to affect the starting point of strategy calculation.

User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Re: Multiple Data Series | MaxBarsBack Problem

Postby master.aurora » 28 Oct 2013

Andrew, you still do not seem to have understood my issue. I am using 2 data series in my strategy.

Code: Select all

atr = average(truerange of data2, length);
Should be:

Code: Select all

var: atr(data2,0);
atr = average(truerange, length) of data2;
This is what you suggested in this very thread. So can you please go through this once again and try to actually see what i am talking about. There are 2 dataseries in my strategy.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Multiple Data Series | MaxBarsBack Problem

Postby Andrew MultiCharts » 29 Oct 2013

Your original question was resolved as far as i can see from the posts above:
...
The ATR indicator (yellow line) starts building on bar number 22 of the daily instrument series. But when i attach my strategy, this is the error i get:

Image

I fail to understand that if i have 20 daily bars available and the ATR indicator on the chart is working as well, then why does the strategy give me the error? Am i missing something here?
...
...It still doesnt work. I guess we also need to have 50 bars of daily data available. If i do that, it runs fine.
...
...
I was able to run it by making sure i have maxbarsback data available for both the time series.
...
Then you said you have another issue, that i was trying to understand:
But, i have another issue that is pretty strange. I am running the strategy on 5 min bars & using daily ATR as well. So, i need maxbarsback of both 5 min & daily. The maxbarsback for the smaller timeframe is obviously achieved earlier, so we have to wait for maxbarsback daily bars. While reviewing the logs, i see that when the maxbarsback number of daily bars arrive, the MC strategy starts calculating by taking into account one 5 min bar from the previous day. Now, the strange thing here is that it just doesn't simply pick up the last bar from the previous day. Please look at the following screenshot:
Judging by the screenshots you provided you have incorrect sessions for the symbol. Your daily bars ends later then intraday data, what causes the following asynchronization between the 2 data series. here is an example of what i am talking about:

Image

In this case the bar from the previous day on the first (intraday) data series will be taken for calculation. If you change the sessions on chart and reload the data to have the correct identical session end on data series 1 and on data series 2. The same works for Portfolio Backtester, as well as for MultiCharts itself.

User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Re: Multiple Data Series | MaxBarsBack Problem

Postby master.aurora » 30 Oct 2013

Hello Andrew,

Thank you very much. I was able to fix the issue with what you suggested. Here is what i did:

I deleted all the data from QuoteManager.
I updated the session to 24 hour i.e:

Image

Now i connected to IQFeed and pulled in the data.
I ran the strategy and it started where it should have.

But now there is another issue, the last bar of each week is being fired twice. For example, here is the data:

Image

The highlighted bar is being calculated upon twice with the same time on the bar:

Code: Select all

Bar : Date = 3/22/2013 | Time = 1800.00 | Open = 1610.90000 | High = 1611.80000 | Low = 1610.80000 | Close = 1610.80000
This is messing up our calculations. This should have only fired once and afterwards should have moved on to

Code: Select all

Bar : Date = 3/25/2013 | Time = 100.00 | Open = 1613.30000 | High = 1615.00000 | Low = 1612.50000 | Close = 1612.60000
So, my logs should have had values like:

Code: Select all

Bar : Date = 3/22/2013 | Time = 1800.00 | Open = 1610.90000 | High = 1611.80000 | Low = 1610.80000 | Close = 1610.80000
Bar : Date = 3/25/2013 | Time = 100.00 | Open = 1613.30000 | High = 1615.00000 | Low = 1612.50000 | Close = 1612.60000
Rather they were:

Code: Select all

Bar : Date = 3/22/2013 | Time = 1800.00 | Open = 1610.90000 | High = 1611.80000 | Low = 1610.80000 | Close = 1610.80000
Bar : Date = 3/22/2013 | Time = 1800.00 | Open = 1610.90000 | High = 1611.80000 | Low = 1610.80000 | Close = 1610.80000
Bar : Date = 3/25/2013 | Time = 100.00 | Open = 1613.30000 | High = 1615.00000 | Low = 1612.50000 | Close = 1612.60000
Can you please let me know what the issue is here?

Regards
Umer

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Multiple Data Series | MaxBarsBack Problem

Postby Andrew MultiCharts » 30 Oct 2013

The case is almost the same. What is the goal to have 24 hour session? The correct sessions for the Gold Futures (all previous screenshots demonstrated exactly this security) should be the following:

Image
Image

User avatar
master.aurora
Posts: 33
Joined: 21 Jan 2013
Location: Islamabad
Has thanked: 6 times
Been thanked: 3 times
Contact:

Re: Multiple Data Series | MaxBarsBack Problem (no problem)

Postby master.aurora » 30 Oct 2013

Hello Andrew,

Thank you for your reply.

But wouldn't that put us in the same situation i was in previously? I mean you said:
Judging by the screenshots you provided you have incorrect sessions for the symbol. Your daily bars ends later then intraday data, what causes the following asynchronization between the 2 data series
Either way, i will change to appropriate session times and try again.

Thanks
Umer

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Multiple Data Series | MaxBarsBack Problem

Postby Andrew MultiCharts » 30 Oct 2013

Well, actually comparing your previous posts (7 and 11), i am not sure i understand what was changed in terms of sessions:
...
The related daily data:

Image
...
The session information:

Image
...
vs.
...
I updated the session to 24 hour i.e:

Image
...
The correct sessions i suggested in my previous post should help you with all your issues.


Return to “MultiCharts”