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

strategy on bar close

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

    strategy on bar close

    hello...
    I test my strategy on EOD data and would like to enter position on Close[0]. But the strategy open the position on Open next bar. And this is problem, because the different between Close[0] and Open next bar is big. How can I how can I solve the problem?
    See the picture.

    Thank you
    Lico
    Last edited by licovata; 02-12-2019, 09:45 AM.

    #2
    Hello licovata,

    Thanks for your post.

    Strategies will have the by default use a Calculate mode of OnBarClose. The open of the next bar signals a bar closure so the event happens on the open of the next bar. This is because NinjaScripts are event based (based on incoming tick data) rather then being strictly based on time.

    If you would like to have the strategy take action before the close of a bar, you can have the strategy Calculate OnPriceChange or OnEachTick. This will have the strategy constantly update for the developing bar with each incoming tick or price change.

    More information on Calculate modes can be referenced here - https://ninjatrader.com/support/help.../calculate.htm

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      I have a similar inquiry. Mostly for exits i have issue when i view in after hours on historical data and a tick based bar ie renko. You close a bar, your condition are meet to update a exit order based on for example the close of a 50 brick size bar. To close another bar up is 50 ticks, to close another bar down is 100 ticks. You have your stop order 40 ticks below the Close(0) that meet all your conditions. However........... the order fills at the close of the next bar which is 60 ticks lower,

      the strategy is build On Bar Close and if you run the strategy "on each tick" or "on price change" when applying to the chart NOTHING different happens. IS THE because of the nature of the input series or does the calculate NOT override what is built into the Strategy

      Comment


        #4
        Additional information is for the Entry orders that are created on bar close YOU can create a buy stop that will not fill until the next bar close if the direction of the bar does not change, but if the direction is change for the entry you do NOT have to wait until the next bar close 100 ticks above the last bar close THE STRATEGY will send the order half way between the 2 bars. EXAMPLE if you place your Buy Stop order on a reversal type bar at 40 ticks above the last Close Bar "Close[0] the fill will be 50 ticks above the Close[0] and will not wait for the bar close 100 ticks above the last bar close.

        THIS is what I expected to see on Exit orders but is not the case

        Comment


          #5
          Hello DTSSTS,

          Order fill simulations and default strategy behavior for backtests vary between historical data and with realtime data. We also should not confuse the filling of orders with the way the strategy processes OnBarUpdate as these are different concepts in NinjaTrader.

          When backtesting, we are using historical data and the strategy will default to using Calculate.OnBarClose for efficiency. (Calculating each tick or price change on historical data can be expensive) This can be overridden using Tick Replay, and having the strategy set its own Calculate mode. This would be for processing historical data in OnBarUpdate with a specific Calculate mode and will not create more accurate order fill simulations.

          Order fill simulations will either use bid/ask/volume data when testing realtime, but only the OHLC values for the data series the strategy is applied against will be used to simulate order fills from historical data. Backtests can use High Order Fill Resolution to simulate order fills with single tick granularity. Tick Replay is not compatible with High Order Fill Resolution, so scripts that use Tick Replay will need to have the single tick data series added to it and have orders submitted to the single tick data series. Please see SampleIntrabarBacktest for an example.
          Publicly available resources on the items discussed can be found below.

          Discrepancies Between Realtime and Backtest - https://ninjatrader.com/support/help...ime_vs_bac.htm

          Historical Fill Algorithm and High Order Fill Resolution - https://ninjatrader.com/support/help...ical_fill_.htm

          SampleIntrabarBacktest - https://ninjatrader.com/support/help...ipt_strate.htm

          Developing for Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

          Please let us know if you have any additional questions.
          JimNinjaTrader Customer Service

          Comment


            #6
            so are you saying in a realtime live trading situation that the fill should be the stopmarket order price plus any slippage of course

            Comment


              #7
              Hello DTSSTS,

              Yes, for a real time order fill simulation on a Sim or Playback account, the current bid/ask and volume will determine the order fill instead of the using OHLC values, so the fill price of the market order (filled by bid/ask) + slippage would be seen for the order fill.

              Let us know if you have any additional questions.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:00 AM
              0 responses
              2 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Started by elirion, Today, 01:36 AM
              0 responses
              4 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by gentlebenthebear, Today, 01:30 AM
              0 responses
              4 views
              0 likes
              Last Post gentlebenthebear  
              Started by samish18, Yesterday, 08:31 AM
              2 responses
              9 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by Mestor, 03-10-2023, 01:50 AM
              16 responses
              391 views
              0 likes
              Last Post z.franck  
              Working...
              X