• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsRequiredToPlot bug when an Indicator is accessed from a Strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • caveat_lector
    replied
    Yes, setting BarsRequiredToPlot in my indicator's OnStateChange method on State.DataLoaded causes it to run correctly without error either attached to a chart or accessed from a Strategy.

    Leave a comment:


  • caveat_lector
    replied
    Thanks, I will try that.

    I was mislead by the methods and properties listed under NinjaScript > Language Reference > Strategy in the Help which include BarsRequiredToTrade, but not BarsRequiredToPlot. However, with more careful reading I see that the statement at the top is "The methods and properties covered in this section are unique to custom strategy development" which doesn't exclude the methods and properties of indicators. Mention there that strategies additionally support Indicator methods and properties would help avoid misinterpretation.

    Leave a comment:


  • NinjaTrader_Jim
    replied
    Hello caveat_lector,

    Thanks for your post.

    Strategies have the ability to plot as well, and when an indicator is added, the indicator will inherit the BarsRequiredToPlot property from the strategy. Setting this in the indicator's OnBarUpdate method or in the indicator's OnStateChange method on State.DataLoaded can have the indicator force its own BarsRequiredToPlot value.

    I have attached a test strategy and indicator that can illustrate.

    Please let us know if there is anything else we can do to help.
    Attached Files

    Leave a comment:


  • BarsRequiredToPlot bug when an Indicator is accessed from a Strategy

    This is posted under Strategy Development, because the error I am about to explain only occurs when an Indicator is accessed from a Strategy.

    I have developed an unusual proprietary Indicator that works well and I am currently coding a Strategy to trade automatically based on its indications. Despite not having an error message during extensive testing of the finished Indicator attached directly to a chart, when accessed from a Strategy there was a startup error message complaining that the code was trying to reference 5 bars back with only 4 bars loaded.

    The indicator only accesses 5 bars back, but needs to analyze patterns over a several hundred historic bars to be able to make reliable market indications. The number of historic bars needed depends complexly on various user settings, so I initially calculated and set a suitable BarsRequiredToPlot value in State.Configure rather than making the value a user setting in State.SetDefaults.

    I thought calculating and setting the value that way might have something to do with the error when the Indicator was accessed from a Strategy, so I commented-out the setting in State.Configure, made BarsRequiredToPlot a user-setting in State.SetDefaults, and passed a suitable value from the Strategy. That didn't change anything. I still had the error message.

    Then I put a Print statement in the indicator to print the BarsRequiredToPlot value and learned that when the Indicator was accessed from a Strategy the BarsRequiredToPlot value was always 20, regardless of the value passed from the Strategy or even hard-coded locally in the Indicator! However, when the Indicator was attached directly to a chart the printed BarsRequiredToPlot value was always whatever value I set and there was no error message.

    Another strange fact is that when the Indicator is attached directly to a chart it runs without an error message with any BarsRequiredToPlot value greater than 4, but when accessed from a Strategy there is the error message even though the printed BarsRequiredToPlot value is 20 ???

    I found experimentally that I could avoid the error and make the indicator work normally when accessed from a Strategy by setting a suitable BarsRequiredToPlot value in OnBarUpdate(), instead of in State.SetDefaults, like this:
    Code:
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBar == 0)
                {
                    BarsRequiredToPlot = 435;
                    return;
                }
    
                ... Other processing
    
            }
    Even though that works, something is obviously wrong.

Latest Posts

Collapse

Topics Statistics Last Post
Started by HiddenPhilosopher, Yesterday, 11:58 PM
1 response
10 views
0 likes
Last Post NT-Roland  
Started by vofupba6, Today, 02:54 AM
0 responses
6 views
0 likes
Last Post vofupba6  
Started by Johnny, Today, 02:37 AM
0 responses
5 views
0 likes
Last Post Johnny
by Johnny
 
Started by waliopaozae, Today, 01:44 AM
0 responses
9 views
0 likes
Last Post waliopaozae  
Started by Futurestrader00, Today, 01:35 AM
0 responses
12 views
0 likes
Last Post Futurestrader00  
Working...
X