Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Spread Strategy As Indicator, StrategyPlot

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

    Spread Strategy As Indicator, StrategyPlot

    I may be an idiot but I have been trying to get a strategy to print a spread of two tickers for me with zero luck. Anyone have an example? I can't even get ANYTHING to print on the StrategyPlot... user error I know but I would appreciate the help of a small tip or pointer.

    #2
    Please post what you have already.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, here it is. When I add this strategy, for example to a NYA chart, I get two StrategyPlot indicators at the bottom but nothing shows up in them.

      Code:
          public class ZenVolAnalysis : Strategy
          {
              #region Variables
              // Wizard generated variables
              // User defined variables (add any user defined variables below)
              #endregion
      
              /// <summary>
              /// This method is used to configure the strategy and is called once before any strategy method is called.
              /// </summary>
              protected override void Initialize()
              {
                  CalculateOnBarClose = false;
                  
                  //Add(PeriodType.Minute, 3);
                  Add("VOL", PeriodType.Minute, 30);
                  Add("UVOL", PeriodType.Minute, 30);
                  Add("DVOL", PeriodType.Minute, 30);
                  
                  /* Add our blank placeholder indicators. The parameter we pass in is used to distinguish the two
                  indicators from each other. */
                  Add(StrategyPlot(0));
                  Add(StrategyPlot(1));
                  
                  StrategyPlot(0).Plots[0].PlotStyle = PlotStyle.Bar;
                  StrategyPlot(1).Plots[0].PlotStyle = PlotStyle.Bar;
                  
                  // Set the color for the indicator plots
                  StrategyPlot(0).Plots[0].Pen.Color = Color.LawnGreen;
                  StrategyPlot(1).Plots[0].Pen.Color = Color.Crimson;
              
                  // Set the panel which the plots will be placed on. 1 = price panel, 2 = panel under the price panel, etc.
                  StrategyPlot(0).PanelUI = 2;
                  StrategyPlot(1).PanelUI = 3;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  if(Input[0] != 0)
                  {
                      StrategyPlot(0).Value.Set(Math.Round(BarsArray[1][0]/Input[0],2));
                      StrategyPlot(1).Value.Set(Math.Round(BarsArray[2][0]/Input[0],2));
                  }
              }

      Comment


        #4
        Thanks for posting the code tradinginzen - did you also check in realtime? This is limited in functionality and will only work on realtime charts.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        60 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        147 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        284 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X