How can I instument symbol (ES) and timeframe (2000 tick) within the strategy code? Use may change it later, but it would predefined to ES 2000 tick.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Set Instrument symbol and timeframe within the strategy code
Collapse
X
-
Hello UltraNIX,
Thanks for your post.
You could add an additional data series in your script using AddDataSeries(). Then, you could ignore processing logic for BarsInProgress 0 (primary series) and add all of your logic within BarsInProgress 1 (added data series). If all your strategy logic is within a BarsInProgress 1 check then your strategy's logic would only process for the added data series.
See the help guide documentation below for more information AddDataSeries() and BarsInProgress.
AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Users have the pleasure of choosing whatever BarType and Instrument to
run a strategy -- there is no 'default' setting for these -- users are forced to
make these choices when starting the strategy.
You can make efforts to defeat these choices, such as adding a new data
series of your preferred instrument, and ignoring BarsInProgress == 0.
Or, perhaps a better approach -- setup your strategy to inspect the user
choices of BarType and Instrument, and refuse to run if these values are
unacceptable.
- Likes 1
Comment
-
Adding additional data series would require me to refactor code (like, instead of using Time[0], I would have to use Times[1][0]), which seems unworthy of effort.Originally posted by NinjaTrader_BrandonH View PostHello UltraNIX,
Thanks for your post.
You could add an additional data series in your script using AddDataSeries(). Then, you could ignore processing logic for BarsInProgress 0 (primary series) and add all of your logic within BarsInProgress 1 (added data series). If all your strategy logic is within a BarsInProgress 1 check then your strategy's logic would only process for the added data series.
See the help guide documentation below for more information AddDataSeries() and BarsInProgress.
AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm
Let us know if we may assist further.
NinjaTrader could have a thought of letting creator of a strategy to determine symbol and timeframe in later releases.
Comment
-
Yes, I am leaning towards that approach - inspect and refuse, if values are unacceptable, if it's not possible to set symbol and timeframe.Originally posted by bltdavid View PostUsers have the pleasure of choosing whatever BarType and Instrument to
run a strategy -- there is no 'default' setting for these -- users are forced to
make these choices when starting the strategy.
You can make efforts to defeat these choices, such as adding a new data
series of your preferred instrument, and ignoring BarsInProgress == 0.
Or, perhaps a better approach -- setup your strategy to inspect the user
choices of BarType and Instrument, and refuse to run if these values are
unacceptable.
Comment
-
Well, uh, hold on there a second. That is not necessarily the case.Originally posted by UltraNIX View PostAdding additional data series would require me to refactor code (like, instead of using Time[0], I would have to use Times[1][0]), which seems unworthy of effort.
Let's consider BarsInProgress a bit more.
When OnBarUpdate is called with BarsInProgress == 1, everything
has been pre-set to what is known as the 'BarsInProgress context'.
What does that mean?
It means a reference like Time[0] automatically reflects the current
BarsInProgress data series.
Which means,
You only need to use Times[1][0] if BarsInProgress != 1.
The idea is when BIP=n, having to explicitly use Times[n][0] is not
strictly necessary -- because Time[0], Close[0], etc, have all been
mapped to the correct series for the current BIP.
That is called the 'BarsInProgress context', and is an automatic
internal setup before calling OnBarUpdate, OnMarketData, etc.
Thus, in a simple case, perhaps all you need to do is put a guard
to filter out all unwanted BarsInProgress values (including 0), so
that your logic only applies to a certain data series,
This cuts way down on any refactoring.Code:protected override void OnBarUpdate() { if (BarsInProgress != 1) return; ... use Time[0], Close[0], etc, normally ... ... all references are using BIP == 1 series ... }
See 'Accessing the Price Data in a Multi-Bars NinjaScript' here.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
59 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
134 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
74 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment