Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Indicator Multi Instrument Value

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

    Indicator Multi Instrument Value

    Hello!
    I'm Trying to plot Close prices into indicator from diffirent instruments
    Want to plot two lines in indicator.
    I added two Plots and one add data series.
    F.e. CL 11-19 & CL 12-19

    I'm using thic code to Plot them:

    if (CurrentBars[0] <= BarsRequiredToPlot || CurrentBars[1] <= BarsRequiredToPlot)
    return;
    if (BarsInProgress == 0){
    Values[0][0] = Closes[0][0];
    }

    if (BarsInProgress == 1){
    Values[1][0] = Closes[1][0];
    }

    But it only works in real-time data. How can I see it on History? It shows fixed difference for me between that instruments. But if I showing only one of them - it shows me correct prices. The trouble is that when I'm trying to display both of them - it shows me incorrect history data. Thanks.
    Last edited by YevhenShynkarenko; 10-16-2019, 05:18 PM.

    #2
    I found the problem. But need help how to resolve it.
    I updated my code to next:

    protected override void OnBarUpdate()
    {
    if(CurrentBar == 0)
    return;

    if(State == State.Historical)
    {
    current = Close[0];
    next = Closes[1][0];
    Value[0] = current;
    Values[1][0] = next;
    Print(ToTime(Time[0]));
    Print("Value 0: " + " : " + current);
    Print("Value:1-0: " + " : " + next);
    }
    if(State == State.Realtime)
    {
    }


    }

    And then I saw in Output window that it calculates two times on each bar (it prints me time two times). And on first calculation it shows me correct prices, but on second it sets both on "next" double. So then it draws in one single line my both plots. What I need to do to calculate it only once?

    Thanks.

    Comment


      #3
      Hello YevhenShynkarenko, thanks for your note.

      This works for me on historical data:


      Code:
              else if (State == State.Configure)
                  {
                      AddDataSeries("CL 11-19");
                  }
      
              ...
      
              protected override void OnBarUpdate()
              {
                  if(BarsInProgress == 0)
                  {
                      Plot0[0] = Closes[0][0];
                  }
      
                  if(BarsInProgress == 1)
                  {
                      Plot1[0] = Closes[1][0];
                  }
              }
      They print the same data while running on a CL 12-19 chart. I also attached my test script. Could you test the same?

      Attached Files
      Chris L.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mestor, 03-10-2023, 01:50 AM
      16 responses
      388 views
      0 likes
      Last Post z.franck  
      Started by rtwave, 04-12-2024, 09:30 AM
      4 responses
      31 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Started by yertle, Yesterday, 08:38 AM
      7 responses
      29 views
      0 likes
      Last Post yertle
      by yertle
       
      Started by bmartz, 03-12-2024, 06:12 AM
      2 responses
      22 views
      0 likes
      Last Post bmartz
      by bmartz
       
      Started by funk10101, Today, 12:02 AM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Working...
      X