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 pechtri, 06-22-2023, 02:31 AM
      10 responses
      124 views
      0 likes
      Last Post Leeroy_Jenkins  
      Started by judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      59 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Yesterday, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Yesterday, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Yesterday, 03:01 PM
      2 responses
      22 views
      0 likes
      Last Post helpwanted  
      Working...
      X