Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          576 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          334 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
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X