Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How do I set this Condition?

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

    How do I set this Condition?

    Hi,

    I want a condition that states "when the EMA goes down for a minimum of 2 bars, Ignoring flat EMA bars"

    Can you please help me with this condition?


    Thank you,

    Michael Hale

    #2
    Hello,

    Try something like this:

    if(EMA(14)[0] < EMA(14)[1] && EMA(14)[1] < EMA(14)[2])
    {
    //some code here
    }
    DenNinjaTrader Customer Service

    Comment


      #3
      Hi Ben,

      Thanks for that reply, I have got that far but I'm struggling to work out how to ignore the flat EMA's in between the down candles?


      I look forward to you comments,
      Thanks,

      Michael Hale

      Comment


        #4
        Michael, you would need to define what 'flat means', it very rarely would be fully flat, so you need to define an acceptable range of flat values, most likely some momentum running on the EMA. Then use it's absolute value and set up a condition to not take trades when it smaller than your treshhold level....
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by Michael1111 View Post
          Hi,

          I want a condition that states "when the EMA goes down for a minimum of 2 bars, Ignoring flat EMA bars"

          Can you please help me with this condition?


          Thank you,

          Michael Hale
          Further to the above question I would like to define that a:
          • "Down Bar" is 1 pip (or more) of movement lower than the previous bar and a
          • "Flat Bar" - is less than 1 pip of movement higher or lower than the previous bar.
          How would I go about defining these?


          Thanks again,

          Michael Hale

          Comment


            #6
            Or in other words I am really just wanting to have 1pip as the minimum movement the script will recognize and not the usual Tenth of a Pip?

            Comment


              #7
              Depending on which connection you are, you would need to 'play around' with the Math.Round method and then round to the amount of decimals you want / need to, if you're on a tenthPip connection just round the Close for example to 4 digits and then use this value in further calcs.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Hi Bertrand,

                Thanks for your reply.
                I have now worked out what the best approach for me is:

                I'm trying to do this formula "if(EMA(5)[0] < EMA(5)[1] && EMA(5)[1] < EMA(5)[2])" but I also want all the EMA figures to be rounded using this formula first "Instrument.MasterInstrument.Round2TickSize(do uble price)"

                I'm new to this and just wondering how I go about scripting the rounding formula first so that all the EMA values are rounded before the "if formula is used?

                An example would be appreciated

                Many Thanks,

                Michael Hale

                Comment


                  #9
                  Hi Michael, for example you can work with this snippet here for the OnBarUpdate() -

                  Code:
                   
                  mySeries.Set(Instrument.MasterInstrument.Round2TickSize(Close[0])); 
                  Plot0.Set(EMA(mySeries, 20)[0]);
                  Of course it assumes a dataseries mySeries being declared and initialized properly, in variables -

                  Code:
                   
                  private DataSeries mySeries;
                  In the Initialize() method -

                  Code:
                   
                  mySeries = new DataSeries(this);
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Bertrand,

                    I have tried to do what you showed to the best of my understanding, but I am getting errors come up (I presume I'm just doing some basic newbie mistakes). Below is a copy of my script so far, Can you help me correct where I'm going wrong. Thanks

                    /// <summary>
                    /// Enter the description of your strategy here
                    /// </summary>
                    [Description("Enter the description of your strategy here")]
                    public class Test4 : Strategy
                    {
                    #region Variables
                    // Wizard generated variables
                    private int myInput0 = 1; // Default setting for MyInput0
                    // 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 = true;
                    mySeries = new DataSeries(this);
                    }

                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                    mySeries.Set(Instrument.MasterInstrument.Round2Tic kSize(Close[0]));
                    Plot0.Set(EMA(mySeries, 20)[0]);

                    Variable1 == Private DataSeries mySeries;
                    (EMA(5)[0] < EMA(5)[1];
                    {
                    DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
                    }
                    }

                    #region Properties
                    [Description("")]
                    [Category("Parameters")]
                    public int MyInput0
                    {
                    get { return myInput0; }
                    set { myInput0 = Math.Max(1, value); }
                    }
                    #endregion
                    }
                    }

                    Comment


                      #11
                      Originally posted by Michael1111 View Post
                      Thanks Bertrand,

                      I have tried to do what you showed to the best of my understanding, but I am getting errors come up (I presume I'm just doing some basic newbie mistakes). Below is a copy of my script so far, Can you help me correct where I'm going wrong. Thanks

                      /// <summary>
                      /// Enter the description of your strategy here
                      /// </summary>
                      [Description("Enter the description of your strategy here")]
                      public class Test4 : Strategy
                      {
                      #region Variables
                      // Wizard generated variables
                      private int myInput0 = 1; // Default setting for MyInput0
                      // 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 = true;
                      mySeries = new DataSeries(this);
                      }

                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      mySeries.Set(Instrument.MasterInstrument.Round2Tic kSize(Close[0]));
                      Plot0.Set(EMA(mySeries, 20)[0]);

                      Variable1 == Private DataSeries mySeries;
                      (EMA(5)[0] < EMA(5)[1];
                      {
                      DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
                      }
                      }

                      #region Properties
                      [Description("")]
                      [Category("Parameters")]
                      public int MyInput0
                      {
                      get { return myInput0; }
                      set { myInput0 = Math.Max(1, value); }
                      }
                      #endregion
                      }
                      }
                      Yes, there are some twists in there, corrected them in the attached zip.
                      Attached Files
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Thank you Bertrand for doing that script for me . I will be spending a bit of time going through the script to get my head around it all.

                        Thanks again,

                        Michael Hale

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by stafe, 04-15-2024, 08:34 PM
                        7 responses
                        31 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by adeelshahzad, Today, 03:54 AM
                        4 responses
                        30 views
                        0 likes
                        Last Post adeelshahzad  
                        Started by merzo, 06-25-2023, 02:19 AM
                        10 responses
                        823 views
                        1 like
                        Last Post NinjaTrader_ChristopherJ  
                        Started by frankthearm, Today, 09:08 AM
                        5 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        43 views
                        0 likes
                        Last Post jeronymite  
                        Working...
                        X