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
          HI, My calculation of distance between high of signal bar and slow ema 34(gold line) is not correct. In settings I placed 1 tick but it opens with distance of a lot more then just one tick. See Pic. Can you provide me with a suggestion on how to fix it? AboveBelowForType2 = 1; else if (TradeType2 && emaAngulation

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,602 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          8 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          4 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          12 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X