Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to buy at close of signaled day.

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

    How to buy at close of signaled day.

    How do I enter on close of the same day as the signal. I'm seeing the entry on the open of the following day?

    For this case:

    Strategy::OnBarUptate()
    {
    if (Time[0].Day == 1) // enter on first of the month
    EnterLong(100, "D1_" + Time[0].ToShortDateString());
    }


    Then on the chart view it shows that the actual purchase was made on the following day (the 2nd of each month) at the open price.

    In the orders view it shows the time as 1st at 1pm.

    So its like the order is placed just after the close so its filled the next day I suppose.

    Is there a simple way to buy at the close? I realize that the indicator would need to be based on a value a few seconds before the close and am willing to neglect that effect.

    Thanks!
    Chris

    #2
    Hello Chris,

    Thank you for your post.

    You would need to calculate intra-bar what the day was. Are you running in backtesting or real-time?

    In real-time data you can just set the CalculateOnBarClose to False. However, historical data and backtesting will calculate on the close of the bar. So the entry is placed after the bar calculates on the close, meaning on the next bar the order will be placed.

    For information on historical versus real-time execution please visit the following link: http://www.ninjatrader.com/support/h...ime_vs_bac.htm

    You could use a smaller series added to the code to check the day, but then you would also need to submit the order to the smaller series on the before the close of the day. Otherwise you will still see the same behavior on historical data and backtesting.

    For information on additional series in your script please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Good answer for real time trading!

      Quite unfortunate for historical inter-day trading.

      I will submit a request for a "buy at close when bar is last of the session." Seems like it would be useful for backtesting systems based on day, 60, 30, 15.

      Thanks,
      Chris

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      33 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, Yesterday, 02:41 AM
      0 responses
      15 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      25 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      34 views
      0 likes
      Last Post CarlTrading  
      Working...
      X