Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicators are not plotting on strategy

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

    Indicators are not plotting on strategy

    I think I am pretty close, but not sure what is going on.

    I created a strategy with the strategy wizard and referencing some custom indicators that I created. The indicators plot fine on charts, but they will not plot on the strategy chart. (As an aside, I can't get the strategy to respond to the indicator either, so something is goofy).

    After a lot of searching, I have come up with this code:

    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
                Add(PeriodType.Day,1);
                Add(PeriodType.Week, 1);
                
                //Weekly Momentum plot
                Add(StrategyPlot(0));
                //Weekly Momentum slope plot
                Add(StrategyPlot(1));
                
                StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
                StrategyPlot(0).PanelUI = 2;
                
                StrategyPlot(1).Plots[0].PlotStyle = PlotStyle.Bar;
                StrategyPlot(1).Plots[0].Pen.Color = Color.Aquamarine;
                StrategyPlot(1).PanelUI = 2;
            
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                //Plots
    
                    StrategyPlot(0).Value.Set(EMAMomentum(Closes[2], 12, 10).Plot0[0]);
                    StrategyPlot(1).Value.Set(EMAMomentumSlope(Closes[2], 12, 10, 3).Plot0[0]);
    Any suggestions?

    #2
    I am trying to debug using print:

    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
                Add(PeriodType.Day,1);
                Add(PeriodType.Week, 1);
                
                //Weekly Momentum plot
                Add(StrategyPlot(0));
                //Weekly Momentum slope plot
                Add(StrategyPlot(1));
                
                StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
                StrategyPlot(0).PanelUI = 2;
                
                StrategyPlot(1).Plots[0].PlotStyle = PlotStyle.Bar;
                StrategyPlot(1).Plots[0].Pen.Color = Color.Aquamarine;
                StrategyPlot(1).PanelUI = 2;
                Print("Initialize");
            
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                //Plots
    
                StrategyPlot(0).Value.Set(EMAMomentum(Closes[2], 12, 10).Plot0[0]);
                StrategyPlot(1).Value.Set(EMAMomentumSlope(Closes[2], 12, 10, 3).Plot0[0]);
                Print("OnBarUpdate");
    Strangely enogh, I only get 'Initialize' in the output window. Not sure what this means, but it looks as if the OnBarUpdate method is not being processed...

    Comment


      #3
      A little more insight.

      The weekly periodtype seems to be the problem - well at least part of the problem. If I comment out the Add for the weekly, the following prints to output:
      Code:
              protected override void Initialize()
              {
                  CalculateOnBarClose = false;
                  Add(PeriodType.Day, 1);
      //            Add(PeriodType.Week, 1);
                  
                  //Weekly Momentum plot
                  Add(StrategyPlot(0));
                  //Weekly Momentum slope plot
                  Add(StrategyPlot(1));
                  
                  StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
                  StrategyPlot(0).PanelUI = 2;
                  
                  StrategyPlot(1).Plots[0].PlotStyle = PlotStyle.Bar;
                  StrategyPlot(1).Plots[0].Pen.Color = Color.Aquamarine;
                  StrategyPlot(1).PanelUI = 2;
                  Print("Initialize");
              
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  if (CrossAbove(SMA(10), SMA(25), 1))
                      EnterLong();
                  else if (CrossBelow(SMA(10), SMA(25), 1))
                      EnterShort();
                  
                  
                  //Plots
      
      //            StrategyPlot(0).Value.Set(EMAMomentum(Closes[1], 12, 10).Plot0[0]);
      //            StrategyPlot(1).Value.Set(EMAMomentumSlope(Closes[2], 12, 10, 3).Plot0[0]);
                  Print("OnBarUpdate");
                  Print(EMAMomentum(Closes[0],12, 10).Value[0] + ", " + EMAMomentum(Closes[1],12, 10).Value[0]);
                  
      //            Print(EMAMomentum(Closes[0],12, 10).Value[0] + ", " + EMAMomentum(Closes[1],12, 10).Value[0] + ", " + EMAMomentum(Closes[2],12, 10).Value[0]);
      However, nothing appears on the plot.

      If I un-comment only the weekly Add, then only "Initialize" prints to the output window (e.g., nothing prints to the output window from the OnBarUpdate method).

      And another thing that I have noticed: when I add the indicator to a standard chart the value of daily indicator is as expected for all time intervals. In the strategy however, the value for the primary period is correct, but the daily series is off by a multiple of ~53. Something strange is happening.

      Comment


        #4
        Narrowing this down some more.

        If I change the primary period to anything other than minutes then I get unexpected values for the indicator. - in the case of Day, it is off by a factor of ~53. I am guessing that when the period is set to a week the number is some astronomical amount and maybe causing some type of error.

        No error is listed in the log, but the strategy seemingly does not call the OnBarUpdate method.

        Do I need to hardcode the period into the indicator? Is this even possible?

        Any help at all would sure be appreciated.

        Comment


          #5
          Ok - looks like it is a bug - or perhaps something I did wrong in the Indicator code.

          The periodtype is not being passed/called correctly to the indicator. Specifically, the indicator requires that the periodtype be used twice, and it is not being applied twice, hence the incorrect value - and for a week it must be way too big for NT to handle. It seems like something should be reflected in the logs.

          If I copy and paste the indicator code into the strategy, and make periodtype adjustments as required, the value is calculated correctly. Hope for a work around, but nonetheless, pretty annoying.

          Any suggestions more than welcome.

          Comment


            #6
            Arrgh...

            Can't get this to work for the weekly time period - does not get to the OnBarUpdate method (as established via Print("OnBarUpdate")). Also does not work for any periodtype longer than one day (e.g., I tried a 7 day period and a 2 day period, neither processes OnBarUpdate).

            Comment


              #7
              Heh...

              Finally figured this out.

              The backtesting dates did not allow for enough data to be collected. Setting the start date back far enough has addressed all the problems!

              What a hair puller.

              Comment


                #8
                Glad to hear you've got it figured out.
                AustinNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                648 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                369 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                108 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                572 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X