Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to calculate the value between two data points
Collapse
X
-
How to calculate the value between two data points
I am used to using pinescript and we have a function called ta.change, which gives us the value of a piece of data between the current and past candle. For example if the ema is at 56, and on the previous candle it was 50, that means the ta.change is 6. I'm having a hardtime finding the similar function in the ninjascript language reference. I'm trying to make an indicator that measures the change of the LinRegSlope indicator. Thnaks in advance! -
Hello AdithBlack,
Thanks for your post.
The barsAgo value you use when calling LinRegSlope(int period)[int barsAgo] will determine the LinRegSlope() value you are accessing.
To get the current value of the LinRegSlope(), you would use a barsAgo value of 0. 0 would be referring to the current bar. A value of 1 would be used the get the previous bar's LinRegSlope() value and so on.
For example:
See this help guide page for more information about using LinRegSlope(): https://ninjatrader.com/support/help...sion_slope.htmCode://Get the current bar LinRegSlope value. LinRegSlope(20)[0]; //Get the previous bar LinRegSlope value LinRegSlope(20)[1]; //Get the LinRegSlope value 2 bar ago LinRegSlope(20)[2];
Please let me know if you have further questions about this.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
-
Awesome, how do I now make it plot the value so I can use it on a chart and in a strategy? I'm struggling to get it right, I want it to plot the value for "greenval".
AddPlot(Brushes.Goldenrod, "Slopeline");
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
val = LinRegSlope(Close, Length);
}
}
protected override void OnBarUpdate()
{
double greenval = val[0] - val[1];
}
Comment
-
Hello AdithBlack,
Thanks for your note.
You must assign the value to the plot by using Value[0] = X, where 'X' is the value you are assigning to the plot.
For example, the code might look something like this to assign greenval to the plot.
Value[0] = greenval;.
See this help guide page for more information about AddPlot and assigning values to a plot: https://ninjatrader.com/support/help...t8/addplot.htm
Let me know if I may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 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
567 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