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 helpwanted, Today, 03:06 AM
          1 response
          12 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          9 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          5 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          387 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X