Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Cover position on Close of the bar
Collapse
X
-
Actually I want to open on Monday on OPEN price and close on Friday on CLOSE price using daily chart.
-
-
nysetrader,
There are a couple issues with what you want to accomplish here.
With calculate on bar close = true, then you wont get a fill until the Monday bar closes. This is the same for the Friday bar, with the difference that it won't close until the next trading day.
In backtesting, calculate on bar close is essentially true so you won't see results that match live trading in backtesting without adding intrabar granularity. This is possible, but more computationally intensive as there are hundreds to thousands of ticks per day.
Here is an example that works but it may cause your charts to take awhile to display historical info, and it will require downloading historical minute data so its available for the strategy in backtesting. It also requires setting a time to end trading since getting this info from the session template isn't currently supported.
Unfortunately there is no way to guarantee an order fills at exactly the open and closes at exactly the close, however you should be able to work with this sample to get something pretty close. Please see the attached screen shot to understand what I mean here.Code:protected override void Initialize() { CalculateOnBarClose = false; ExitOnClose = false; Add(PeriodType.Minute,1); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if(BarsInProgress == 0 && Historical) { return; } else if(BarsInProgress == 1) { Print(Times[1][0].DayOfWeek+" "+ToTime(Times[1][0])+" "+ToTime(EndHour,EndMinute,0)); if (Times[1][0].DayOfWeek == DayOfWeek.Monday) { EnterLong(DefaultQuantity, ""); } else if(Times[1][0].DayOfWeek == DayOfWeek.Friday && ToTime(Times[1][0])>=ToTime(EndHour,EndMinute,0)) { ExitLong(); } } }Last edited by NinjaTrader_AdamP; 04-17-2012, 08:59 AM.Adam P.NinjaTrader Customer Service
Comment
-
Thank you Adam. I know how to do what I need using intraday data, but for big stock list it will be much more computationally intensive than using daily data only. I've looked through support forum and I saw a lot of requests to your development team to make closing on CLOSE price of bar available. Also it is available in many other programs for backtesting which I tried, but NT is much better than others. Is it really planned to make this feature and, if so, is there any estimated time of doing this?
Comment
-
nysetrader,
It looks like Bertrand may have already responded to your feature request in another thread.
With calculate on bar close = false, you could access the "Close[0]' value any time friday and it would be the most current last traded price. The example I gave you was meant to work in backtesting.
The main issue here is the backtesting vs. real time trading discrepancy related to intra-bar granularity. You could backtest using the example, then have a separate strategy working only on daily bars with COBC = false for live trading. You can check the current time using DateTime.Now and use this for entrance/exit conditions in live trading, but it would require forward testing to see how it performs. With the live version, you wouldn't need to add a minute data series.
Please let me know if I may assist further.Last edited by NinjaTrader_AdamP; 04-17-2012, 09:30 AM.Adam P.NinjaTrader Customer Service
Comment
-
I second that!
Just wanted to let you know I would also love to see the feature you are discussing: opening or closing a position at the close of the bar. I'm working with the free Kinetick data for the moment where adding granularity from intraday bars isn't an option.
Thanks!
Comment
-
Also interested in this feature
Hi all,
I also wanted to say that it would be great to have an exit on close of a daily bar. I use data from IB, and have coded a few strategies with intraday timeframes. Now when you want to exit on close you just set this to true in the bacfktest options and that's it.
For a new trading idea I have the entry condidions could all be handeled in daily timeframe. But to do decent backtests for strategies that only take a few trades a year I would need at least ten years of minute data if I want to test exit on close. IB provides only 2 years.
The easiest thing would be to have this Exit on bar close option.
Maybee there is a workaround or prospects of seing this updated as a new feature.
Marco
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
646 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
367 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
569 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment