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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X