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 cre8able, Today, 01:16 PM
      2 responses
      9 views
      0 likes
      Last Post cre8able  
      Started by chbruno, 04-24-2024, 04:10 PM
      3 responses
      48 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by samish18, Today, 01:01 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by WHICKED, Today, 12:56 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by WHICKED, Today, 12:45 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X