Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Spread between S&P cash and futures

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

    Spread between S&P cash and futures

    Hello, I am trying to have a plot calculate the spread value between the S&P 500 cash and futures markets. Though I am having problems getting it to plot as all I get on the indicator panel on my chart is a prompt saying "Calculating..."

    I believe the problem may be because the trading hour templates are different between the instruments. Is that correct? I've included the code below.

    AddPlot(Brushes.Orange, "T");
    }
    else if (State == State.Configure)
    {

    AddDataSeries("ES 12-19", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
    AddDataSeries("^SP500", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
    }
    }

    protected override void OnBarUpdate()
    {
    Values[0][0] = Closes[2][0] - Closes[1][0];
    }

    Attached Files

    #2
    Hello edmata1109,

    Thank you for the post.

    You may be having an error, can you check the control center log tab?

    For this type of plotting you generally need to do two things which would be:

    Code:
    protected override void OnBarUpdate()
    {
    [B]if(CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1) return;
    if(BarsInProgress != 0) return; [/B]
    Values[0][0] = Closes[2][0] - Closes[1][0];
    }
    This would ensure you have data for all series and that you are only plotting for the primary series.

    Can you check if this assists in getting the indicator plotting?

    As an alternative, try adding different time frames of the same instrument and add a Print instead of plotting. This would just help to confirm if one instrument is failing to load.


    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 10-21-2019, 08:25 AM.

    Comment


      #3
      Jesse,

      Adding the CurrentBars and BarsInProgress objects allowed it to plot. Thank you for your help.

      Edgar

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      576 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 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
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X