Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price at Cross Above / Cross Below

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

    Price at Cross Above / Cross Below

    I'm using the CrossAbove and CrossBelow indicators on range charts which update on every tick., e.g.,
    if (CrossAbove(EMA(10), EMA(20), 1))
    {
    do something
    }

    Is there a way that I can capture the instrument price at the time the actual crossover occurs?

    #2
    Hello sgordet,

    Yes, you can capture a value in a variable at the time of a crossover.

    if (CrossAbove(EMA(10), EMA(20), 1))
    {
    double myDouble = Close[0];
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello sgordet,

      Yes, you can capture a value in a variable at the time of a crossover.

      if (CrossAbove(EMA(10), EMA(20), 1))
      {
      double myDouble = Close[0];
      }
      If one is updating intrabar, does Close[0] wait until the first tick of the next bar to update or do you get the price of the current tick when the crossover occurs?

      Comment


        #4
        With CalculateOnBarClose = false and real time: You get the value of current tick, when crossover occurs.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I'm sorry to trouble you again, it didn't occur to me at the time to ask: I just noticed that the cross often occurs outside of the price bar. Can I also get the price point at the intersection of the two moving averages involved in the crossover when I plot them overlaying the price chart?

          Comment


            #6
            Yes, you can use the same principles to capture an indicator value.

            if (CrossAbove(EMA(10), EMA(20), 1))
            {
            double myDouble1 = EMA(10)[0];
            double myDouble2 = EMA(20)[0];
            }
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I got an error message when I tried this
              double crossValue = 0;
              if (CrossAbove(EMA(10), EMA(20), 1))
              {
              crossValue = EMA[
              10][0];
              Print(
              "crossValue" + crossValue.ToString());
              }
              Error: Cannot apply indexing with [] to an expression of type 'method group' CS0021
              What have I missed?
              Thanks.
              Last edited by sgordet; 01-11-2011, 03:38 PM.

              Comment


                #8
                Your EMA code is formatted incorrectly. It should be:

                crossValue = EMA(10)[0];
                Ryan M.NinjaTrader Customer Service

                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
                550 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X