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

Reference to indicator crossover barsAgo

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

    Reference to indicator crossover barsAgo

    Hi, I want to find the value of indicator crossover exactly 2 bars ago, look back period won't work since it counts current bar up to the look back period.

    I know indicators can be reference like SMA(20)[2] to find the value 2 bars ago. But I have problem applying it to indicator crossovers.

    I tried:
    if (CrossAbove(T3(1, 2)[2].Plot1, T3(1, 4)[2].Plot1, 1))
    if (CrossAbove(T3(1, 2).Plot1[2], T3(1, 4).Plot1[2], 1))
    if (CrossAbove(T3(1, 2).Plot1, T3(1, 4).Plot1, 1)[2])

    All returned with syntax error, what's the method to program it?

    Thanks in advance.

    #2
    Not sure I follow, CrossAbove() returns either true or false. It does not return a value.
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by Novicetrader View Post
      I tried:
      if (CrossAbove(T3(1, 2)[2].Plot1, T3(1, 4)[2].Plot1, 1))
      if (CrossAbove(T3(1, 2).Plot1[2], T3(1, 4).Plot1[2], 1))
      if (CrossAbove(T3(1, 2).Plot1, T3(1, 4).Plot1, 1)[2])
      While it may not accomplish what you want, the syntax error is due to the forced index (ie [x], [1], [2] etc) which cannot be used in CrossAbove/Below.

      CrossAbove(T3(1, 2).Plot1, T3(1, 4).Plot1, 1))

      would be the correct way to re-write your first example. It says if T3(1, 2).Plot1 crosses above T3(1, 4).Plot1 within the last 1 bar, then 'true' otherwise false. If you want it to be within 4 bars change the very last number from 1 to 4, for instance.

      If you want to find out if it crossed within 10 bars, but want to exclude anything that crosses within the last 2 bars, this would do it:

      CrossAbove(T3(1, 2).Plot1, T3(1, 4).Plot1, 10))
      && !CrossAbove(T3(1, 2).Plot1, T3(1, 4).Plot1, 2))

      first line says everything in 10 bars, second line says except within 2 bars.

      HTH

      Mike

      Comment


        #4
        Oh and this may help as well:

        if T3(1, 2).Plot1[3] < T3(1, 4).Plot1[4] // 3 bars ago was less than 4 bars ago
        && T3(1, 2).Plot1[2] > T3(1, 4).Plot1[3] // 2 bar ago was more than 3 bars ago

        Comment


          #5
          Thanks ctrlbrk, excluding recent 2 bars will serve my purpose. Got to love this forum, I learn something new everyday.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by f.saeidi, Today, 01:32 PM
          1 response
          2 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by mmckinnm, Today, 01:34 PM
          0 responses
          3 views
          0 likes
          Last Post mmckinnm  
          Started by traderqz, Today, 12:06 AM
          9 responses
          16 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by kevinenergy, 02-17-2023, 12:42 PM
          117 responses
          2,766 views
          1 like
          Last Post jculp
          by jculp
           
          Started by Mongo, Today, 11:05 AM
          5 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X