Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

General Question about CrossAbove

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

    General Question about CrossAbove

    Hi!

    I am new to this and I am trying to understand how the indicators work in code.

    If I have a chart open, with an EMA (Close, 13) and an SMA(Close 20), I am trying to programatically determine with they cross with my own indicator (so I have a total of three indicators on the chart.) This is the code I wrote in my custom indicator which does not seem to work:

    if (CrossAbove(EMA(Close, 13), SMA(Close, 20), 1))
    {
    DrawArrowUp(
    "UpArrow", 0, High[0] + TickSize, Color.LimeGreen);
    }

    So when your indicators cross, my code does not seem to place the arrow anywhere close to where your indicators show the crossover. Which of these arguments do I have wrong and do not understand?

    Thanks so much!
    Michael

    #2
    Hi Michael,

    Your code will only ever plot 1 arrow and move the arrow on each new occurence of a cross. If you want individual arrows for each cross, change your tag to "UpArrow" + CurrentBar.ToString().

    Please try this change and see if it makes a difference.
    RayNinjaTrader Customer Service

    Comment


      #3
      Example Screenshot

      Hi! Thanks for writing back.

      I understand the need for a unique tag; that was not my problem. (I was actually appending a serialized date time to each tag which is obviously overkill compared to your superior example - ha!)

      Anyway, this is the new code:

      if (CrossAbove(EMA(Close, 13), SMA(Close, 20), 1))
      {
      DrawArrowUp(
      "UpArrow" + CurrentBar.ToString(), 0, High[0] + TickSize, Color.LimeGreen);
      }

      I have attached a screenshot of what I am trying to do. I want to catch these crossovers [note: I have not yet written the CrossBelow code; I am trying to get it to work in the one direction.)

      Thanks again!
      Attached Files

      Comment


        #4
        The SMA on the chart has 10 period. Your code has 20 period. That is the source of the discrepancy.
        RayNinjaTrader Customer Service

        Comment


          #5
          As they say...

          So the problem was between the keyboard and the chair.

          Thanks! This drove me nuts.

          Comment

          Latest Posts

          Collapse

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