How to set the MaxBarsBack in the .Net Editor

Questions about MultiCharts .NET and user contributed studies.
fareast1001
Posts: 2
Joined: 21 Sep 2013

How to set the MaxBarsBack in the .Net Editor

Postby fareast1001 » 21 Sep 2013

I am quite new to the .Net version.
Initially, I set the MaxBarsBack under the Strategy Properties windows, e.g. 200.
However, when I try to set MaxBarsBack in the StartCalc() method, e.g:
protected override void StartCalc() {
ExecInfo.MaxBarsBack=150;
}

It seems there is no change for my strategy. My strategy still calculates from the bar =200. How can I set the MaxBarsBack in .Net Editor??

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1502 times
Contact:

Re: How to set the MaxBarsBack in the .Net Editor

Postby JoshM » 22 Sep 2013

fareast1001 wrote:It seems there is no change for my strategy. My strategy still calculates from the bar =200. How can I set the MaxBarsBack in .Net Editor??

You're right; it does not (seem to) work with signals. Even if one sets the MaxBarsBack in the settings to a maximum of 200, and sets the ExecInfo.MaxBarsBack to 123 (so below the maximum of 200), the MaxBarsBack is still set to 200.

And if ExecInfo.MaxBarsBack is set to 300 (i.e. a higher maximum), the value is still set at 200 (the maximum in the properties).

Indicator:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
   public class MaxBarsBack_Test : IndicatorObject
    {
      public MaxBarsBack_Test(object _ctx):base(_ctx){}
      
        protected override void Create()
        {
      }

      protected override void StartCalc()
        {           
            ExecInfo.MaxBarsBack = 123;
      }

      protected override void CalcBar()
        {
            if (Bars.LastBarOnChart)
            {
                Output.WriteLine("Indicator: MaxBarsBack = {0}", ExecInfo.MaxBarsBack);
            }
      }
   }
}


Signal:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy
{
   public class MaxBarsBack_Test : SignalObject
    {
      public MaxBarsBack_Test(object _ctx):base(_ctx){}

        protected override void Create()
        {
      }
      
        protected override void StartCalc()
        {
            ExecInfo.MaxBarsBack = 123;
      }

      protected override void CalcBar()
        {
            if (Bars.LastBarOnChart)
            {
                Output.WriteLine("Strategy: MaxBarsBack = {0}", ExecInfo.MaxBarsBack);
            }
      }
   }
}


Settings:
* Indicator: auto-detect.
* Signal: maximum of 200 bars.

Output:

Code: Select all

Indicator: MaxBarsBack = 123
Strategy: MaxBarsBack = 200


MultiCharts Support: can this behaviour be changed? I think it will be beneficial if the MaxBarsBack property can also be set in signals.
(Or am I doing it in the wrong way? :) )

(Using MultiCharts .NET64 Version 8.7 Release (Build 7636), by the way).
These users thanked the author JoshM for the post:
MidKnight

fareast1001
Posts: 2
Joined: 21 Sep 2013

Re: How to set the MaxBarsBack in the .Net Editor

Postby fareast1001 » 22 Sep 2013

JoshM wrote:MultiCharts Support: can this behaviour be changed? I think it will be beneficial if the MaxBarsBack property can also be set in signals.
(Or am I doing it in the wrong way? :) )

(Using MultiCharts .NET64 Version 8.7 Release (Build 7636), by the way).

Yes, I have to set the MaxBarsBack for optimization.

User avatar
Henry MultiСharts
Posts: 9047
Joined: 25 Aug 2011
Has thanked: 1250 times
Been thanked: 2905 times

Re: How to set the MaxBarsBack in the .Net Editor

Postby Henry MultiСharts » 25 Sep 2013

Unfortunately that is not technically possible to set MaxBarsBack from the code. ExecInfo.MaxBarsBack is for returning the value that has been specified for the study in the Strategy Properties windows into the code, not for assigning this value.
These users thanked the author Henry MultiСharts for the post:
JoshM

cjwik
Posts: 4
Joined: 13 Dec 2013

Re: How to set the MaxBarsBack in the .Net Editor

Postby cjwik » 13 Dec 2013

You might consider to do proper coding (Microsoft codeing guidelines) as the .Net code has both the get and set on the property. To have a set indicate that you can set the value. Please remove the set or change it to private as it confuses us when we try to use your API. When you have a set you do believe that you can set the value and it will work.

Code: Select all

int MaxBarsBack { get; set; }

User avatar
Henry MultiСharts
Posts: 9047
Joined: 25 Aug 2011
Has thanked: 1250 times
Been thanked: 2905 times

Re: How to set the MaxBarsBack in the .Net Editor

Postby Henry MultiСharts » 17 Dec 2013

cjwik wrote:You might consider to do proper coding (Microsoft codeing guidelines) as the .Net code has both the get and set on the property. To have a set indicate that you can set the value. Please remove the set or change it to private as it confuses us when we try to use your API. When you have a set you do believe that you can set the value and it will work.

Code: Select all

int MaxBarsBack { get; set; }

MaxBarsBack is the property of the base class. The same property is used for both indicators and signals.
MaxBarsBack can be set from the code for the indicator only, though it can "get" for both indicators and signals.

cjwik
Posts: 4
Joined: 13 Dec 2013

Re: How to set the MaxBarsBack in the .Net Editor

Postby cjwik » 17 Dec 2013

Thank you for the explanation. I understand the solution behind it and where you are coming from. I am not trying to pick on the API implementation, but things like this makes it a bit challenging to get it to work. But well sometimes it is nice to get challenged :). If you would consider to have separate interfaces for the two then you would be able to solve this... but I do understand that you would have concern to make this change and break some code. Anyhow I understand how to work it now and can move forward. Thank you.


Return to “MultiCharts .NET”