Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Why my newly created indictor can not be plotted
Collapse
X
-
Why my newly created indictor can not be plotted
I created a new indicator ( series) and tested in the output window, the output seems fine. I try to use AddPlot to plot the indicator ( series) in a separate panel, and used isOverlay=false; DrawOnPricePandel=false; but it didn't show up in the new panel. Not sure what is the issue.Tags: None
-
Hello plant,
Thanks for your post.
Do you see any error messages in the Log tab of the Control Center? If so, what exactly does the error report?
Did you assign a value to the plot after calling the AddPlot() method?
The AddPlot() method adds a plot to the script but a value must be assigned to the plot for the value to be plotted on the chart.
See this help guide page for more information about AddPlot() and sample code: https://ninjatrader.com/support/help...t8/addplot.htm<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
-
Ok.
Just fyi, this would go so much faster
if you could post the code.
Is that possible?
At the very least:
Show us every bit of code in your
indicator that has anything do with
this newly added plot.
This is probably a simple error, one that
is easily spotted just by eyeballing the
code ... otherwise it feels like a game
of 20 questions ...
Comment
-
Can you take a look for me? 2 print shows valid number in output window and there is no error in the log or output window
namespace NinjaTrader.NinjaScript.Indicators
{
public class KST : Indicator
{
private Series<double> KSTline;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "KST";
Name = "KST";
IsSuspendedWhileInactive = true;
IsOverlay = false;
DrawOnPricePanel = false;
//variable settings
AddLine(Brushes.DarkGray,0, Custom.Resource.NinjaScriptIndicatorZeroLine);
AddPlot(Brushes.DarkCyan,"KSTline");
}
else if (State == State.DataLoaded)
{
KSTline = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
Print(string.Format("{0}:{1}", Time[0], Close[0]));
if (CurrentBar < 30) return;
else
{
double smaroc1 = SMA(ROC(Close, (int) roclen1), (int) smalen1 )[0] ;
double smaroc2 = SMA(ROC(Close, (int) roclen2), (int) smalen2) [0] ;
double smaroc3 = SMA(ROC(Close, (int) roclen3), (int) smalen3) [0] ;
double smaroc4 = SMA(ROC(Close, (int) roclen4), (int) smalen4) [0] ;
double kst0 = smaroc1+ 2 * smaroc2 + 3 * smaroc3 + 4 * smaroc4;
Print(string.Format("{0}:{1}", Time[0], kst0));
KSTline[0]=kst0;
}
}
}
}
- Likes 1
Comment
-
Helo plant,
Thanks for your notes.
You do not need to call 'private Series<double> KSTline' in your script. Instead, a public Series<double> property should be defined in the script for the plot.
First, remove the line of code 'private Series<double> KSTline' from the script.
Then, add a public Series<double> property to the script outside of OnBarUpdate() for the plot. The code might look something like this:
[Browsable(false)]
[XmlIgnore]
public Series<double> KSTline
{
get { return Values[0]; }
}
An example of this could be seen in the second section of sample code on the AddPlot() help guide page.
See this help guide page for information about AddPlot(): https://ninjatrader.com/support/help...t8/addplot.htm
<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>
- Likes 1
Comment
-
Thank you very much! You helped me solved this problem! But I have a new question. I want to add a new signal line ( moving average of KSTline), so I added following code , it seems the signal line got the wrong value, do you have any idea? If KST has value between -1~1, the moving average of KST should have similar value, not sure why it gets -75.
double sig= SMA(KSTline, siglen)[0];
Sigline[0]=sig;
Values[1][0]=sig;
kst 10/11/2023 11:59:00 AM:-0.36262000579914
sig 10/11/2023 11:59:00 AM:-75.8771961107832
kst 10/11/2023 12:00:00 PM:-0.207204063574082
sig 10/11/2023 12:00:00 PM:-75.6732613965559
kst 10/11/2023 12:01:00 PM:-0.135115152615088
sig 10/11/2023 12:01:00 PM:-75.4900125926121
kst 10/11/2023 12:02:00 PM:-0.125399990589574
sig 10/11/2023 12:02:00 PM:-75.3298395534933
kst 10/11/2023 12:03:00 PM:-0.133352117482076
sig 10/11/2023 12:03:00 PM:-75.1976715225567
kst 10/11/2023 12:04:00 PM:-0.181693379376382
sig 10/11/2023 12:04:00 PM:-75.0863534988641
Comment
-
Hello plant,
Thanks for your notes.
To clarify, is Sigline another plot that you added to the script or is this a custom Series<T> variable in your script?
How exactly are you defining the prints in your script?
To see how your logic is evaluating, add prints one line above where you are assigning 'SMA(KSTline, siglen)[0]' to 'sig' to see how that value is evaluating. Also, add prints to the script that prints out Sigline[0] and Values[1][0] to see how those objects are evaluating.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121<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
-
Sigline is a new series I created by taking KSTline moving average, I added the print before and after I assign sig
Print(string.Format("kst before {0}:{1}", Time[0], kst0));
double sig= SMA(KSTline, siglen)[0];
Print(string.Format("kst after {0}:{1}", Time[0], kst0));
Print(string.Format("sig after {0}:{1}", Time[0], sig));
I only assign siglen=3 so the sig should =( kst before+ kst before+ kst before) /3= (0.46+0.45+0.47)/3=0.46, but I got -128 for sig, I'm not sure whether the formula I assign sig (double sig= SMA(KSTline, siglen)[0]) is not correct?
Results:
kst before 10/11/2023 12:30:00 PM:0.455694016429037
kst after 10/11/2023 12:30:00 PM:0.455694016429037
sig after 10/11/2023 12:30:00 PM:-128.8918128485
kst before 10/11/2023 12:30:15 PM:0.448976700890162
kst after 10/11/2023 12:30:15 PM:0.448976700890162
sig after 10/11/2023 12:30:15 PM:-129.034848856991
kst before 10/11/2023 12:30:30 PM:0.46674704506999
kst after 10/11/2023 12:30:30 PM:0.46674704506999
sig after 10/11/2023 12:30:30 PM:-129.189275255012
Comment
-
I also added print for Signline[0] and Value[1][0], but those two were not be print out in the output window:
Print(string.Format("kst before {0}:{1}", Time[0], kst0));
double sig= SMA(KSTline, siglen)[0];
Print(string.Format("kst after {0}:{1}", Time[0], kst0));
Print(string.Format("sig after {0}:{1}", Time[0], sig));
Print(string.Format("sigline after {0}:{1}", Time[0], Sigline[0]));
Print(string.Format("value after {0}:{1}", Time[0], Values[1][0]));
Results:
kst before 10/11/2023 12:47:00 PM:-0.452587064548669
kst after 10/11/2023 12:47:00 PM:-0.452587064548669
sig after 10/11/2023 12:47:00 PM:-136.267911151647
kst before 10/11/2023 12:47:15 PM:-0.513852898357123
kst after 10/11/2023 12:47:15 PM:-0.513852898357123
sig after 10/11/2023 12:47:15 PM:-136.160272619143
kst before 10/11/2023 12:47:30 PM:-0.5480490156279
kst after 10/11/2023 12:47:30 PM:-0.5480490156279
sig after 10/11/2023 12:47:30 PM:-136.031270336015
Comment
-
Hello plant,
Thanks for your notes.
Yes, that would be the correct way to have the SMA() calculate values using the Series KSTline.
Here is a forum thread demonstrating this concept. The forum thread is for NinjaTrader 7 but the concept would be the same in NinjaTrader 8.
https://forum.ninjatrader.com/forum/...00#post1039800
One line above where you assign a value to 'double sig' you should print out the value being assigned to see how it is evaluating.
For example:
Print("SMA(KSTline, siglen)[0] is " + SMA(KSTline, siglen)[0]);
double sig= SMA(KSTline, siglen)[0];
Print("sig is: " + sig);
Further, you would need to make sure to print out Signline[0] and Values[1][0] after a value has been assigned to them.Last edited by NinjaTrader_BrandonH; 10-11-2023, 10:55 AM.<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
-
I feel kst0 is one datapoint, but does SMA(KSTline, siglen) add all the data points together in KSTline and do the moving average? otherwise how the number will be so big? Signline[0] and Values[1][0] I do not worry that so much because it after sig be assigned, so if sig is not correct, those two will not be correct either.
My code and results are below:
double kst0 = smaroc1+ 2 * smaroc2 + 3 * smaroc3 + 4 * smaroc4;
Print("kst0 " + kst0);
Print("SMA(KSTline, siglen)[0] is " + SMA(KSTline, siglen)[0]);
double sig= SMA(KSTline, siglen)[0];
Print("sig is: " + sig);
Results:
kst0 0.0423471294863548
SMA(KSTline, siglen)[0] is -116.069221531375
sig is: -116.069221531375
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
53 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
44 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment