What are my options please?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy with COBC = true needs Opening price
Collapse
X
-
Strategy with COBC = true needs Opening price
I have a multi-series strategy that needs to run with COBC = true. One series is 5 min and the other is a range bar type. I would like to get the Opening price, but I dont want to wait 5 mins to check the 9:35 bar for the Open[0].
What are my options please?Tags: None
-
Hello Laserdan,
Thanks for writing in and I am happy to assist you.
You can use the Opens[<bars array index>][0] to get the opening price of the 5 minute bar. http://www.ninjatrader.com/support/h...html?opens.htm
For example if your primary data series is a range bar and the secondary data series is a 5 minute data series and you want to get the opening price of the 5 minute bar when the range bars gets updated then you can use the following code
Alternatively you can also open the OnMarketData steam and get update from there.Code:if (BarsInProgress == 0) //range bar updates { double open5 = Opens[1][0]; //gets the open of the 5 minute data series //rest of code }
You could also set COBC to false and check the all relevant codes in the FirstTickOfBar while get the opening value from the OnBarUpdate method as it updates. Please refer to this sample code to get more idea on it http://www.ninjatrader.com/support/f...ad.php?t=19387
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
-
Hello Laserdan,
Yes it will eat up resource, but it depends on how much code you expose in the OnMarketData event. For example you could set your entry logic in the OnBarUpdate event while the exit logic is coded in the OnMarketData event. This way you can optimize resource utilization.
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Hello Laserdan,
If you only need the opening price of the then no need to set COBC to false. Please use the following code
Set COBC to false and use the following code
Code:protected override void OnBarUpdate() { if (BarsInProgress == 0 && FirstTickOfBar && BarsArray[0].FirstBarOfSession) { //get open price } else if (FirstTickOfBar) { //rest of the code } }
Alternatively you can also use the following code with COBC set to true. But do note the OnMarketData stream will remain open which will consume some resource and OnMarketData is for realtime only. It cannot be backtested.
in variable
Code:bool gotOpenPrice = true;
If it is a multi timeframe strategy (i.e. instrument is same but different timeframe) then the opening price of the day will be same for all data series as such we pull it from any one series.Code:protected override void OnMarketData(MarketDataEventArgs e) { if (BarsInProgress == 0 && BarsArray[0].FirstBarOfSession && e.MarketDataType == MarketDataType.Last && gotOpenpricee == false) { //get open price; gotOpenPrice = true; } }
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Thank you for your time JoyDeep. I was afraid that was the case.
Please remember I HAVE TO RUN WITH COBC = true for various other reasons in this complex strategy I have written.
So my only option is to access a datastream in the OnMarketUpdate method. Which will only be used on live data , no backtesting.
If I wanted to backtest I guess i could I use another dataseries of 1 tick & check that when the market opens. I am using range bars anyways, so I need tick data to build the range bars. I guess it wont slow it down that much...
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment