Announcement

Collapse
No announcement yet.

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

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      68 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      55 views
      0 likes
      Last Post CarlTrading  
      Working...
      X