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

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 aligator, 01-06-2022, 12:14 PM
          4 responses
          233 views
          0 likes
          Last Post john_44573  
          Started by reynoldsn, Today, 05:56 PM
          0 responses
          4 views
          0 likes
          Last Post reynoldsn  
          Started by bortz, 11-06-2023, 08:04 AM
          51 responses
          1,989 views
          0 likes
          Last Post aligator  
          Started by dmking, 11-12-2019, 12:31 PM
          4 responses
          4,150 views
          0 likes
          Last Post jasonw
          by jasonw
           
          Started by roblogic, Today, 04:31 PM
          0 responses
          10 views
          0 likes
          Last Post roblogic  
          Working...
          X