Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

External Data Indicator issue

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

    External Data Indicator issue

    I have made an indicator that plots an external symbol as an indicator in its own pane. It works with one problem. To check out that it works properly, I called the same instrument series as on the primary chart. As long as the period of the main chart matches the period in the AddDataSeries expression, the close in the primary chart matches the close in the indicator pane. However if I change the Primary Chart time period to something else, then the two closes no longer match. For example in the AddDataSeries code I have BarsPeriodType set at 1 minute. As long at the Chart itself is on one minute there is a match, but if I change the Chart to 3 minutes, then the indicator pane values get off a little bit.

    Is there a way to make the secondary data series automatically be on the same time interval as the main chart? Perhaps something that calls and returns the current chart time period, that can be put into a variable. That variable could be used when the secondary data series is called. And how would I do that?

    Here is how I am setting up the secondary data series. Symbol is what the user can change from the Indicator variables panel.

    else if (State == State.Configure)
    {
    AddDataSeries(Symbol, Data.BarsPeriodType.Minute,1,Data.MarketDataType.L ast);

    }
    Thanks,
    bigtee

    #2
    Hello bigtee,

    I want to clarify what you are comparing.

    Are you only looking at the close price?
    Say a 3 minute primary series and 1 minute series are added to the script. If Calculate is set to OnBarUpdate, the price of the 1 minute series should match a separate 1 minute chart each time the bar closes.

    However, if you are supplying a series to an indicator, changing the interval will drastically change the results of the calculations.

    What are you comparing?
    May we have output from prints in the script as well as screenshots of the chart you are comparing this to?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Some clarification... There is a chart.... Assume the Input Data Series for the chart is NQ 03-17, on some time period.
      In an indicator panel below the chart, this indicator will plot the Close of any instrument. This instrument is selected by the user from the Edit Indicators screen. The idea is that one can plot the close of a different instrument from that in the chart itself, and then view how the two symbols are tracking or not tracking each other. So I may have the ES 03-17 plotted in the indicator pane. Or maybe the TICK, or ADD or whatever. The attached pic "Goal" will show what it will do when completed.

      To test it out, I have set the data series in the indicator to be the same as that in the main chart. That will allow me to see that the closing values in the chart to the closing values in the indicator. They are in fact the same as long as the Chart time interval is the same as that used in the AddDataSeries code. However if the two are different, then the values are NOT the same. This is a problem as sometimes I may wish to use a chart time interval that is different than that in the indicator code.

      Ideally there would be a way to make the time interval called in the indicator code automatically detect the time interval used by the main chart and set the indicator data series to the same time interval? Is there a way to do this?

      Here is the majority of the relevant code... There is only one plot. The indicator works On Price Change.


      else if (State == State.Configure)
      {
      AddDataSeries(Symbol, Data.BarsPeriodType.Minute,1,Data.MarketDataType.L ast);// adds external symbol
      // Symbol is a variable the user can enter from the Edit Indicators screen.
      }


      protected override void OnBarUpdate()
      {
      //Add your custom indicator logic here.

      if (CurrentBars[0] < 1 || CurrentBars[1] < 1 ) return; // do not process unless we have a bar in each dataseries.
      // assign plots
      Values[0][0] = Closes[1][0]; // plot 0 Close
      }


      For debug, l have changed the main chart plot to a Line on Close, and plotted the indicator in the same pane. The two lines should lay on top of each other, and they do, as long as the time interval in the main chart is the same as that called in the indicator code when adding the data series..

      However if I change the Chart Input time interval to something other than that of the added Data Series in the code, then the two no longer match.
      In picture, the Red line is that actual data series on 3 minute, while the blue line is the same data series called from the indicator, except that it is initiated as a 1 min interval. The attached pic will show the issue.

      If this does not make sense, ask again.

      Thks

      bigtee
      Attached Files

      Comment


        #4
        Hello bigtee,

        I'd like to simplify what you are trying to compare.

        To clarify, you have added a secondary series to an indicator and you are setting the plot of this indicator to the close price of this secondary series, is this correct?

        On the chart, you have set the chart style to Line on close, is this correct?

        In your script, likely you are updating the plot each time the added series updates which is where the difference in price is. The plot is synchronized to the primary series, meaning there will only be one bar for each primary series and there will not be a bar slot for each bar of the added series.

        Lets take a 3 minute series and a 1 minute series as an example

        At 10:03 BarsInProgress 0 triggers OnBarUpdate (OBU) and set the value to 1000.00.
        BarsInProgress 1 also triggers at 10:03 and sets the plot value for the 10:03 bar to 1000.00.
        At 10:04 BarsInProgress 1 triggers OBU and sets the plot value for the 10:03 bar to 1000.25.
        At 10:05 BarsInProgress 1 triggers OBU and sets the plot value for the 10:03 bar to 1000.50.
        At 10:06 BarsInProgress 0 triggers OBU and sets the plot value for the 10:06 bar to 1000.50.

        On the chart, the 10:03 close price for the 3 minute series is 1000.0, but the plot is set to the last update that occured before the next bar closed. So this is the 10:05 update and the plot shows a price of 1000.50.

        To correct this, only set the plot to the value of the secondary series when the primary plot is triggered.
        In other words, add a check for BarsInProgress to be 0 before allowing the plot to be set.
        Code:
        protected override void OnBarUpdate()
        {
        	if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || BarsInProgress != 0)
        		return;
        			
        	Values[0][0] = Closes[1][0];
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          That worked great! Thank you so much.

          bigtee

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          557 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          324 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          545 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          547 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X