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

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.
    JesseNinjaTrader Customer Service

    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 cls71, Today, 04:45 AM
      0 responses
      1 view
      0 likes
      Last Post cls71
      by cls71
       
      Started by mjairg, 07-20-2023, 11:57 PM
      3 responses
      213 views
      1 like
      Last Post PaulMohn  
      Started by TheWhiteDragon, 01-21-2019, 12:44 PM
      4 responses
      544 views
      0 likes
      Last Post PaulMohn  
      Started by GLFX005, Today, 03:23 AM
      0 responses
      3 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      12 views
      0 likes
      Last Post XXtrader  
      Working...
      X