Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator using two data series

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

    #16
    MojoJojo - That's really cool

    I reduced the time of the primary to 10 seconds and now stuff looks to be happening so I'll be able to continue to tweak from there.

    One more question the chart is not building the EMA for the past instead it's only building for the future. I read something about tick replay. does that have anything to do with this? How would I have the EMA build for the entire days loaded from the primary chart?

    Thanks for the help it's appreciated!

    Comment


      #17
      Hello CopyPasteGhost,

      TickReplay is used to have Calculate .OnPriceChange or .OnEachTick work historically. Does this script set values on each tick?

      Have you used prints to see why the values are not being set?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        CopyPasteGhost, cool that it's coming together.

        I've noticed that the time comparison needed some tweaking otherwise it messes up the calculation.
        It can be left out entirely but because NT decides which data series gets updated first, I thought it wouldn't be a bad idea to include it.

        Code:
                    if(BarsInProgress == 0 || CurrentBars[0] < 1) {
                        return;
                    }
        
                    if( Calculate != Calculate.OnBarClose
                        || (Calculate == Calculate.OnBarClose
                            && Times[1][0].CompareTo(Times[0][0]) >= 0)
                        ) {
                        int barsAgo = CurrentBars[1] - BarsArray[1].GetBar(Times[0][0]);
                        Value[0] = EMA(Inputs[1], 24)[barsAgo];
                    }

        Comment


          #19
          Thanks I'll check it out and get back to you with any comments

          Comment


            #20
            Chelsea,

            I have the indicator set to update on each tick. (when I'm confirguring it at the time of adding it to the chart, not in code)
            Here is a screen shot:

            I moved the indicator to another panel. You can see new values are being plotted, but the historial data points are not. What did I miss?

            Current Code:

            protected override void OnBarUpdate()
            {
            if (!CurrentBars.Any(v => v < 1))
            {
            if (BarsInProgress == 0)
            {
            //Base Chart Time Frame - Skip
            return;
            }
            else if (BarsInProgress == 1)
            {
            if (Calculate != Calculate.OnBarClose || (Calculate == Calculate.OnBarClose && Times[1][0].CompareTo(Times[0][0]) >= 0))
            {
            int barsAgo = CurrentBars[1] - BarsArray[1].GetBar(Times[0][0]);
            Value[0] = EMA(Inputs[1], 24)[barsAgo];
            }

            }
            }
            }

            Thanks

            Comment


              #21
              Hello CopyPasteGhost,

              Its hard say.

              I recommend using prints to understand the behavior.
              Below is a link to a forum post that demonstrates with videos.


              If you print the Time[0] and BarsInProgress outside of any conditions does the print appear for each historical bar of BarsInProgress 1?
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Ok Let me try and I'll get back to you with results

                Comment


                  #23
                  For example when putting an indicator that is calculated every 5 minutes on a chart with a period of 1 minute there won't be a new value for the indicator every bar, therefore it needs to be repeated so a line plot can connect them. I wrote the code for the scenario where the time periods are reversed.


                  Code:
                              } else if (State == State.Configure) {
                                  this.AddDataSeries(BarsPeriodType.Second, secondarySeriesPeriod);
                                  fastSeriesIndex = BarsPeriod.Value < secondarySeriesPeriod ? 0 : 1;
                  The fastSeriesIndex assignment only works if the BarsPeriodType is the same.

                  Code:
                              if(CurrentBars.Any(v => v < 2)
                                  || BarsInProgress != fastSeriesIndex
                                  ) {
                                  return;
                              }
                  
                              Value[0] = Value[1];
                              int barsAgo = CurrentBars[1] - BarsArray[1].GetBar(Times[0][0]);
                              if(barsAgo >= 0) {
                                  Value[0] = EMA(Inputs[1], 24)[barsAgo];
                              }
                  Attached Files

                  Comment


                    #24
                    Hi MojoJojo, Chelsea

                    Sorry it's taken a while to get back to you. I've slimed down the code and cleaned it up a bit.
                    Code:
                     
                    protected override void OnStateChange()
                            {
                                if (State == State.SetDefaults)
                                {
                                    Description = @"Create a custom EMA line for any period and any instrument";
                                    Name = "Custom EMA For Any Instrument";
                                    Calculate = Calculate.OnEachTick;
                                    IsOverlay = true;
                                    BarsRequiredToPlot = 1;
                                    Period1 = 165;
                                    Period2 = 55;
                                    MinuteChartValue = 1;
                    
                                    AddPlot(new Stroke(Brushes.White, DashStyleHelper.Dash, 2), PlotStyle.HLine, MinuteChartValue + "M EMA " + Period1);
                                    AddPlot(new Stroke(Brushes.PaleTurquoise, DashStyleHelper.Dash, 2), PlotStyle.HLine, MinuteChartValue + "M EMA " + Period2);
                                }
                                else if (State == State.Configure)
                                {
                                    AddDataSeries(BarsPeriodType.Minute, MinuteChartValue);
                                }
                            }
                    
                            protected override void OnBarUpdate()
                            {
                                if (!CurrentBars.Any(v => v < 1))
                                {
                                    if (BarsInProgress == 0) { return; }
                                    if (BarsInProgress == 1)
                                    {
                                        int barsAgo = CurrentBars[1] - BarsArray[1].GetBar(Times[0][0]);
                                        Values[0][0] = EMA(Inputs[1], Period1)[barsAgo];
                                        Values[1][0] = EMA(Inputs[1], Period2)[barsAgo];
                                    }
                                }
                            }
                            [Range(1, int.MaxValue), NinjaScriptProperty]
                            [Display(ResourceType = typeof(Custom.Resource), Name = "Period1", GroupName = "Indicator Parameters", Order = 0)]
                            public int Period1 { get; set; }
                    
                            [Range(1, int.MaxValue), NinjaScriptProperty]
                            [Display(ResourceType = typeof(Custom.Resource), Name = "Period2", GroupName = "Indicator Parameters", Order = 0)]
                            public int Period2 { get; set; }
                    
                            [Range(1, int.MaxValue), NinjaScriptProperty]
                            [Display(ResourceType = typeof(Custom.Resource), Name = "Minute Chart Value", GroupName = "Indicator Parameters", Order = 1)]
                            public int MinuteChartValue { get; set; }
                    This is working for all new values and MOST historical values. When I'm using a chart of the same bar type I don't have any problems if I put this indicator on a renko chart there are certain historical points where my lines show n/a in the data box. You can see this by adding this indicator to a renko with brick size 5 as shown in the attachaed image.

                    I'm not getting any errors just N/A...

                    Any ideas? Thanks for the support in advance!

                    Comment


                      #25
                      Hello CopyPasteGhost,

                      I still recommend using prints to understand the behavior of any script. If you print the Time, BarsInProgress, and condition values, are you seeing in the prints that you are setting the plot on every primary bar close?


                      Below is a link to an example of plotting information from added series with higher time frames.
                      https://ninjatrader.com/support/foru...196#post820196
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      663 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      376 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      110 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      575 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      580 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X