as in instead of me calculating the slope between Plot[0] and Plot[10] and manually putting the value for each candle in between, it will connect them automatically
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to connect Plot values between empty values
Collapse
X
-
How to connect Plot values between empty values
Hello, I am trying to do a zig zag like Plot, where most candles have no value, but some do, and as such connect the points that do have value
as in instead of me calculating the slope between Plot[0] and Plot[10] and manually putting the value for each candle in between, it will connect them automaticallyTags: None
-
SOLVED: double.IsNaN();
Okay thank you very much. one more question, why can't I compare my plot to a double.NaN
if I do PlotMe[5] == double.NaN I get false, even tho it was set to double.NaN
but if I compare != High which gets assigned if a pivot point is found, it works
also thank you very much for the extremely fast replies, I am coming from Pine/MQL/TOS to Ninja and might have a few more questions in time, is it okay if I just post them on this post here?Code:protected override void OnBarUpdate() { if(CurrentBar >= 5) { PlotMe[5] = pivothigh(High,5,5); if(PlotMe[5] != High[5]) PlotMe.Reset(5); // works if(PlotMe[5] == double.NaN) PlotMe.Reset(5); // doesn't work } } protected double pivothigh(ISeries<double> c_array,int c_left, int c_right) { if(CurrentBar < c_left+c_right) return double.NaN; double c_high = c_array[c_right]; double c_max = c_array[0]; for(int o = 0; o <= 0+(c_left+c_right); o++) c_max = Math.Max(c_max,c_array[o]); return (c_max==c_high? c_high : double.NaN); }Last edited by LuxSpuzy; 02-09-2023, 03:13 PM.
Comment
-
Hello LuxSpuzy,
In this case I would suggest making the following syntax:
into:Code:PlotMe[5] = pivothigh(High,5,5);
Then make your method like the following. You can either set a value or don't set a value, do not set double.NaN.Code:pivothigh(High,5,5);
Code:private void pivothigh(ISeries<double> c_array,int c_left, int c_right) { if(CurrentBar < c_left+c_right) return; double c_high = c_array[c_right]; double c_max = c_array[0]; for(int o = 0; o <= 0+(c_left+c_right); o++) c_max = Math.Max(c_max,c_array[o]); if(c_max==c_high) PlotMe[5] = c_high; }
That lets you use the existing IsValidDataPointAt method on the series.
https://ninjatrader.com/support/help...validdatapoint
Also keep in mind checking if two doubles are equal or not equal will fail in most cases. You should use math instead to check if there is a difference: https://ninjatrader.com/support/help...arithmetic.htmPlotMe[5] != High[5]
For unrelated questions you can post as many new threads as you like.Last edited by NinjaTrader_Jesse; 02-09-2023, 03:17 PM.
Comment
-
in that case the function needs to be modified for each next indicator
I used
instead.Code:double ph = pivothigh(High,5,5); if(!double.IsNaN(ph)) PlotMe[5] = ph;
Thank you for the comparing doubles tip!! much appreciated.
one more question related to OnRender, can I dynamically set the color of the render then?
makes the whole line RedCode:Plots[0].Brush = (CurrentBar % 2 == 0) ? Brushes.Lime : Brushes.Red;
does nothingCode:PlotBrushes[0][0] = (CurrentBar % 2 == 0) ? Brushes.Lime : Brushes.Red;
I see inside OnRender this function
but I can't use Brush here, and BrushDX is read onlyCode:RenderTarget.DrawGeometry(g, Plots[0].BrushDX, Plots[0].Width, Plots[0].StrokeStyle);
EDIT: Okay I've noticed OnRender is called differently and I can't change the color inside OnBarUpdate, but still is it possible for the line to be colored dynamically between points, so 1 connection is red, and the other is greenLast edited by LuxSpuzy; 02-09-2023, 03:48 PM.
Comment
-
Hello LuxSpuzy,
You would generally use anything with a BarsAgo in OnBarUpdate, those items cant be used from OnRender because [0] BarsAgo is irrelevant there. OnRender only knows about the current bars that are visible by using the FromIndex and ToIndex properties, that gives direct bar indexes.
BarsAgo are a number of bars from now in processing in relation to OnBarUpdate. For example on bar 10 a BarsAgo of 5 means you get data from bar 5. In OnRender you get data based on indexes, if we assume you are looking at bars 1 through 10 the index of bar 5 would be 4, indexing starts at 0 and goes left to right.
When you use Brush in OnRender you need to convert them to a BrushDX object. You an use the ToDxBrush() method on any Brush object. https://ninjatrader.com/support/help...BrushResources
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
646 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
367 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
107 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
569 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