Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CalculateOnBarClose issue

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

    CalculateOnBarClose issue

    I run an indicator on a 5 minute chart. The indicator does nothing but print a log message with
    CalculateOnBarClose set to true. I would expect to see the log message printed in the Log once for every 5 minutes. However, I am seeing many messages that seem to suggest that
    NT prints out the message for every tick. I did make sure "CalculateOnBarClose" is set to true
    when I added the indicator to the chart. What was wrong with the following indicator code ?

    Peter

    -------

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;
    }

    protected override void OnBarUpdate()
    {
    Log("Test CalculateOnBarClose", NinjaTrader.Cbi.LogLevel.Information);
    Plot0.Set(Close[0]);
    }

    #2
    Hello redbank199,

    Please see the link below.


    It needs to be the last statement in the Initialize() method.
    JasonNinjaTrader Customer Service

    Comment


      #3
      Originally posted by redbank199 View Post
      I run an indicator on a 5 minute chart. The indicator does nothing but print a log message with
      CalculateOnBarClose set to true. I would expect to see the log message printed in the Log once for every 5 minutes. However, I am seeing many messages that seem to suggest that
      NT prints out the message for every tick. I did make sure "CalculateOnBarClose" is set to true
      when I added the indicator to the chart. What was wrong with the following indicator code ?

      Peter

      -------

      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      CalculateOnBarClose = true;
      Overlay = false;
      PriceTypeSupported = false;
      }

      protected override void OnBarUpdate()
      {
      Log("Test CalculateOnBarClose", NinjaTrader.Cbi.LogLevel.Information);
      Plot0.Set(Close[0]);
      }
      If you see many messages it does not mean that they are printing every tick.
      You probably received a message for every historical bar on your chart.

      Comment


        #4
        Moving CalculateOnBarClose to the end of the Initialize method did fix the problem.

        However, this means the indicator wizard has a bug - the code in my original post was generated by the wizard; the generated code should have placed the call at the end of Initialize method.

        I am surprised to learn from this that where you put CalculateOnBarClose in Initialize
        would have impact on the execution of OnBarUpdate. I have thought that OnBarUpdate
        is not called until Initialize is called, and once Initialize is called, NT should know the
        I have set CalcualteOnBarClose to true, and therefore every call to OnBarUpdate would
        check against CalcualteOnBarClose flag, regardless of where I put CalculateOnBarClose
        in Initialize, and knows that OnBarUpdate should not be executed at all until a bar
        is completed.

        I guess I do not know how NT executes the script. Could you explain why the placement
        of CalculateOnBarClose in Initialize have impact on the execution of OnBarUpdate ?

        Comment


          #5
          Some of the NT supplied indicators, e. g., ParabolicSAR, do not place CalculateOnBarClose
          at the end of the Initialize call. These are bugs too and should be changed.

          Comment


            #6
            Not sure what you mean. CalculateOnBarClose can be placed anywhere in Initialize(). System indicators do NOT set CalculateOnBarClose settings for indicators.

            CalculateOnBarClose goes into Initialize(). OnBarUpdate() is absolutely influenced by what this setting is. OnBarUpdate() always happens after Initialize().
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Jason's post stated that CalculateOnBarClose needs to be the last statement in
              Initialize() method.

              So this Initialize() in ParabolicSAR (and other indicator codes) should be changed from

              protected override void Initialize()
              {
              Add(new Plot(Color.OrangeRed, PlotStyle.Dot, "Parabolic SAR"));
              CalculateOnBarClose = true; // Call 'OnBarUpdate' only as a bar closes
              Overlay = true; // Plots the indicator on top of price
              }

              to

              Add(...);
              Overlay ...;
              CalculateOnBarClose = true;

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rdtdale, Yesterday, 01:02 PM
              2 responses
              16 views
              0 likes
              Last Post rdtdale
              by rdtdale
               
              Started by TradeSaber, Today, 07:18 AM
              0 responses
              7 views
              0 likes
              Last Post TradeSaber  
              Started by PaulMohn, Today, 05:00 AM
              0 responses
              10 views
              0 likes
              Last Post PaulMohn  
              Started by ZenCortexAuCost, Today, 04:24 AM
              0 responses
              6 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by ZenCortexAuCost, Today, 04:22 AM
              0 responses
              3 views
              0 likes
              Last Post ZenCortexAuCost  
              Working...
              X