Many Thanks!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to pass double from strategy to indicator?
Collapse
X
-
I worked through it a little, but the retrieved variable value is always 0 (zero).
Code in strategy (where shared variable is stored):
Code in Indicator OnBarUpdate to assign value to shared variable:Code:namespace NinjaTrader.NinjaScript.Strategies { public partial class MySharedVariables: NinjaTrader.NinjaScript.AddOnBase { public static double CumulativeProfit { get; set; } } }
Code in indicator OnBarUpdate to retrieve the value of shared variableCode:NinjaTrader.NinjaScript.Strategies.MySharedVariables.CumulativeProfit = DayNetProfit;
Code:protected override void OnBarUpdate() { CumulativeProfitPlot[0] = NinjaTrader.NinjaScript.Strategies.MySharedVariables.CumulativeProfit; Print("Cumulative Profit (from Indicator) " + CumulativeProfitPlot[0]); // This is always 0 (zero) }
Comment
-
Hello Skechers,
making a double requires extra logic for that to work, you can instead just use the sample exactly as it is to pass values. If you need to pass more than one value you would duplicate the logic in that sample.
The strategy exposes a Series<double> which does not require extra logic to expose to the indicator. The indicator reads the 0 bars ago value of the series and plots it.
Comment
-
Hello Skechers,
It looks like you have misunderstood the sample, the sample code does not retrieve any values from the indicator. It does the reverse like you are asking.
Please look at the indicators that come in the sample and see how they are using a reference to the strategy to get values from the strategy.
This is the code which retrieves the value from the strategy and has the indicator plot it:
Code:Plot[0] = Strategy.OverlayPlot.GetValueAt(CurrentBar);
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
48 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
66 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment