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 helpwanted, Today, 03:06 AM
      1 response
      10 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      9 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      387 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X