Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CrossAbove & CrossBelow Interpretation

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

    CrossAbove & CrossBelow Interpretation

    Hello Support,

    I am trying to code the following condition:

    Check if the Close has crossed above & closed above the EMA(10) in the past 20 bars

    Which means, that a previous bar's close is less than the EMA and the current bar's close is above the EMA. So in essence, the CLOSE has crossed above the EMA and CLOSED above it,

    I am coding it as follows:

    Code:
    if(CrossAbove(Closes[1], EMA(BarsArray[1], 10), 20))
    {
        //Do work
    }
    The issue here is that this condition returns true when the price crosses above the EMA and doesnt wait for it to CLOSE above the EMA. From what i understand, it should be checking the CLOSES of bars in the dataseries # 1, and check if they have crossed above the EMA dataseries.

    Am i misunderstanding the function's meaning? If so what's the correct interpretation and how can i implement the condition i need?

    Please advise.

    Thanks
    Umer

    #2
    Umer, from which BarsInProgress do you check this condition and would this be run with CalculateOnBarClose = false in realtime? Then the bar would not need to close above the EMA, as conditions could "come and go" intrabar here...

    Comment


      #3
      Hello Bertrand

      Thank you for your prompt reply.

      I have multiple timeseries added to my strategy and i use the appropriate one.
      But yeah, the main issue here is the fact that i am running it with CalculateOnBarClose = true i.e realtime.

      Is there a workaround for that?

      Thanks,
      Umer

      Comment


        #4
        Thanks Umer, yes you could run this check the in FirstTickOfBar to simulate using COBC = true for this only - http://www.ninjatrader.com/support/h...FirstTickOfBar

        Comment


          #5
          Thanks for the reply

          I will check it and let you know if i run into trouble.

          Thanks
          Umer

          Comment


            #6
            Hello Bertrand,

            Can you please explain this stipulation:

            NOTE: This property should NOT be accessed outside of the OnBarUpdate() method

            Because i am using a modular approach and i call different functions from my OnBarUpdate method. And when i tried using the FirstTickOfBar in my methods, NT doesn't give any compilation errors.

            Please advise if i can use it the way i am? If not then how does it effect?

            Thanks,
            Umer

            Comment


              #7
              Umer, I think it should be fine, as you call your custom functions / methods still from OnBarUpdate() context.

              Comment


                #8
                Hello Bertrand,

                Does the FirstTickOfBar have any adverse effect on the performance? Since i used it in my strategy, NinjaTrader has frozen twice since yesterday.

                Please advise.

                Thanks
                Umer

                Comment


                  #9
                  Umer, I'm not aware of any direct impact - this would need to be see in context, would this be reproducible for you in replay? This would give a good chance of further isolation. Also: do you see any entries in the log tab / trace file when this occurs?

                  Comment


                    #10
                    There is no alarming message in the logs as well as trace. I will try to investigate it further

                    Comment


                      #11
                      Hello Bertrand,

                      I have another small but related question. From what i understand from the description of these 2 methods, they only check whether one dataseries has crossed above or below the other dataseries in the previous N bars. So, CrossAbove will return true if close has crossed above the EMA in the past 5 bars regardless of the fact that it may have crossed below as well in the past 5 bars.

                      Is there a way to find out if, for example, the close has crossed above and stayed above the EMA?

                      Please advise.

                      Thanks
                      Umer

                      Comment


                        #12
                        You're correct in understanding, it would be a CrossAbove check for the lookback period - it would not check for a continuous close above your series. This could be implemented though via further custom coding into your conditions.

                        Comment


                          #13
                          I'm trying to interpret the CrossAbove/CrossBelow function as well and I have a question. I set my CalculateOnBarClose = false to allow my strategy to immediately exit positions when profit targets are hit.

                          I'm trying to create a strategy where if the price dips below a certain price but closes above it on the same bar, a long position will be entered into. Am I correct in using the CrossAbove function here? Would this produce the desired result?

                          Code:
                          if (FirstTickOfBar && Position.MarketPosition == MarketPosition.Flat)
                          {
                              if (CrossAbove (Close, 20, 1)
                                   {
                                        EnterLong (DefaultQuantity, "")
                                   }
                          }

                          Comment


                            #14
                            Originally posted by IFT20 View Post
                            I'm trying to interpret the CrossAbove/CrossBelow function as well and I have a question. I set my CalculateOnBarClose = false to allow my strategy to immediately exit positions when profit targets are hit.

                            I'm trying to create a strategy where if the price dips below a certain price but closes above it on the same bar, a long position will be entered into. Am I correct in using the CrossAbove function here? Would this produce the desired result?

                            Code:
                            if (FirstTickOfBar && Position.MarketPosition == MarketPosition.Flat)
                            {
                                if (CrossAbove (Close, 20, 1)
                                     {
                                          EnterLong (DefaultQuantity, "")
                                     }
                            }
                            Yes, the above code will look for a a cross above in the previous 1 bar. So what you need to do should be done.

                            Comment


                              #15
                              Thanks for the quick reply Aurora! To take it a step further.. how can I achieve the same result if instead of dipping below the specified price, the price ticks to exactly the price I specified before closing above it? For example, if the price is falling and its low of the bar is 20 (which is the CrossAbove price I specified), will an entry still be created?
                              Last edited by IFT20; 08-20-2013, 09:35 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              650 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              370 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              109 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              574 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              577 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X