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

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 cre8able, 02-11-2023, 05:43 PM
                3 responses
                231 views
                0 likes
                Last Post rhubear
                by rhubear
                 
                Started by frslvr, 04-11-2024, 07:26 AM
                8 responses
                111 views
                1 like
                Last Post NinjaTrader_BrandonH  
                Started by stafe, 04-15-2024, 08:34 PM
                10 responses
                44 views
                0 likes
                Last Post stafe
                by stafe
                 
                Started by rocketman7, Today, 09:41 AM
                3 responses
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by traderqz, Today, 09:44 AM
                2 responses
                5 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Working...
                X