Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
indicator doesnt plot in data window but plots in strategy builder
Collapse
X
-
Hello tkaboris,
Thank you for your post.
Which data window are you referring to? If you add this indicator to a strategy in strategy builder with the "Plot on chart" box checked, then enable the strategy on a chart, do you see the plots on the chart? If not, do you see any errors on the Log tab of the Control Center?
I look forward to your reply.
-
Hello tkaboris,
Thank you for your reply.
I was not providing information to you about plotting values from the indicator vs. in a strategy. I am asking questions to clarify your inquiry. What is the "data window" that you are referring to? Can you please send me a screenshot of the data window?- To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
- Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
I look forward to your reply.
Comment
-
For an indicator's plots to show in the data box, the indicator must have DisplayInDataBox set to true in either State.SetDefaults or State.Configure:Originally posted by tkaboris View PostHi I was just referring to regular data box window
Please let us know if we may be of further assistance.
Comment
-
Hi i used strategy builder to include indicator to the strategy and it did, but when I enable it i get error
Indicator 'SupDemZones': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object. Can you please help?
Thank you
Code:#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class MyCustomStrategy10 : Strategy { private SupDemZones SupDemZones1; private SMA SMA1; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "MyCustomStrategy10"; Calculate = Calculate.OnBarClose; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { SupDemZones1 = SupDemZones(Close, true, barTypes.Minute, 15, Brushes.YellowGreen, Brushes.Tomato, 0.3f, 0.15f, 0.1f, 0.05f, 1, false, false, true, @"1.2 | Dec. 2016"); // SMA1 = SMA(Close, 14); SupDemZones1.Plots[0].Brush = Brushes.YellowGreen; SupDemZones1.Plots[1].Brush = Brushes.Tomato; AddChartIndicator(SupDemZones1); } } protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; // Set 1 // if (CrossBelow(SupDemZones1, SMA1, 1)) // { // } } } }
Comment
-
Hello tkaboris,
Thank you for your reply.
Is SupDemZones an indicator you developed or was it imported from a third party? The error "Object reference not set to an instance of an object" could have a few potential causes. It is a very common error that happens when an object value is referenced, but that value is null. We have a tip page in the help guide about checking for null references here:
It sounds like the error needs to be addressed within the indicator script itself and is not something you are doing in the Strategy Builder. If you developed the indicator, we could guide you through the debugging process of adding prints and figuring out what object is resulting in the null reference. Otherwise, if it was imported from a third party, you may need to reach out to the developer to let them know about the error and/or see if they have an updated version of the script that has logic in place to prevent this error.
Please let me know if I may be of further assistance.
Comment
-
Hello tkaboris,
Thank you for your reply.
Although the indicator compiles, that alone does not prevent it from getting errors when running the script or calling the indicator from another script, such as a strategy.
Do you see errors if you try to add just the indicator (not the strategy) to a chart? I am curious about the results if you try to add the indicator with the same settings you tried in your strategy:
SupDemZones(Close, true, barTypes.Minute, 15, Brushes.YellowGreen, Brushes.Tomato, 0.3f, 0.15f, 0.1f, 0.05f, 1, false, false, true, @"1.2 | Dec. 2016")
I look forward to your reply with the results.
Comment
-
Hello tkaboris,
Thank you for your reply.
I suggest adding prints to debug your script. This will help you to narrow down which part of your strategy is causing the error. There are suggestions for debugging your scripts here:
Since you are working with the Strategy Builder, you could even add prints from the strategy builder as demonstrated in the following post and video:The prints can help you to understand the values being used, such as the floats, as well as which line might be causing errors. The last print to show before the error can help to narrow down what line of code is causing the errors.
I would be glad to test the strategy on my end and see if it also results in errors. Then, I can get a better idea of what might be the next step in the debugging process. Please export the strategy by going to Control Center > Tools > Export > NinjaScript AddOn. Select your strategy and the indicator. Once the export is successful, you may attach the .zip file that is generated to your reply here in the forum.
I look forward to assisting you further.
Comment
-
Hi ,
please find an attached strategy and indicator
I appriciate your helpAttached Files
Comment
-
Hello tkaboris,
Thank you for your reply.
When I tried to apply SupDemZones to a chart with the default settings, I got the same error you were getting with the strategy:- Indicator 'SupDemZones': Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.
Since the error is coming from OnStateChange, I added prints throughout OnStateChange with the line number. What are the results if you add these prints to the script then try to add it to a chart?
What is the last print you see in the NinjaScript Output window prior to getting an error? This will help to determine what line is causing the error.Code:protected override void OnStateChange() { if(State == State.SetDefaults) { Description = @""; Print("95"); Name = "SupDemZonesWithPrints"; Calculate = Calculate.OnBarClose; IsOverlay = true; IsAutoScale = false; DrawOnPricePanel = true; PaintPriceMarkers = false; IsSuspendedWhileInactive = false; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; IsSuspendedWhileInactive = true; Print("105"); AddPlot(Brushes.YellowGreen, "zl"); AddPlot(Brushes.Tomato, "zr"); useMTF = false; barType = barTypes.Minute; barPeriod = 30; demandColor = Brushes.YellowGreen; supplyColor = Brushes.Tomato; Print("115"); activeLineOpacity = 0.30f; activeAreaOpacity = 0.15f; brokenLineOpacity = 0.10f; brokenAreaOpacity = 0.05f; Print("120"); lineWidth = 1; extendZones = false; hideActiveZones = false; hideBrokenZones = true; indicatorVersion = "1.2 | Dec. 2016"; Print("126"); } else if(State == State.Configure) { if(useMTF) { barIndex = 1; AddDataSeries((BarsPeriodType)barType, barPeriod); } Print("136"); ZOrder = ChartBars.ZOrder - 7; Print("138"); if(!initOne) { menuSepa = new Separator(); menuItem = new MenuItem { Header = "Zones" }; menuItemActive = new MenuItem { Header = (hideActiveZones) ? "Show Active Zones" : "Hide Active Zones" }; menuItemBroken = new MenuItem { Header = (hideBrokenZones) ? "Show Broken Zones" : "Hide Broken Zones" }; Print("145"); menuItemActive.Click += toggleActiveZones; menuItemBroken.Click += toggleBrokenZones; Print("148"); menuItem.Items.Add(menuItemActive); menuItem.Items.Add(menuItemBroken); Print("151"); initOne = true; } }
I look forward to your reply.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
607 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
353 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
560 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
561 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment