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

Two MAs coming close within 3 ticks

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

    Two MAs coming close within 3 ticks

    Hi. I have what I think/hope is a small coding question.

    What do I have to do to when I want something to happen when two MAs come close to each other, like for example within 3 ticks of each other?

    I am familiar with when two MAs meet:
    EMA(13)[0] == EMA(20)[0]

    and when one is less than or equal to:
    EMA(13)[0] <= EMA(20)[0])

    I tried using offset but could not make it work.

    Can I use one of these to get what I want e.g. are the same within lets say 3 ticks, or is less than 3 ticks or equal to?

    sandman

    #2
    Hello Sandman,

    You already have half of the statement, the second condition it would need to meet would be a tick size difference

    here is an example of using Ticks


    This would check if EMA(13)[0] is less than EMA(20)[0] and also checks if EMA(13) is greater than EMA(20)[0] - 3 ticks

    I used a && sign to tell the if statement that there is a second condition to be met so it gives it a range to check within.

    Code:
    if (EMA(13)[0] <= EMA(20)[0] && EMA(13)[0] >= EMA(20)[0] - (3 * TickSize))
    I hope that helps with your indicator, please let me know if you need additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by sandman View Post
      Hi. I have what I think/hope is a small coding question.

      What do I have to do to when I want something to happen when two MAs come close to each other, like for example within 3 ticks of each other?

      I am familiar with when two MAs meet:
      EMA(13)[0] == EMA(20)[0]

      and when one is less than or equal to:
      EMA(13)[0] <= EMA(20)[0])

      I tried using offset but could not make it work.

      Can I use one of these to get what I want e.g. are the same within lets say 3 ticks, or is less than 3 ticks or equal to?

      sandman
      You might try:

      If (math.ABS((EMA (13)[0] - EMA (20)[0]) / TickSize) <= 3 )
      {
      Do your stuff here
      }

      The math.abs gives you the absolute value of the difference between the two EMAs so that you don't have to worry about positive or negative conditions while /TickSize converts the difference to ticks regardless of instrument. Then you compare to the 3 or whatever ticks you want.

      Hope that helps.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by WHICKED, Today, 12:56 PM
      2 responses
      14 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Started by Felix Reichert, Today, 02:12 PM
      0 responses
      1 view
      0 likes
      Last Post Felix Reichert  
      Started by Tim-c, Today, 02:10 PM
      0 responses
      1 view
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by cre8able, Today, 01:16 PM
      2 responses
      9 views
      0 likes
      Last Post cre8able  
      Started by chbruno, 04-24-2024, 04:10 PM
      3 responses
      49 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X