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 cmoran13, Yesterday, 01:02 PM
        0 responses
        29 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        21 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        95 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X