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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
43 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
20 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
30 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
47 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
38 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment