I've tried several methods like to call Custom Indicator and loading in State.DataLoaded / State.Historical but then OnBarUpdate much the bars, so I 'm not getting fixed value on real-time bar, but where the OnBarUpdate is. See the pic for more information. Thanks in advance.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to pass real-time value and recalculate the indicator ?
Collapse
X
-
How to pass real-time value and recalculate the indicator ?
It's a very concrete question. How to read real-time (last value) indicator[0] value an use this value to redraw/recalculate the indicator from the beginning?
I've tried several methods like to call Custom Indicator and loading in State.DataLoaded / State.Historical but then OnBarUpdate much the bars, so I 'm not getting fixed value on real-time bar, but where the OnBarUpdate is. See the pic for more information. Thanks in advance.
​
Tags: None
-
Hello, thanks for writing in. The indicator would need to loop back on previous bars and re-calculate its plot. You can alternatively loop back to prior bars in your host indicator and pass new parameters to the indicator on each bar. You can loop through all the bars like this:
Code:for(int i = CurrentBar; i > 0; i--) { Print(Close[i]); }
- Likes 1
-
Didn't knew I can fill Plots backwords... It works! Thanks. Here is it :
But, is it possible this method to reduce platform performance, it will redo all bars on every tick if I update OnTick or OnPriceChange?Code:namespace NinjaTrader.NinjaScript.Indicators { public class LoopBackTest : Indicator { private ADX _adx; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "LoopBackTest"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.Red, 3), PlotStyle.Line, "_loopValue"); } else if (State == State.Configure) { } else if (State == State.Historical) { _adx = ADX(14); } } double real_time_adx; protected override void OnBarUpdate() { // doing hithing until we reach recent bar if ( CurrentBar == Count-1) { //getting the value we need real_time_adx = _adx[0]; // back loop to fill Plot with values for(int i = CurrentBar; i>0; i--) { _loopValue[i] = High[i] + real_time_adx; } } } [Browsable(false)] [XmlIgnore] public Series<double> _loopValue { get { return Values[0]; } } } }
Comment
-
I thing this way is better :
Code:double real_time_adx; [B]bool isFirstRun = true;[/B] protected override void OnBarUpdate() { // doing nothing until we reach recent bar if ( CurrentBar == Count-1 && isFirstRun ) { //getting the value we need real_time_adx = _adx[0]; // back loop to fill Plot with values for(int i = CurrentBar; i>0; i--) { _loopValue[i] = High[i] + real_time_adx; } [B]isFirstRun = false;[/B] } // then moving on OnBarUpdate - real-time if(State == State.Realtime) _loopValue[0] = High[0] + real_time_adx; }​
Comment
-
Thanks Chris, yes I tried this method, and it works for a limited number of cases. Haven't got time yet, but I'll try to use a Dispatcher at the first run and first to get the value of external indicator at the recent bar, then normally to go over all bars. I hope this will be better, I'll post the result later
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
630 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 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
565 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment