Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

what really happens when calculateonbarclose = false

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

    what really happens when calculateonbarclose = false

    I am trying to achieve the following:
    When a certain condition is met the system must:
    Remember the highest high of the previous 3 bars for a possible long position, and
    Remember the lowest low of the previous 3 bars for a stoploss of a possible long

    I have the same rules (opposite condition) for going short.

    I am having a problem with the "advanced order handling"

    When the system goes long a setstoploss is placed - which then prevents a short order from being filled. I have therefore decided to only use enterlong, exitlong, entershort and exitshort (these orders do not seem to have the same complications as stop orders)

    The thing is I do not want to only place orders when a bar has closed. I want to for example go long whenever the price goes higher than the highest high of the previous 3 bars - and the condition is true.

    I have started to look at making calculateonbarclose = false. What I don't understand is what price Close[0] refers to when calculateonbarclose = false. Does it still wait for a bar to close.

    The ideal would be if someone can show be a good example of advanced order handling where both long and short positions are taken. The examples I could find show going in one direction only.

    Or if someone can give me some kind of "template" to do the following:
    If long condition is met and price > highest high of previous 3 bars then go long immediately, and
    place stop loss order below lowest low of previous 3 bars

    If short condition is met and price < lowest low of previous 3 bars then go short immediately, and
    place stop loss order above highest high of previous 3 bars

    If system is long and condition for short position is met then exit long and go short. The way it is coded now the long position is only closed by the stoploss - never by a short position. I have read the documentation on advanced order handling but are still stuck

    Sorry for being so long

    #2
    When "CalculateOnBarClose" is set to false, the value of Close[0] is the most recent close price as if the bar had closed then. Think of watching an actual chart and seeing the last price of the bar changed. Close[0] == the last price.
    RayNinjaTrader Customer Service

    Comment


      #3
      I think I understand but ...

      Originally posted by NinjaTrader_Ray View Post
      When "CalculateOnBarClose" is set to false, the value of Close[0] is the most recent close price as if the bar had closed then. Think of watching an actual chart and seeing the last price of the bar changed. Close[0] == the last price.
      Thank you Ray for the response

      I think I understand what you are saying but I think saying Close[0] == the last price needs to be qualified. I have changed my system to use Close[0] - and it performs the way I expect when using live data. Using historical data however Close[0] refers to the close of the last bar - even if CalculateOnBarClose = false.

      1) Is my statement above correct?
      2) If correct then it seems that using live and historical data will ALWAYS differ. It seems that the only thing I can do to try and replicate a true "live" environment is to record data and then use replay? Or - is there something I must know that will enable testing on live and historical data to show exactly the same results?

      TIA

      Comment


        #4
        Your understanding is correct. You only can backtest with CalculateOnBarClose=true logic, since there is no "look into the bar and speculate what could have happened intra-bar" logic.

        Comment


          #5
          High[0] compared to Close[0]

          Hi Ray,

          Quote:
          When "CalculateOnBarClose" is set to false, the value of Close[0] is the most recent close price as if the bar had closed then. Think of watching an actual chart and seeing the last price of the bar changed. Close[0] == the last price.

          Does the same principle apply to High[0], i.e. it is the most recent high of the current bar?

          Hadley

          Comment


            #6
            >> Does the same principle apply to High[0], i.e. it is the most recent high of the current bar?
            Correct. barsAgo=0 always denotes the most current bar.

            Comment


              #7
              Thanks Dierk,

              Just to confirm, I meant in the context of CalculateOnBarClose=false. So in other words if I want to check that the current high is greater than the closing high of the previous bar for example, i can use:

              High[0] > High[1]

              Hadley

              Comment


                #8
                barsAgo=0 always denotes the most current bar, regardless if CalculateOnBarClose=true/false.

                Comment


                  #9
                  perfect !!! thank you

                  Comment


                    #10
                    Originally posted by verge View Post
                    If correct then it seems that using live and historical data will ALWAYS differ. It seems that the only thing I can do to try and replicate a true "live" environment is to record data and then use replay? Or - is there something I must know that will enable testing on live and historical data to show exactly the same results?
                    The historical resolution depends on your bar size. If you use 15 second bars, for example, then you'll get 4x the resolution as 1 minute bars. But there are tradeoffs, including the fact that you can't get as much historical data for sub-minute bars.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    560 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    325 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
                    547 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X