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

Logic for distance between major emas greater then in ticks

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

    Logic for distance between major emas greater then in ticks

    Hi in my strategy settings i have
    DistanceBEMAs = 20;

    and in logic I want to specify to open order only if distance between EMAs are greater in ticks . Is this the correct logic?

    slowEMA[0] > EMA600[0] + DistanceBEMAs * TickSize)

    #2
    Hello, thanks for writing in. The best way to verify your code is to use Print so you can see the data that your strategy is producing e.g.

    Code:
    if(slowEMA[0] > EMA600[0] + DistanceBEMAs * TickSize)
    {
       Print("EMA condition true " + Time[0] + " " + slowEMA[0] + " " + EMA600[0] + DistanceBEMAs * TickSize);
       //submit order
    }
    .
    This way you can see exactly the condition you have set up and make adjustments if necessary.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by tkaboris View Post
      Hi in my strategy settings i have
      DistanceBEMAs = 20;

      and in logic I want to specify to open order only if distance between EMAs are greater in ticks . Is this the correct logic?

      slowEMA[0] > EMA600[0] + DistanceBEMAs * TickSize)
      Probably not.

      You should always take into account that the either of the EMAs
      could be higher or lower than the other.

      Try this,

      Add this code as a new Class variable:
      Code:
      // calculate constant value
      private double EmaDistance;
      Add this code inside State.Configure:
      Code:
      // one time calculation
      EmaDistance = DistanceBEMAs * TickSize;
      Add this code inside OnBarUpdate:
      Code:
      double EmaDiff = Math.Abs(slowEMA[0] - EMA600[0]);
      if (EmaDiff > EmaDistance)
          Print("Distance is good");
      else
          Print("Distance is no good");
      ​Make sense?

      Last edited by bltdavid; 02-01-2023, 11:04 PM.

      Comment


        #4
        Hi, Will I need to create a double for opposite to calculate for longs/shorts?
        double EmaDiff = Math.Abs(EMA600[0] - slowEMA[0]);

        Comment


          #5
          Can you please also loot at other similar challenge i have with calculating difference between EMA and Low/High
          https://ninjatrader.com/support/foru...a-bar-is-wrong

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alanlopen, 03-21-2023, 07:37 AM
          6 responses
          22 views
          0 likes
          Last Post bltdavid  
          Started by JTizz, Today, 10:10 AM
          0 responses
          4 views
          0 likes
          Last Post JTizz
          by JTizz
           
          Started by qewcool, 03-19-2023, 05:51 PM
          31 responses
          344 views
          1 like
          Last Post anon84
          by anon84
           
          Started by BartMan, Today, 09:24 AM
          0 responses
          8 views
          0 likes
          Last Post BartMan
          by BartMan
           
          Started by Lucius. valerius, 03-23-2023, 01:39 AM
          7 responses
          170 views
          0 likes
          Last Post NinjaTrader_Ray  
          Working...
          X