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 Hwop38, 05-04-2026, 07:02 PM
          0 responses
          169 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          327 views
          0 likes
          Last Post CaptainJack  
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          252 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          353 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          180 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Working...
          X