Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter Position on Close of Candle

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

    Enter Position on Close of Candle

    Hi there,

    I am trying to get a strategy to enter long or short positions on the close of the candle that meets the signal requirements or when the price meets the requirements. However, the strategy is entering on the opening of the following candle instead. Is there a way to get it to open on the close of the candle that meets the strategy requirements or as the price changes to meet that requirement?

    I tried updating the calculation to "OnEachTick and OnPriceChange", but that didn't change when the strategy entered the position.

    Thanks for your help!

    #2
    Hello tjfintrade,

    When orders are submitted after the bar has closed the order is filled at the moment it is submitted at the open of the new bar.

    To place an order before the bar closes, you would need Calculate.OnEachTick (and TickReplay in historical) along with 1-tick intra-bar granularity, and a way to predict when the bar is going to close.

    Below is a link to a forum post that discusses.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello tjfintrade,

      When orders are submitted after the bar has closed the order is filled at the moment it is submitted at the open of the new bar.

      To place an order before the bar closes, you would need Calculate.OnEachTick (and TickReplay in historical) along with 1-tick intra-bar granularity, and a way to predict when the bar is going to close.

      Below is a link to a forum post that discusses.
      https://forum.ninjatrader.com/forum/...bar#post782992
      Thanks for the information. I read through the post you sent, and I am still a little confused when you say, "predict when the bar is going to close". Why would there need to be a prediction of when the bar is going to close since we know when the bar is going to close? For instance, if I am using a 5 min bar, we should already know the bar is going to close at the end of 5 minutes right? Even if I was using a tick chart shouldn't the order be placed and time-stamped the moment the last tick hit the tape? Which should be on the candle that generates the signal.

      I have used this same strategy with Thinkorswim and TradeStation and they both process the entry and exit at the close of the bar in live trading and in backtesting.

      Just trying to see if there is something specific we need to add to our code to get this to function as intended.

      Thanks!

      Comment


        #4
        Hello tjfintrade,

        That would depend on the bar type.

        A time based bar is easy to predict. A movement based bar like range or tick would not be easy to predict when it will close.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by tjfintrade View Post
          I have used this same strategy with Thinkorswim and TradeStation and they both process the entry and exit at the close of the bar in live trading and in backtesting.
          Well, that's partially true I suppose. They possess the ability to pretend they can get in exactly at the close in back-testing. That's a bug, not a feature. That doesn't work in live trading - in live trading, what happens is when the bar has closed (which isn't known until the first tick (or open) of the following bar - they then place a market order and you may or may not get a fill at the now previous bar's close. And, things that don't work in live trading really don't belong in back-tests unless the reports are going to be filed under "fiction."

          TradeStation has the ability to place orders "at close" in EasyLanguage for reasons that date back practically to trading off of the stocks page in the back of the newspaper and when they sent out TradeStation 2000 diskettes by Federal Express (it was not called FedEx yet - that didn't happen until 1994 and TradeStation started in 1982). You don't really want to back-test the way it was done in the 1980s and 1990s.

          ThinkOrSwim has that ability because it wasn't designed for back-testing at all and was only added as an afterthought and I don't think they thought it through. You rarely see automated trading systems for real on ThinkOrSwim - just sort of "proof of concept" or demonstration systems or things someone tested so they could put the equity curve on their website. Almost every futures-related request that comes in here to do with ThinkOrSwim is to convert systems away from there so they can get a good test. They do have good options analytics, though.
          Last edited by QuantKey_Bruce; 05-05-2023, 03:39 PM.
          Bruce DeVault
          QuantKey Trading Vendor Services
          NinjaTrader Ecosystem Vendor - QuantKey

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          53 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X