Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting Secondary Series Indicators

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

    Plotting Secondary Series Indicators

    Hi,

    I am looking for some advice on how to get my strategy to plot the secondary series correctly. I have a secondary data series in a test strategy and have added the MACD indicator to both the primary and secondary data. After much trial and error, the primary MACD plots correctly, but the secondary is stepped. Other than that it seems to be working correctly.

    Not sure what I'm doing wrong, but is there a way to plot this correctly (not stepped)? Once I get this working, I also plan to add the Stochastics and Swing indicator to both primary and secondary series and use them in a strategy

    Here is my current test code:



    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class MACDWithSecondarySeriesStrategy : Strategy
    {
    private MACD primaryMACD;
    private MACD secondaryMACD;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = "Strategy with primary and secondary plots";
    Name = "MACDWithSecondarySeries";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;

    // Default parameters
    MACDFast = 12;
    MACDSlow = 26;
    MACDSmooth = 9;
    PlotPrimaryMACD = true;
    PlotSecondaryMACD = true;


    SecondarySeriesPeriod = 60;

    AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Line, "SecondaryMACD");
    AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Line, "SecondaryMACDAvg");
    AddPlot(new Stroke(Brushes.Gray, 2), PlotStyle.Bar, "SecondaryMACDDiff");
    }
    else if (State == State.Configure)
    {
    // Add secondary bars series
    AddDataSeries(BarsPeriodType.Minute, SecondarySeriesPeriod);
    }
    else if (State == State.DataLoaded)
    {

    primaryMACD = MACD(Closes[0], MACDFast, MACDSlow, MACDSmooth);
    secondaryMACD = MACD(Closes[1], MACDFast, MACDSlow, MACDSmooth);

    if (PlotPrimaryMACD)
    {

    AddChartIndicator(primaryMACD);
    }
    }
    }

    protected override void OnBarUpdate()
    {
    // Ensure we have enough bars to calculate
    if (CurrentBars[1] < SecondarySeriesPeriod)
    return;


    if (PlotSecondaryMACD)
    {
    Values[0][0] = secondaryMACD.Default[0];
    Values[1][0] = secondaryMACD.Avg[0];
    Values[2][0] = secondaryMACD.Diff[0];
    }


    if (BarsInProgress != 0)
    return;

    // Example strategy logic
    if (primaryMACD.Diff[0] > 0 && primaryMACD.Diff[1] <= 0)
    {

    EnterLong();
    }
    else if (primaryMACD.Diff[0] < 0 && primaryMACD.Diff[1] >= 0)
    {

    EnterShort();
    }
    }

    region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="MACD Fast", Description="Fast period for MACD", Order=1, GroupName="MACD Parameters")]
    public int MACDFast { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="MACD Slow", Description="Slow period for MACD", Order=2, GroupName="MACD Parameters")]
    public int MACDSlow { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="MACD Smooth", Description="Smoothing period for MACD", Order=3, GroupName="MACD Parameters")]
    public int MACDSmooth { get; set; }

    [NinjaScriptProperty]
    [Display(Name="Plot Primary MACD", Description="Show primary MACD plot", Order=4, GroupName="MACD Parameters")]
    public bool PlotPrimaryMACD { get; set; }

    [NinjaScriptProperty]
    [Display(Name="Plot Secondary MACD", Description="Show secondary MACD plot", Order=5, GroupName="MACD Parameters")]
    public bool PlotSecondaryMACD { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Secondary Series Period", Description="Period for secondary bars series (minutes)", Order=1, GroupName="Secondary Series")]
    public int SecondarySeriesPeriod { get; set; }
    #endregion
    }
    }

    Thank you,
    Ray​

    #2
    Hello,

    Thanks for your message.


    First, if you add an indicator via AddChartIndicator(), it cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code (please make sure though the hosting strategy has the same AddDataSeries()
    ​​ call included as well).

    AddChartIndicator()

    Also, for any bar that lacks a value due to no update, assign it the value from the previous bar

    The link below contains an example that demonstrates supplying a secondary series as the input series to an indicator and plotting the values over the primary series chart bars.



    https://support.ninjatrader.com/s/article/Developer-Example-Higher-Time-Frame-Indicator-Plot?language=en_US


    Comment


      #3
      Hi Helom,

      Thank you for the info. I will look at the example you provided. Based on what you said, I have to create a new MACD indicator to plot an indicator with a secondary data series? I'm assuming I can just copy the MACD indicator and then add the desired data series to it?

      Thank you,
      Ray

      Comment


        #4
        That is correct.

        You can create a copy of the MACD script by opening the MACD script in the NinjaScript editor. Right-click the background and select "Save-as". You can enter a unique name and click save. This way it will create a copy from the MACD script and you can add the series to it manually.

        Within your host strategy, you will have to reference this new copy of the MACD that you have added the data series to it.

        Comment


          #5
          Have one more question.

          Is it only the Plotting of the secondary series indicator that is not correct? I can assume that any trading logic I use with regards to the indicator using the secondary series within the strategy should be correct?

          Thank you,
          Ray

          Comment


            #6
            Hello raysinred

            Thanks for your reply.


            Overall we don't see any issues with your script but we can only know for certain once you run and test your script.

            Are you experiencing issues with the logic of your script? Is it not behaving as you expect?

            To understand any unexpected behavior of a NinjaScript, such as placing orders or not placing orders when expected, drawing or not drawing objects when expected, or understanding why any actions are happening or not happening, it is necessary to add prints to the script that print the values used throughout the logic of the script to understand how the script is evaluating.

            The article below contains tips and steps to follow if you need to troubleshoot your script.


            Developer Guide - Debugging using Print() and TraceOrders


            Feel free to reach back with any other questions

            Comment


              #7
              Hi Helom,

              Thank you for the reply. No, I don't have any issue right now with logic, but I have not got there just yet. I just wanted to make sure that I don't have to worry about any logic issues with secondary series even if the plots are not as nice looking as if I used the method you outlined with a separate indicator.

              But, I have added the Stochastics and Swing indicator as I had mentioned earlier, and I'm having an issue with plotting of the MACD and Stochastics for the secondary series. Not sure why, but I can't get the Secondary Stochastics to plot at all, and it seems to always want to plot the secondary MACD. Here is my updated code.

              Any help is greatly appreciated.

              Thanks,
              Ray



              namespace NinjaTrader.NinjaScript.Strategies
              {
              public class MACDWithSecondarySeriesStrategy : Strategy
              {
              private MACD primaryMACD;
              private MACD secondaryMACD;
              private Stochastics primaryStochastics;
              private Stochastics secondaryStochastics;
              private Swing primarySwing;
              private Swing secondarySwing;

              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = "Strategy with MACD, Stochastic and Swing indicators on primary and secondary series";
              Name = "MACDWithSecondarySeries";
              Calculate = Calculate.OnBarClose;
              IsOverlay = false;

              SecondarySeriesPeriod = 60;

              // Default parameters for MACD
              MACDFast = 12;
              MACDSlow = 26;
              MACDSmooth = 9;
              PlotPrimaryMACD = true;
              PlotSecondaryMACD = true;

              // Default parameters for Stochastic
              StochPeriod = 14;
              StochK = 3;
              StochD = 3;
              PlotPrimaryStochastics = true;
              PlotSecondaryStochastics = true;

              // Default parameters for Swing
              PrimarySwingStrength = 5;
              SecondarySwingStrength = 5;
              PlotPrimarySwing = true;
              SwingPeriod = 100;

              // Add plots for secondary MACD
              if (PlotSecondaryMACD)
              {
              AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Line, "SecondaryMACD");
              AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Line, "SecondaryMACDAvg");
              AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, "SecondaryMACDDiff");
              }

              // Add plots for secondary Stochastic
              if (PlotSecondaryStochastics)
              {
              AddPlot(new Stroke(Brushes.Green, 2), PlotStyle.Line, "SecondaryStochK");
              AddPlot(new Stroke(Brushes.Purple, 2), PlotStyle.Line, "SecondaryStochD");
              }
              }
              else if (State == State.Configure)
              {

              AddDataSeries(BarsPeriodType.Minute, SecondarySeriesPeriod);
              }
              else if (State == State.DataLoaded)
              {

              primaryMACD = MACD(Closes[0], MACDFast, MACDSlow, MACDSmooth);
              secondaryMACD = MACD(Closes[1], MACDFast, MACDSlow, MACDSmooth);


              primaryStochastics = Stochastics(StochPeriod, StochK, StochD);
              secondaryStochastics = Stochastics(BarsArray[1], StochPeriod, StochK, StochD);


              primarySwing = Swing(PrimarySwingStrength);
              secondarySwing = Swing(BarsArray[1], SecondarySwingStrength);

              if (PlotPrimaryMACD)
              {
              AddChartIndicator(primaryMACD);
              }

              if (PlotPrimaryStochastics)
              {
              AddChartIndicator(primaryStochastics);
              }

              if (PlotPrimarySwing)
              {
              AddChartIndicator(primarySwing);
              }
              }
              }

              protected override void OnBarUpdate()
              {

              if (CurrentBars[1] < SecondarySeriesPeriod)
              return;


              if (PlotSecondaryMACD)
              {
              Values[0][0] = secondaryMACD.Default[0]; // SecondaryMACD plot
              Values[1][0] = secondaryMACD.Avg[0]; // SecondaryMACDAvg plot
              Values[2][0] = secondaryMACD.Diff[0]; // SecondaryMACDDiff plot
              }


              if (PlotSecondaryStochastics)
              {
              Values[3][0] = secondaryStochastics.K[0]; // SecondaryStochK plot
              Values[4][0] = secondaryStochastics.D[0]; // SecondaryStochD plot
              }

              if (BarsInProgress != 0)
              return;

              // Example strategy logic
              if (primaryMACD.Diff[0] > 0 && primaryMACD.Diff[1] <= 0)
              {

              EnterLong();
              }
              else if (primaryMACD.Diff[0] < 0 && primaryMACD.Diff[1] >= 0)
              {

              EnterShort();
              }
              }​

              region Properties
              // MACD Properties
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="MACD Fast", Description="Fast period for MACD", Order=1, GroupName="MACD Parameters")]
              public int MACDFast { get; set; }

              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="MACD Slow", Description="Slow period for MACD", Order=2, GroupName="MACD Parameters")]
              public int MACDSlow { get; set; }

              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="MACD Smooth", Description="Smoothing period for MACD", Order=3, GroupName="MACD Parameters")]
              public int MACDSmooth { get; set; }

              [NinjaScriptProperty]
              [Display(Name="Plot Primary MACD", Description="Show primary MACD plot", Order=4, GroupName="MACD Parameters")]
              public bool PlotPrimaryMACD { get; set; }

              [NinjaScriptProperty]
              [Display(Name="Plot Secondary MACD", Description="Show secondary MACD plot", Order=5, GroupName="MACD Parameters")]
              public bool PlotSecondaryMACD { get; set; }

              // Stochastic Properties
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Stochastic Period", Description="Period for Stochastic", Order=1, GroupName="Stochastic Parameters")]
              public int StochPeriod { get; set; }

              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Stochastic %K", Description="%K period for Stochastic", Order=2, GroupName="Stochastic Parameters")]
              public int StochK { get; set; }

              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Stochastic %D", Description="%D period for Stochastic", Order=3, GroupName="Stochastic Parameters")]
              public int StochD { get; set; }

              [NinjaScriptProperty]
              [Display(Name="Plot Primary Stochastic", Description="Show primary Stochastic plot", Order=4, GroupName="Stochastic Parameters")]
              public bool PlotPrimaryStochastics { get; set; }

              [NinjaScriptProperty]
              [Display(Name="Plot Secondary Stochastic", Description="Show secondary Stochastic plot", Order=5, GroupName="Stochastic Parameters")]
              public bool PlotSecondaryStochastics { get; set; }

              // Swing Properties
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Primary Swing Period", Description="Period for primary Swing", Order=1, GroupName="Swing Parameters")]
              public int PrimarySwingStrength { get; set; }

              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Secondary Swing Period", Description="Period for secondary Swing", Order=2, GroupName="Swing Parameters")]
              public int SecondarySwingStrength { get; set; }

              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Swing Strength", Description="Strength for Swing identification", Order=3, GroupName="Swing Parameters")]
              public int SwingPeriod { get; set; }

              [NinjaScriptProperty]
              [Display(Name="Plot Primary Swing", Description="Show primary Swing plot", Order=4, GroupName="Swing Parameters")]
              public bool PlotPrimarySwing { get; set; }

              // Secondary Series Property
              [NinjaScriptProperty]
              [Range(1, int.MaxValue)]
              [Display(Name="Secondary Series Period", Description="Period for secondary bars series (minutes)", Order=1, GroupName="Secondary Series")]
              public int SecondarySeriesPeriod { get; set; }
              #endregion
              }
              }​

              Comment


                #8
                Hello Ray,

                You should have 3 separate indicator scripts for each indicator you want using a secondary series for logic.

                Each of these would be called by the strategy, saved to variable, and supplied to AddChartIndicator() in the strategy.

                Each of these indicators as well as the host strategy would internally call the same AddDataSeries(BarsPeriodType.Minute, 1); call in State.Configure.

                In each indicator, the logic would be run when BarsInProgress is 1 to use the secondary series. The plot values will be synchronized with the primary series only. This means if no value is set, then set the value of the previous bar's value.

                Note, the use of the SecondarySeriesPeriod variable would be using AddDataSeries() dynamically which is not supported.
                This will cause issues when optimizing in the Strategy Analyzer.
                A hard coded value would be necessary to be fully supported.

                From the Desktop SDK:
                "Warning
                Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.

                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  Ok, I'm a little confused now. I thought Helom said that you don't need a separate indicator for the secondary series indicator if you just want to use it in the logic. I'm not as worried about the plotting being 100% accurate. But now it sounds like you are saying I need a separate indicator just so the logic and strategy work correctly if I use an indicator against and added series? There is no way to Add a Data Series and use indicators against that added data series without using a separate indicator?

                  Thanks,
                  Ray

                  Comment


                    #10
                    Hello Ray,

                    You can call the original indicator that does not have the added series modifications if you want the values in the plot calculated with the primary series data.
                    If you want the added series indicator call the copy indicator that was modified to add a series and perform calculations with the added series data.

                    "There is no way to Add a Data Series and use indicators against that added data series without using a separate indicator?"

                    You can call an indicator that has a secondary series as the Input series parameter, but you cannot use AddChartIndicator() to add that indicator to a chart. You would only be able to use the values.

                    To add the indicator to the chart, the indicator would need to have the added series added directly and the logic modified to calculate using the data of the added series.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      Thank you for the information. I have made a few changes. I have not used separate indicators, but for the most part, it is working how I would like. I just have a couple issues/questions.

                      1. For some reason I cannot get the Swing indicator to plot on the main price panel. No matter what I do, it still plots on another panel. Being that this is added using AddChartIndicator(), I'm not sure what the issue is.

                      2. Is there a way to choose the panel for the AddPlot()s?

                      Any help/insight is appreciated.

                      Thanks,
                      Ray


                      namespace NinjaTrader.NinjaScript.Strategies
                      {
                      public class MACDWithSecondarySeriesStrategy : Strategy
                      {
                      region Startup

                      private MACD primaryMACD;
                      private MACD secondaryMACD;
                      private MACDwwma primaryMACDw;
                      private MACDwwma secondaryMACDw;
                      private Stochastics primaryStochastics;
                      private Stochastics secondaryStochastics;
                      private Swing primarySwing;
                      private Swing secondarySwing;
                      private bool mACDType


                      #endregion

                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = "Strategy with MACD, Stochastic and Swing indicators on primary and secondary series";
                      Name = "MACDWithSecondarySeries";
                      Calculate = Calculate.OnBarClose;
                      EntriesPerDirection = 1;
                      EntryHandling = EntryHandling.UniqueEntries;
                      IsExitOnSessionCloseStrategy = false;
                      ExitOnSessionCloseSeconds = 30;
                      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                      OrderFillResolution = OrderFillResolution.Standard;
                      Slippage = 0;
                      StartBehavior = StartBehavior.WaitUntilFlat;
                      TimeInForce = TimeInForce.Gtc;
                      TraceOrders = true;
                      // RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                      RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
                      StopTargetHandling = StopTargetHandling.PerEntryExecution;
                      IsAutoScale = true;
                      IsOverlay = false;

                      region Default Parameters

                      SecondarySeriesPeriod = 5;
                      PrimaryMACDFast = 12;
                      PrimaryMACDSlow = 26;
                      PrimaryMACDSmooth = 9;
                      SecondaryMACDFast = 12;
                      SecondaryMACDSlow = 26;
                      SecondaryMACDSmooth = 9;
                      PlotPrimaryMACD = true;
                      PlotSecondaryMACD = true;
                      PrimaryStochPeriod = 14;
                      PrimaryStochK = 3;
                      PrimaryStochD = 3;
                      SecondaryStochPeriod = 14;
                      SecondaryStochK = 3;
                      SecondaryStochD = 3;
                      PlotPrimaryStochastics = true;
                      PlotSecondaryStochastics = false;
                      PrimarySwingStrength = 5;
                      SecondarySwingStrength = 5;
                      PlotPrimarySwing = false;
                      StopLossPercent = 1.0;

                      #endregion

                      // Add plots for secondary MACD
                      if (PlotSecondaryMACD)
                      {
                      // BarsRequiredToPlot = 10;
                      AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Line, "SecondaryMACD");
                      AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Line, "SecondaryMACDAvg");
                      AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, "SecondaryMACDDiff");
                      }

                      // Add plots for secondary Stochastic
                      if (PlotSecondaryStochastics)
                      {
                      // BarsRequiredToPlot = 10;
                      AddPlot(new Stroke(Brushes.Green, 5), PlotStyle.Line, "SecondaryStochK");
                      AddPlot(new Stroke(Brushes.Purple, 5), PlotStyle.Line, "SecondaryStochD");
                      }
                      }

                      else if (State == State.Configure)
                      {

                      SetStopLoss(CalculationMode.Percent, StopLossPercent);
                      AddDataSeries(BarsPeriodType.Day, 7);



                      else if (State == State.DataLoaded)
                      {
                      // Initialize Swing indicators
                      primarySwing = Swing(PrimarySwingStrength);
                      secondarySwing = Swing(BarsArray[1], SecondarySwingStrength);

                      if (PlotPrimarySwing)
                      {
                      AddChartIndicator(primarySwing);
                      }

                      // Initialize MACD indicators with their respective parameters
                      primaryMACD = MACD(Closes[0], PrimaryMACDFast, PrimaryMACDSlow, PrimaryMACDSmooth);
                      secondaryMACD = MACD(Closes[1], SecondaryMACDFast, SecondaryMACDSlow, SecondaryMACDSmooth);
                      primaryMACDw = MACDwwma(Closes[0], PrimaryMACDFast, PrimaryMACDSlow, PrimaryMACDSmooth);
                      secondaryMACDw = MACDwwma(Closes[1], SecondaryMACDFast, SecondaryMACDSlow, SecondaryMACDSmooth);

                      if (PlotPrimaryMACD && MACDType)
                      {
                      AddChartIndicator(primaryMACDw);
                      }

                      else if(PlotPrimaryMACD)
                      AddChartIndicator(primaryMACD);


                      // Initialize Stochastic indicators with their respective parameters
                      primaryStochastics = Stochastics(PrimaryStochPeriod, PrimaryStochK, PrimaryStochD);
                      secondaryStochastics = Stochastics(BarsArray[1], SecondaryStochPeriod, SecondaryStochK, SecondaryStochD);

                      if (PlotPrimaryStochastics)
                      {
                      AddChartIndicator(primaryStochastics);
                      }

                      }
                      }

                      protected override void OnBarUpdate()
                      {
                      // Ensure we have enough bars to calculate
                      if (CurrentBars[0] < 1 || CurrentBars[1] < SecondarySeriesPeriod)
                      return;

                      if (BarsInProgress != 0)
                      return;


                      region Plot Values

                      // Update secondary MACD plots if enabled
                      if (PlotSecondaryMACD && MACDType)
                      {
                      Values[0][0] = secondaryMACDw.Default[0]; // SecondaryMACD plot
                      Values[1][0] = secondaryMACDw.Avg[0]; // SecondaryMACDAvg plot
                      Values[2][0] = secondaryMACDw.Diff[0]; // SecondaryMACDDiff plot
                      }

                      else if (PlotSecondaryMACD)
                      {
                      Values[0][0] = secondaryMACD.Default[0]; // SecondaryMACD plot
                      Values[1][0] = secondaryMACD.Avg[0]; // SecondaryMACDAvg plot
                      Values[2][0] = secondaryMACD.Diff[0]; // SecondaryMACDDiff plot
                      }

                      // Update secondary Stochastic plots if enabled
                      if (PlotSecondaryStochastics)
                      {
                      Values[3][0] = secondaryStochastics.K[0]; // SecondaryStochK plot
                      Values[4][0] = secondaryStochastics.D[0]; // SecondaryStochD plot
                      }

                      #endregion



                      region Place Trades


                      region Properties

                      // Secondary Series Property

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary Series Period", Description="Period for secondary bars series (Minutes or Days)", Order=2, GroupName="1- Series")]
                      public int SecondarySeriesPeriod { get; set; }

                      [NinjaScriptProperty]
                      [Range(0.001, 100)]
                      [Display(Name="Stop Loss Percent", Description="Percentage for stop loss (1 = 1%)", Order=3, GroupName="1- Series")]
                      public double StopLossPercent { get; set; }

                      [NinjaScriptProperty]
                      [Display(Name="MACDwwma", Description="Use MACDwwma in place of MACD", Order=0, GroupName="2 - MACD")]
                      public bool MACDType { get; set; }

                      // Primary MACD Properties
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary MACD Fast", Description="Fast period for Primary MACD", Order=1, GroupName="2 - MACD")]
                      public int PrimaryMACDFast { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary MACD Slow", Description="Slow period for Primary MACD", Order=2, GroupName="2 - MACD")]
                      public int PrimaryMACDSlow { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary MACD Smooth", Description="Smoothing period for Primary MACD", Order=3, GroupName="2 - MACD")]
                      public int PrimaryMACDSmooth { get; set; }

                      // Secondary MACD Properties
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary MACD Fast", Description="Fast period for Secondary MACD", Order=4, GroupName="2 - MACD")]
                      public int SecondaryMACDFast { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary MACD Slow", Description="Slow period for Secondary MACD", Order=5, GroupName="2 - MACD")]
                      public int SecondaryMACDSlow { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary MACD Smooth", Description="Smoothing period for Secondary MACD", Order=6, GroupName="2 - MACD")]
                      public int SecondaryMACDSmooth { get; set; }

                      [NinjaScriptProperty]
                      [Display(Name="Plot Primary MACD", Description="Show primary MACD plot", Order=7, GroupName="2 - MACD")]
                      public bool PlotPrimaryMACD { get; set; }

                      [NinjaScriptProperty]
                      [Display(Name="Plot Secondary MACD", Description="Show secondary MACD plot", Order=8, GroupName="2 - MACD")]
                      public bool PlotSecondaryMACD { get; set; }

                      // Primary Stochastic Properties
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary Stochastic Period", Description="Period for Primary Stochastic", Order=1, GroupName="3 - Stochastics")]
                      public int PrimaryStochPeriod { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary Stochastic %K", Description="%K period for Primary Stochastic", Order=2, GroupName="3 - Stochastics")]
                      public int PrimaryStochK { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary Stochastic %D", Description="%D period for Primary Stochastic", Order=3, GroupName="3 - Stochastics")]
                      public int PrimaryStochD { get; set; }

                      // Secondary Stochastic Properties
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary Stochastic Period", Description="Period for Secondary Stochastic", Order=4, GroupName="3 - Stochastics")]
                      public int SecondaryStochPeriod { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary Stochastic %K", Description="%K period for Secondary Stochastic", Order=5, GroupName="3 - Stochastics")]
                      public int SecondaryStochK { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary Stochastic %D", Description="%D period for Secondary Stochastic", Order=6, GroupName="3 - Stochastics")]
                      public int SecondaryStochD { get; set; }

                      [NinjaScriptProperty]
                      [Display(Name="Plot Primary Stochastic", Description="Show primary Stochastic plot", Order=7, GroupName="3 - Stochastics")]
                      public bool PlotPrimaryStochastics { get; set; }

                      [NinjaScriptProperty]
                      [Display(Name="Plot Secondary Stochastic", Description="Show secondary Stochastic plot", Order=8, GroupName="3 - Stochastics")]
                      public bool PlotSecondaryStochastics { get; set; }

                      // Swing Properties
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Primary Swing Strength", Description="Strength for Primary Swing identification", Order=1, GroupName="4 - Swing")]
                      public int PrimarySwingStrength { get; set; }

                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Secondary Swing Strength", Description="Strength for Secondary Swing identification", Order=2, GroupName="4 - Swing")]
                      public int SecondarySwingStrength { get; set; }

                      [NinjaScriptProperty]
                      [Display(Name="Plot Primary Swing", Description="Show primary Swing plot", Order=2, GroupName="4 - Swing")]
                      public bool PlotPrimarySwing { get; set; }

                      #endregion
                      }
                      }​

                      Comment


                        #12
                        Hello raysinred,

                        Thanks for your response.



                        First, when adding an indicator to your chart using the method AddChartIndicator(), it will pull the settings from the indicator itself.

                        You need to ensure that the Swing indicator has the IsOverlay property set to true. This property controls if the indicator plot will be drawn over the price panel.

                        Most likely it is set to false, resulting in being added to a new panel.


                        IsOverlay


                        Second, using the ChartIndicator collection, you can determine in which panel to plot.


                        ChartIndicators


                        Below we have other examples of how to use the IsOverlay and ChartIndicators as well as a sample code.






                        Feel free to reach back with any other questions or concerns.

                        Comment


                          #13
                          Hi Helom,

                          I looked at the Swing indicator, and the Overlay is already set to true. Also, I tried using ChartIndicators[0].Panel = 1 for the Swing indicator, but still no luck in getting the Swing indicator to plot on the main panel. It plots its on its own panel or a panel used by one of the AddPlots. Not sure what the issue is.

                          Does the ChartIndicators[0].Panel = ? work for AddPlots as well?

                          Thanks,
                          Ray

                          Comment


                            #14
                            Hello raysinred

                            Thanks for your message.



                            It seems that the panel indexes start at 0 and not 1. When using the ChartIndicator[0].Panel property, ensure to set that value to 0.

                            ChartIndicators[0].Panel = 0.

                            This will ensure that the first added indicator, Swing, will plot on the main price panel.

                            ChartIndicator.

                            Feel free to reach out with any other questions or concerns.

                            Comment


                              #15
                              Hi Helom,

                              So I tried using the following:

                              AddChartIndicator(primarySwing);
                              ChartIndicators[0].Panel = 0;​

                              Still no luck. Plots the Swing on another panel. I also tried adding a couple EMAs using the EMA indicator and AddChartIndicator(), and they also will not show up on the main price panel. Not sure what is going on. Obviously something with my code.

                              Thank you,
                              Ray
                              Last edited by raysinred; 04-16-2025, 07:13 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              50 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              126 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              69 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              46 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X