Announcement

Collapse
No announcement yet.

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.

    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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      560 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      325 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X