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

Calculate on Bar Close or not?

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

    Calculate on Bar Close or not?

    Hi,

    I have an simple strategy witch use the SMA to enter a position with a limit oder for the next bar. If i set the Caltulate on BarClose to false I can see that Nijatrader dont calculate the SMA for the current bar.
    Here is an example of the Entrylogic:

    //Long
    if(Position.MarketPosition == MarketPosition.Flat
    && Trade
    && (ToTime(Time[0])) >= 110000
    && (ToTime(Time[0])) <= 234500
    && Close[0] > Ma[0]
    && Close[0] > Filter[0])
    { EnterLongLimit(Stuck,Instrument.MasterInstrument.R ound2TickSize(Ma[0] - EntryTicks*TickSize*2), "Long");
    }

    The Backtest is fine but if i run the strategy in Realtime the Entryorders are not alway submitted. Do you think it could be because the Calculate on Bars Close is set to TURE? Would it be better to run such Code like in the example above in Calculate on BarClose = FALSE???

    #2
    It is up to you which one you want to run on. With CalculateOnBarClose = true, you are waiting till the close of the bar to run calculations on it. You are not calculating on the current building bar, but rather the bar that just closed. With CalculateOnBarClose = false, you are processing every single incoming tick on the building bar.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      So if I run the strategy with onBarClose = false, then I must use the condition
      "FirstTickOfBar"? Else will Ninjatrader submitt an Order on every Tick?

      In such case I must change such standart Entry like:
      Close[0] > Open[0] to Close[1] > Open[1] and then the oder will be submitted on the open of the current bar?
      Is this correct?

      Comment


        #4
        If you want it to submit on the open of a bar after calculating the values of the recently closed bar just stick with CalculateOnBarClose = true and use [0].

        Otherwise you will need if (FirstTickOfBar) and offsetting your [0] to [1]s to get the recently closed bar.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by andrewtrades, Today, 04:57 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        5 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X