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 helpwanted, Today, 03:06 AM
        2 responses
        21 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by DayTradingDEMON, Today, 09:28 AM
        0 responses
        1 view
        0 likes
        Last Post DayTradingDEMON  
        Started by navyguy06, Today, 09:28 AM
        0 responses
        1 view
        0 likes
        Last Post navyguy06  
        Started by rjbtrade1, 11-30-2023, 04:38 PM
        2 responses
        77 views
        0 likes
        Last Post DavidHP
        by DavidHP
         
        Started by cmtjoancolmenero, Yesterday, 03:58 PM
        7 responses
        31 views
        0 likes
        Last Post cmtjoancolmenero  
        Working...
        X