I am using the Add("variable", PeriodType.Minute, 60); // BarsArray[1] type to add a secondary instrument in my strategy. The strategy will automatically assign an instrument to the variable, however under certain circumstances I would need the value to be constant ==1
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
strange question
Collapse
X
-
strange question
by any chance is there a way in NT7 to upload an instrument as secondary instrument that returns a constant value of 1?
I am using the Add("variable", PeriodType.Minute, 60); // BarsArray[1] type to add a secondary instrument in my strategy. The strategy will automatically assign an instrument to the variable, however under certain circumstances I would need the value to be constant ==1Tags: None
-
Hello yades,
Thank you for your post.
This would not be possible without creating a data feed that provided a constant value of 1. You can however do this by creating a data series that has a constant value of 1. Please see the example below on how to add this data series and call it into an indicator as the input:
For information on the DataSeries class please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htmCode:#region Variables private DataSeries myDataSeries; #endregion protected override void Initialize() { myDataSeries = new DataSeries(this); } protected override void OnBarUpdate() { myDataSeries.Set(1); //Prints the 10 period SMA of the myDataSeries Print(SMA(myDataSeries, 10)[0]); }
Please let me know if I may be of further assistance.
-
Patrick
very useful, I need a secondary instrument in my strategy to recall the cross rate for forex rates, but only for specific xurrency pairs.
Do you think this script would work:
Code:Variables private string variable0 myDataSeries = new DataSeries(this); Initialize() myDataSeries = new DataSeries(this); Add(xRate, PeriodType.Minute, 60)// BarsArray[1] protected override void OnStartUp() { var variable0 = String.Empty; if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY"; if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD"; if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries"; } protected override void OnBarUpdate() { myDataSeries.Set(1);Originally posted by NinjaTrader_PatrickH View PostHello yades,
Thank you for your post.
This would not be possible without creating a data feed that provided a constant value of 1. You can however do this by creating a data series that has a constant value of 1. Please see the example below on how to add this data series and call it into an indicator as the input:
For information on the DataSeries class please visit the following link: http://www.ninjatrader.com/support/h...ries_class.htmCode:#region Variables private DataSeries myDataSeries; #endregion protected override void Initialize() { myDataSeries = new DataSeries(this); } protected override void OnBarUpdate() { myDataSeries.Set(1); //Prints the 10 period SMA of the myDataSeries Print(SMA(myDataSeries, 10)[0]); }
Please let me know if I may be of further assistance.
Comment
-
Hello yades,
Thank you for your response.
I do not understand what you intend to do with variable0, can you explain this section of the code further?
I look forward to your response.Code:var variable0 = String.Empty; if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY"; if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD"; if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries";
Comment
-
sure.
First of all this is a MTF strategy.
According to what my primary instrument is (BarsArray[0]), I want my strategy to select a specific secondary instrument (BarsArray[1]), given this selection is done only once on start-up, i thought it might be convenient to include this computation in the OnStartUp() method. Also I assume the output format of variable0 must be a string, as this will then be used in the Add() method in the Intialize() method to select the secondary instrument. Let me know if this is clear enough.
Originally posted by NinjaTrader_PatrickH View PostHello yades,
Thank you for your response.
I do not understand what you intend to do with variable0, can you explain this section of the code further?
I look forward to your response.Code:var variable0 = String.Empty; if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY"; if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD"; if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries";
Comment
-
Patrick alternatively to the variable i could use a switch type to determine the secondary instrument. However, what I need to know is if this can be done in the OnStartUp() method? I ask this because the string assigned must then be added to the Add() type in the Initiation() camp.
Originally posted by NinjaTrader_PatrickH View PostHello yades,
Thank you for your response.
I do not understand what you intend to do with variable0, can you explain this section of the code further?
I look forward to your response.Code:var variable0 = String.Empty; if(Instrument.MasterInstrument.Name == "USDJPY") variable0 = "$GBPJPY"; if(Instrument.MasterInstrument.Name == "EURUSD") variable0 = "$GBPUSD"; if(Instrument.MasterInstrument.Name == "EURGBP") variable0 = "myDataSeries";
Comment
-
Hello yades,
Thank you for your response.
The "myDataSeries" string will not work as that is a DataSeries and not an instrument. I am not sure how checking the MasterInstrument.Name will work as OnStartUp() is called after Initialize().
Can you provide details on what exactly you are trying to do?
I look forward to your response.
Comment
-
Forget about the myDataSeries, i've another way around this. To cut a long story short I need to know if its possible to set the secondary instrument bars object from within the strategy, hence running a calculation in the initiate() method or elsewhere. Would you be able to advise on this?
Originally posted by NinjaTrader_PatrickH View PostHello yades,
Thank you for your response.
The "myDataSeries" string will not work as that is a DataSeries and not an instrument. I am not sure how checking the MasterInstrument.Name will work as OnStartUp() is called after Initialize().
Can you provide details on what exactly you are trying to do?
I look forward to your response.
Comment
-
Hello yades,
Thank you for your response.
You could do something like the following:
Please let me know if I may be of further assistance.Code:protected override void Initialize() { if(Instrument.MasterInstrument.Name == null) return; if(Instrument.MasterInstrument.Name == "EURUSD") { Add("$GBPUSD", PeriodType.Minute, 60); } }
Comment
-
This answer all my questions. Thanks
Originally posted by NinjaTrader_PatrickH View PostHello yades,
Thank you for your response.
You could do something like the following:
Please let me know if I may be of further assistance.Code:protected override void Initialize() { if(Instrument.MasterInstrument.Name == null) return; if(Instrument.MasterInstrument.Name == "EURUSD") { Add("$GBPUSD", PeriodType.Minute, 60); } }
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
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment