MaxBarsBack and ICalculationInfo  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

MaxBarsBack and ICalculationInfo

Postby tradetree » 14 Nov 2013

I have gone through the .NET programming guide and the .NET help and found little to nothing on MaxBarsBack. The problem I have is that my strategy, newly converted from another platform, builds in the PLeditor but fails to run do to an exception for MaxBarsBack. I know I access many bars back in my strategy, I think about 100, so this is no surprise, but not being able to find any reference on MaxBarsBack is quite surprising.

The programmers guide talks about "auto detection" but that is not what I want. I have a setting I'm trying to put in for MaxBarsBack. I also posted about there not being any connection between C# interfaces and C# objects that implement the interface. Here is a good example:

So ICalculationInfo has a MaxBarsBack member, but there is no information on what object is instantiated as ICalculationInfo?

What object should I use and where should it be placed to set MaxBarsBack?

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

Re: MaxBarsBack and ICalculationInfo

Postby Andrew MultiCharts » 14 Nov 2013

Hello tradetree,

As we discussed in the live chat, you should put a correct value of MaxBarsBack in Strategy Properties.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: MaxBarsBack and ICalculationInfo

Postby JoshM » 14 Nov 2013

The programmers guide talks about "auto detection" but that is not what I want. I have a setting I'm trying to put in for MaxBarsBack. I also posted about there not being any connection between C# interfaces and C# objects that implement the interface.

(...)

What object should I use and where should it be placed to set MaxBarsBack?
I think you're confused between the MaxBarsBack for indicators and strategies:

Indicators: MaxBarsBack can be set to auto-detection in the indicator properties but also can be set programmatically in the code (see this thread for an example).

Strategies: MaxBarsBack can not be set to auto-detection and can not be set programmatically. It needs to be specified in the Strategy Properties setting (see Andrew's link).

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: MaxBarsBack and ICalculationInfo

Postby tradetree » 17 Nov 2013

Yes, one reason I'm confused is that this doesn't take the right approach. I am porting code from another platform that does this "MaxBarsBack" correctly. Here is an example case:

You have 100 bars on a chart, and after the first 20 bars come in you will go back with some calculation to the first bar. This would be 20 MaxBarsBack. After 60 bars come in you want to go back to the first bar. As far as I can tell you get an exception even though the data should be available. You can only go back to bar 40 when you are at bar 60 in CalcBar! That means that they are throwing away the data greater than MaxBarsBack. That is totally wrong! What could I be missing?

Here is another way to say it. I don't want the infrastructure to throw away any data. If I have 100 bars on a chart, at the last call to CalcBar I should be able to go back to the first bar for a calculation. Now if I change MaxBarsBack to 100, then the signal does not even look at any bars until all bars have gone by! Other platforms don't do such a strange thing.

One solution would be for me to create my own linked list for storing bar data. But why would they require that when they have a platform that is meant to help me code?

Here is even more information. Here is an output of my output window for my signals. The first number after "Chan" is the Bars.CurrentBar. The first number after the "Bars" is the bars back it will go. MaxBarsBack is 20, so I will get an exception on the next bar when I go back 21 bars, even though the Bars.CurrentBar will be 41 on that bar:
  • Chan: 40, Pt: 1050.3, 1048.7, 1049.3, Price: 1050.3, Dir: True, ATR: 4.095, Date: 9/13/2013 3:30:00 PM
    Bars: 20, 0, Time: 9/10/2013 4:00:00 PM, 9/13/2013 3:30:00 PM
    Vec: 9/10/2013 4:00:00 PM, 1042.14238333333, End: 9/13/2013 3:30:00 PM, 1048.63089147287

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: MaxBarsBack and ICalculationInfo  [SOLVED]

Postby JoshM » 18 Nov 2013

(...)
You have 100 bars on a chart, and after the first 20 bars come in you will go back with some calculation to the first bar. This would be 20 MaxBarsBack. After 60 bars come in you want to go back to the first bar. As far as I can tell you get an exception even though the data should be available. You can only go back to bar 40 when you are at bar 60 in CalcBar! That means that they are throwing away the data greater than MaxBarsBack. That is totally wrong! What could I be missing?
(...)
There are multiple ways to access data:

1) With the MaxBarsBack constraint
This is the default way, i.e. Bars.Close[1] etc.

2) Without the MaxBarsBack constraint
In this situation you can use the data of the whole data series; i.e. from Bars.FullSymbolData.Close[0] (first bar) to Bars.FullSymbolData.Close[Bars.FullSymbolData.Count] (last bar). See the MultiCharts programming manual, page 22, section 4.2.5 for this.

tradetree
Posts: 81
Joined: 29 Apr 2013
Location: www.threefoldmarkets.com
Has thanked: 12 times
Been thanked: 16 times
Contact:

Re: MaxBarsBack and ICalculationInfo

Postby tradetree » 18 Nov 2013

Your points cover the issue quite well within the constraints of using MC data objects.

I also solved it another way and we'll see if I ultimately like the outcome. I created my own linked list object and overrode the [] operator to create constructs like "Close[0]". I don't have to worry about going back too many bars because the linked list limits to the first bar in the series. This approach works for me, it will just be interesting to see if optimizing and back-testing suffer performance wise, as I'm copying all the data into my linked list. But what I like is that my data is not order inverted, ie Close[0] is the current bar, not the first bar. And the way my algorithm works it does not care if early bars are repeats of the first bar in the series.

(...)
You have 100 bars on a chart, and after the first 20 bars come in you will go back with some calculation to the first bar. This would be 20 MaxBarsBack. After 60 bars come in you want to go back to the first bar. As far as I can tell you get an exception even though the data should be available. You can only go back to bar 40 when you are at bar 60 in CalcBar! That means that they are throwing away the data greater than MaxBarsBack. That is totally wrong! What could I be missing?
(...)
There are multiple ways to access data:

1) With the MaxBarsBack constraint
This is the default way, i.e. Bars.Close[1] etc.

2) Without the MaxBarsBack constraint
In this situation you can use the data of the whole data series; i.e. from Bars.FullSymbolData.Close[0] (first bar) to Bars.FullSymbolData.Close[Bars.FullSymbolData.Count] (last bar). See the MultiCharts programming manual, page 22, section 4.2.5 for this.


Return to “MultiCharts .NET”