Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Compilation Error

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

    Compilation Error

    Tried to modify "SampleMultiTimeFrame" example by adding DM condition:

    there is compliation error which is not clear.


    [Description("This is a sample multi-time frame strategy.")]
    public class MultiTimeFrameADX : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int fast = 5; // Default setting for Fast
    private int slow = 21; // Default setting for Slow
    private int ADXPeriod = 18;
    // 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()
    {
    // Add a 5 minute Bars object to the strategy
    Add(PeriodType.Minute, 5);

    // Add a 15 minute Bars object to the strategy
    Add(PeriodType.Minute, 15);

    // Note: Bars are added to the BarsArray and can be accessed via an index value
    // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above

    // Add simple moving averages to the chart for display
    // This only displays the SMA's for the primary Bars object on the chart
    Add(SMA(Fast));
    Add(SMA(Slow));
    Add(DM(DmiPeriods));
    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
    // We only want to process events on our primary Bars object (index = 0) which is set when adding
    // the strategy to a chart
    if (BarsInProgress != 0)
    return;

    // Checks if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
    if (SMA(BarsArray[1], Fast)[0] > SMA(BarsArray[1], Slow)[0] && SMA(BarsArray[2], Fast)[0] > SMA(BarsArray[2], Slow)[0])
    {
    // Checks for a cross above condition of the 5 and 50 period SMA on the primary Bars object and enters long

    if (CrossAbove(SMA(Fast), SMA(Slow), 1)
    && (CrossAbove(DM(DmiPeriods).DiPlus, DM(DmiPeriods).DiMinus, 1))
    )
    EnterLong(10, "SMA");
    }

    // Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
    if (CrossBelow(SMA(BarsArray[2], Fast), SMA(BarsArray[2], Slow), 1))
    ExitLong(10);
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int Fast
    {
    get { return fast; }
    set { fast = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int Slow
    {
    get { return slow; }
    set { slow = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #2
    Hello,

    Can you please upload the file instead as an attachment so that I do not have to copy and paste this in as it doesnt look you copyied everything up and is giving my some issues.

    My Documents->NinjaTrader 7->bin->custom->strategy->strategyname.cs

    Thank You.

    Comment


      #3
      Thx. attached
      Attached Files

      Comment


        #4
        Sam, it appears you never defined DmiPeriods, so the compiler takes offense here at that point.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          In my copy, I see it defined. The issue to my knowledge, when I try to reference DM ADX or DI.Plus , I am not sure how to reference it in multi time frame! SMA....would be SMA(xx, Fast)... what about DM.DiPlus... how to reference in array one or array two?

          thx.

          Comment


            #6
            Hello,

            I had to add this to your code in the variables section:

            privateint DmiPeriods = 4;


            Then for your second question you would do the same as you would for SMA.

            DM(BarsArray[1], DmiPeriods).DiPlus

            Let me know if I can be of further assistance.

            Comment


              #7
              I updated the script...however, dmiperiods is not showing as a variable to optimize when I optimize the strategy. Thanks. attached
              Attached Files

              Comment


                #8
                Hello,

                Yes this is because you need to set it as a parameter instead of just a local variable.

                If you check out the Parameters section in the code you will see how this is done for the other variables. You will want to do this with DmiPeriods as well.

                Let me know if I can be of further assistance.

                Comment


                  #9
                  Here is how defined:
                  #region Variables
                  // Wizard generated variables
                  private int fast = 5; // Default setting for Fast
                  private int slow = 21; // Default setting for Slow
                  private int DmiPeriods = 4;
                  // User defined variables (add any user defined variables below)
                  #endregion

                  protected override void Initialize()

                  Add(SMA(Fast));
                  Add(SMA(Slow));
                  Add(DM(DmiPeriods));
                  CalculateOnBarClose = true;



                  I do not see the problem. how do I fix it?

                  Comment


                    #10
                    Hello,

                    You have to go down under OnBarUpdate() there is a parameters section there to expand out. You will need to create a parameter that will look exactly the same as the other ones. Except for the DmiPeriod variable.

                    Let me know if I can be of further assistance.

                    Comment


                      #11
                      You would use this in your case.

                      [Description("")]
                      [GridCategory("Parameters")]
                      public int DmiPeriods
                      {
                      get { return dmiPeriods; }
                      set { fast = Math.Max(1, value); }
                      }



                      Also, change under variable the variable name from DmiPeriods to dmiPeriods.

                      Comment


                        #12
                        Here is a screen print of what I see under onbarupdate... there is no definition of fast or slow there to copy it to dmiperiods.

                        If you are reading and new to ninjatrader like me....do not be discouraged if it takes days to find an answer, you will get it eventually and start trading one day.
                        Attached Files

                        Comment


                          #13
                          Hello,

                          Click on the plus icon on the very left hand side of the chart to expand out where it says Properties in this screenshot.

                          I look forward to assisting you further.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Jon17, Today, 04:33 PM
                          0 responses
                          1 view
                          0 likes
                          Last Post Jon17
                          by Jon17
                           
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post Javierw.ok  
                          Started by timmbbo, Today, 08:59 AM
                          2 responses
                          10 views
                          0 likes
                          Last Post bltdavid  
                          Started by alifarahani, Today, 09:40 AM
                          6 responses
                          41 views
                          0 likes
                          Last Post alifarahani  
                          Started by Waxavi, Today, 02:10 AM
                          1 response
                          21 views
                          0 likes
                          Last Post NinjaTrader_LuisH  
                          Working...
                          X