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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Brandon H.NinjaTrader Customer Service
-
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
-
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
-
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
-
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,
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 algospoke, Yesterday, 06:40 PM
|
2 responses
23 views
0 likes
|
Last Post
by algospoke
Today, 07:04 PM
|
||
Started by ghoul, Today, 06:02 PM
|
3 responses
15 views
0 likes
|
Last Post Today, 06:43 PM | ||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
46 views
0 likes
|
Last Post
by jeronymite
Yesterday, 10:10 PM
|
||
Started by Barry Milan, Yesterday, 10:35 PM
|
7 responses
23 views
0 likes
|
Last Post Today, 06:16 PM | ||
Started by AttiM, 02-14-2024, 05:20 PM
|
10 responses
181 views
0 likes
|
Last Post
by jeronymite
Today, 06:11 PM
|
Comment