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 sjsj2732, 03-23-2026, 04:31 AM
                0 responses
                42 views
                0 likes
                Last Post sjsj2732  
                Started by NullPointStrategies, 03-13-2026, 05:17 AM
                0 responses
                294 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                290 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                135 views
                1 like
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                98 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Working...
                X