multi timeframe strategy?

Questions about MultiCharts .NET and user contributed studies.
drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

multi timeframe strategy?

Postby drolles » 16 Dec 2012

Hi,

Is there an example of a multi timeframe strategy anywhere? Or a description of how to do this in MC .Net?

I’ve found a lot of examples of how to do it in std MC, but none for .Net.

Any assistance greatly appreciated.

Thanks and regards,

drolles

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: multi timeframe strategy?

Postby MidKnight » 16 Dec 2012

Hi drolles,

Can you maybe elaborate what part you don't understand? It is just a matter of adding in multiple data streams and then using BarsOfData() to access your various timeframes within the code.

All my best,
MK

drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Re: multi timeframe strategy?

Postby drolles » 17 Dec 2012

MidKnight,

Thanks very much for your reply. I appreciate you stepping in – I love these forums when the users collaborate.

My post a suggestion and a question.

Firstly, the suggestion; was that there should be an introductory example of this.

Secondly, the question; (which you have in part answered – thank you) was how it is recommended to be done by the MC team?

Thanks for the suggestion of BarsOfData(). That’s good news as it is the conclusion that I’ve come to.

The scenario is: If I want to use timebased bars; I want to signal at a higher timeframe (e.g. 1 hour) and trade (including backtest) at a lower timeframe (1 min). If I want to signal to do this I’m assuming I need to filter for the appropriate timeframe? Therefore, I’m wondering what value I filter on the Object tree via the IInstrument interface? In OpenQuant you would filter via the following: if (Bar.Size == 60) as Size is defined as the seconds of the Bar.

I’ve found Resolution which doesn’t seem right as I inspected it via VS and it returns 1 with Resolution.Size … 1 what?

Thanks and regards,

drolles

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: multi timeframe strategy?

Postby MidKnight » 17 Dec 2012

Hi there drolles,

I'm not really sure I understand your query correctly yet. Following on from your example where you have two timeframes that you want to reference in your code. If you create the chart with the 1 minute data and then add another instrument, which will be the same instrument but as 60 minute data. In the format instruments window I'd set the 60 minute data to hidden just to keep the chart clean, but this isn't required and you may want to leave it on for a while to make sure your code is doing what you expect it to.

Then in the code, anytime you reference Bars.Close[0], it would be referring to the 1 minute series. Anytime you reference BarsOfData(2).Close[0] it would be referring to the 60 minute series. The order that you have added the data onto the chart matters. The format instruments window shows each data series on the chart and its respective data stream ID number.

Does that help? I'm sorry if I'm not understanding your query properly...

With kind regards,
MK

drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Re: multi timeframe strategy?

Postby drolles » 17 Dec 2012

Hi MidKnight,

Thanks very much for the reply.

My starting assumption is that you don't know timeframe is in the data order, which is the usual assumption you make in OpenQuant as you don't know (when you have multiple instruments) when the events are going to fire to fire the OnBar event.

You explanation has possibly helped. How is the data referenced when in the Portfolio Backtester? For instance, if I have the instruments configured as I have in this screen shot, will both instruments 1 min data always be Data1?

Thanks,

drolles
Attachments
Portfolio Backtester shot.JPG
(94.11 KiB) Downloaded 2754 times

MidKnight
Posts: 343
Joined: 12 Aug 2012
Has thanked: 123 times
Been thanked: 56 times

Re: multi timeframe strategy?

Postby MidKnight » 17 Dec 2012

My starting assumption is that you don't know timeframe is in the data order, which is the usual assumption you make in OpenQuant as you don't know (when you have multiple instruments) when the events are going to fire to fire the OnBar event.

You explanation has possibly helped. How is the data referenced when in the Portfolio Backtester? For instance, if I have the instruments configured as I have in this screen shot, will both instruments 1 min data always be Data1?
MC.net isn't like that. AFAIK (and I may be wrong because I'm pretty new to MC), CalcBar() will fire on each new bar for your data1 series only. That is why you put your lowest timeframe into the data1 slot.

With regards to portfolio backtester, I've tried it a couple of times and it crashed on me so have not yet revisited it and cannot offer any advice on that subject - sorry.

With kind regards,
MK

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: multi timeframe strategy?

Postby Henry MultiСharts » 18 Dec 2012

Hello drolles,

MidKnight's explanations are correct.
Your trading resolution should be the main data series (Data1 in Format Instruments window).
Then you need to add second data series (subchart, dataN) with XXX resolution.
In the script the calculation can be based on the subchartN (data seriesN) with the help of BarsOfData.

In MultiCharts the second data series is added using Format tab->Instrument->Add.
In Poftfolio Backtester the second data series is added using the vertical Data columns.

On your screenshot the setup is correct. 1min data series is the main(trading) dataseries, 1hour is data2 and can be used for reference in the code.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: multi timeframe strategy?

Postby Henry MultiСharts » 18 Dec 2012

With regards to portfolio backtester, I've tried it a couple of times and it crashed on me so have not yet revisited it and cannot offer any advice on that subject - sorry.
MidKnight, please update to MC .Net 8.1 beta 1 and let me know if you still have the issue.

Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Re: multi timeframe strategy?

Postby Emmanuel » 19 Dec 2012

Hi

I agree with MidKnight,
CalcBar() will fire on each new bar for your data1 series only. That is why you put your lowest timeframe into the data1 slot.
We have to use data1 series only, I agree,

Do you know if the indicator of Data2, will be updated every minute in CalcBar() of Data1
even if Data2 are 1 hour resolution ?

I am not sure about that

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: multi timeframe strategy?

Postby Henry MultiСharts » 21 Dec 2012

Do you know if the indicator of Data2, will be updated every minute in CalcBar() of Data1 even if Data2 are 1 hour resolution ?
Hello Emmanuel,

Please provide more detailed description of this inquiry.
Also attach a workspace and sample script so that we can check it in our environment.

drolles
Posts: 50
Joined: 03 Dec 2012
Has thanked: 4 times

Re: multi timeframe strategy?

Postby drolles » 23 Dec 2012

Hi,

Thanks again all for the responses.

If CalcBar() only fires for how do you signal from a higher timeframe to a lower one? E.g. if I have a Bollinger Band strategy that signals at a higher timeframe of 1 hour and I want to backtest on 1 min data to get a better simulation of fills?

Thanks,

drolles

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: multi timeframe strategy?

Postby Henry MultiСharts » 11 Jan 2013

Hello drolles,

You can create a 1 hour chart for signal calculation and turn on 1 min Bar Magnifier.
Here is how signals are calculated.


Return to “MultiCharts .NET”