Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to reference PriceType

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

    How to reference PriceType

    Hi,
    I declared a PriceType variable in a strategy and now I can choose (close, high, low,...)
    private PriceType PrType = PriceType.Close;
    How do I reference it in a SMA?
    Like in: Add(SMA(????,Period));
    and: SMA(????,Period)[0];

    Regards,
    Baruch

    #2
    Hello,

    I think this is what you are after:

    SMA(Input,Period) ... etc.
    This link my help:
    DenNinjaTrader Customer Service

    Comment


      #3
      Ben,
      Thanks for a quick replay, but I still don't understand. Something is missing.
      Let me expand the question a bit.
      I have two SMA's (fast and slow).
      The Parameters section has 4 parameters:
      Fast_Period = 10
      Fast_PrType = High //Gives a list box to choose
      Slow_Period = 30
      Slow_PrType = Low //Gives a list box to choose

      Now how do I add the two MA's and get their values?
      Add (SMA(?????,Fast_Period); // Should be High
      Add (SMA(?????,Slow_Period); // Should be Low

      So the INPUT for Fast should be HIGH and for Slow should be LOW.

      Baruch

      Comment


        #4
        You would need custom inputs for both and then reference them in your call - http://www.ninjatrader-support2.com/...ead.php?t=5782

        Comment


          #5
          Bertrand,
          I know that and I have them:
          private PriceType PrTypeFast = PriceType.High;
          private PriceType PrTypeSlow = PriceType.Low;
          And of course I have the necessary definitions in Properties.
          But if I call SMA(PrTypeFast, PeriodFast)[0];
          I get an error: Argument '1': cannot convert from 'NinjaTrader.DataPriceType' to 'NinjaTrader.DataSeries'.

          So please if you can answer how to do it in more than one sentence, with all the peaces of the puzzle, I will be very grateful.

          Baruch

          Comment


            #6
            Baruch, sorry was too quick in my previous reply - for this you would need to create custom enums as in this example to make available more than one input setting (PriceTypeSupported setting) - http://www.ninjatrader-support2.com/...ead.php?t=3420

            Comment


              #7
              Bertrand,
              NT already has PriceType as an enum and I can choose a wanted type.
              My problem is that :
              1. Add(SMA(????)) - doesn't have two parameters, only period and I need also price type.
              2. SMA(??????,period) - what do I enter instead of the question marks. You saw the error I got.
              I tried to define two dataseries (fast & slow), and set the appropriate values to them depending on the enum and calling SMA (MyDataSeriesFast, period); This doesn't create an error but it does nothing, I still get the same result like in SMA(Close, period) even if I choose PriceType.High.

              Baruch

              Comment


                #8
                Correct Baruch, you would need to use a switch statement as in the sample to assign the relevant indicator calls for your different input series.

                Comment


                  #9
                  Bertrand,
                  You are not answering my questions.
                  I just created a variant of samplemasrossover.
                  What wrong with it. As I asked Add(SMA(period)); doesn't accept price type parameter so in back testing by looking on a chart it says SMA(Close,10) and SMA(Close,25). How to make it something else like SMA(High,10)?

                  #region Using declarations
                  using System;
                  using System.ComponentModel;
                  using System.Diagnostics;
                  using System.Drawing;
                  using System.Drawing.Drawing2D;
                  using System.Xml.Serialization;
                  using NinjaTrader.Cbi;
                  using NinjaTrader.Data;
                  using NinjaTrader.Indicator;
                  using NinjaTrader.Strategy;
                  #endregion
                  // This namespace holds all strategies and is required. Do not change it.
                  namespace NinjaTrader.Strategy
                  {
                  /// <summary>
                  /// Simple moving average cross over strategy.
                  /// </summary>
                  [Description("Simple moving average cross over strategy.")]
                  public class MACrossOver : Strategy
                  {
                  #region Variables
                  private int fast = 10;
                  private PriceType PrTypeFast = PriceType.Close;
                  private int slow = 25;
                  private PriceType PrTypeSlow = PriceType.Close;
                  private DataSeries MyDSFast;
                  private DataSeries MyDSSLow;
                  #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()
                  {
                  SMA(fast).Plots[0].Pen.Color = Color.Orange;
                  SMA(slow).Plots[0].Pen.Color = Color.Green;
                  Add(SMA(fast));
                  Add(SMA(slow));
                  MyDSFast = new DataSeries(this);
                  MyDSSLow = new DataSeries(this);

                  CalculateOnBarClose = true;
                  }
                  /// <summary>
                  /// Called on each bar update event (incoming tick).
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  switch (PrTypeFast)
                  {
                  case (PriceType.Close):
                  MyDSFast.Set(Close[0]);
                  break;
                  case (PriceType.High):
                  MyDSFast.Set(High[0]);
                  break;
                  case (PriceType.Low):
                  MyDSFast.Set(Low[0]);
                  break;
                  case (PriceType.Median):
                  MyDSFast.Set((High[0] + Low[0]) / 2);
                  break;
                  case (PriceType.Open):
                  MyDSFast.Set(Open[0]);
                  break;
                  case (PriceType.Typical):
                  MyDSFast.Set((High[0] + Low[0] + Close[0]) / 3);
                  break;
                  }
                  switch (PrTypeSlow)
                  {
                  case (PriceType.Close):
                  MyDSSLow.Set(Close[0]);
                  break;
                  case (PriceType.High):
                  MyDSSLow.Set(High[0]);
                  break;
                  case (PriceType.Low):
                  MyDSSLow.Set(Low[0]);
                  break;
                  case (PriceType.Median):
                  MyDSSLow.Set((High[0] + Low[0]) / 2);
                  break;
                  case (PriceType.Open):
                  MyDSSLow.Set(Open[0]);
                  break;
                  case (PriceType.Typical):
                  MyDSSLow.Set((High[0] + Low[0] + Close[0]) / 3);
                  break;
                  }
                  if (CrossAbove(SMA(MyDSFast, fast), SMA(MyDSSLow, slow), 1))
                  EnterLong();
                  else if (CrossBelow(SMA(MyDSFast, fast), SMA(MyDSSLow, slow), 1))
                  EnterShort();
                  }
                  #region Properties
                  /// <summary>
                  /// </summary>
                  [Description("Period for fast MA")]
                  [Category("Parameters")]
                  public int p1_Fast
                  {
                  get { return fast; }
                  set { fast = Math.Max(1, value); }
                  }
                  [Description("")]
                  [Category("Parameters")]
                  public PriceType p2_PrTypeFast
                  {
                  get { return PrTypeFast; }
                  set { PrTypeFast = value; }
                  }
                  /// <summary>
                  /// </summary>
                  [Description("Period for slow MA")]
                  [Category("Parameters")]
                  public int p3_Slow
                  {
                  get { return slow; }
                  set { slow = Math.Max(1, value); }
                  }
                  [Description("")]
                  [Category("Parameters")]
                  public PriceType p4_PrTypeSlow
                  {
                  get { return PrTypeSlow; }
                  set { PrTypeSlow = value; }
                  }
                  #endregion
                  }
                  }

                  Comment


                    #10
                    Baruch, ok I see so the strategy is actually calculating with the correct values? For the indicators added for display you can't change this dynamically in the Initialize() unfortuantely. You can take a look at the StrategyPlot sample for this then - http://www.ninjatrader-support2.com/...ead.php?t=6651

                    Comment


                      #11
                      Bertrand,
                      No it's not!
                      I made a new customization to samplemacrossover. I only changed SMA(fast) to SMA(High, fast) and then after back testing I added new indicator to a chart SMA(Close, 10) (fast=10). Both plots give same results, so in strategy it ignores the price type!!!
                      Please fix it.

                      #region Using declarations
                      using System;
                      using System.ComponentModel;
                      using System.Diagnostics;
                      using System.Drawing;
                      using System.Drawing.Drawing2D;
                      using System.Xml.Serialization;
                      using NinjaTrader.Cbi;
                      using NinjaTrader.Data;
                      using NinjaTrader.Indicator;
                      using NinjaTrader.Strategy;
                      #endregion
                      // This namespace holds all strategies and is required. Do not change it.
                      namespace NinjaTrader.Strategy
                      {
                      /// <summary>
                      /// Simple moving average cross over strategy.
                      /// </summary>
                      [Description("Simple moving average cross over strategy.")]
                      public class MACrossOver2 : Strategy
                      {
                      #region Variables
                      private int fast = 10;
                      private int slow = 25;
                      #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()
                      {
                      SMA(10).Plots[0].Pen.Color = Color.Orange;
                      SMA(Slow).Plots[0].Pen.Color = Color.Green;
                      Add(SMA(Fast));
                      Add(SMA(Slow));
                      CalculateOnBarClose = true;
                      }
                      /// <summary>
                      /// Called on each bar update event (incoming tick).
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      if (CrossAbove(SMA(High, Fast), SMA(High, Slow), 1))
                      EnterLong();
                      else if (CrossBelow(SMA(High, Fast), SMA(High, Slow), 1))
                      EnterShort();
                      }
                      #region Properties
                      /// <summary>
                      /// </summary>
                      [Description("Period for fast MA")]
                      [Category("Parameters")]
                      public int Fast
                      {
                      get { return fast; }
                      set { fast = Math.Max(1, value); }
                      }
                      /// <summary>
                      /// </summary>
                      [Description("Period for slow MA")]
                      [Category("Parameters")]
                      public int Slow
                      {
                      get { return slow; }
                      set { slow = Math.Max(1, value); }
                      }
                      #endregion
                      }
                      }

                      Comment


                        #12
                        Baruch, see here for a description of the Input array:

                        Comment


                          #13
                          Baruch, please post a zip export of the latest strategy you're now using, then I'll test this on my end - thanks.

                          Comment


                            #14
                            Its not the strategy I'm trading. Its just samplemacrossover with a small change.

                            Baruch
                            Attached Files

                            Comment


                              #15
                              Baruch,

                              In your zip you have no reference to any of the PriceType things you are trying to do. Please export one with the code you are using. Thank you.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              639 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              366 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              572 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X