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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Carolscogginsi, Yesterday, 10:45 PM
        0 responses
        6 views
        0 likes
        Last Post Carolscogginsi  
        Started by RaddiFX, Yesterday, 10:15 AM
        2 responses
        15 views
        0 likes
        Last Post RaddiFX
        by RaddiFX
         
        Started by patrickmlee007, Yesterday, 09:33 AM
        2 responses
        18 views
        0 likes
        Last Post patrickmlee007  
        Started by magnatauren, 08-15-2020, 02:12 PM
        5 responses
        208 views
        0 likes
        Last Post RaddiFX
        by RaddiFX
         
        Started by rene69851, 05-02-2024, 03:25 PM
        1 response
        24 views
        0 likes
        Last Post rene69851  
        Working...
        X