I decide to make my own indicator so I went to GhatGPT for some help.
The indicator it gave me is this one:
using System; using System.ComponentModel; using System.Windows.Media; using System.Windows.Shapes; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.NinjaScript.Indicators; namespace NinjaTrader.NinjaScript.Indicators { [Description("Displays a horizontal line at the price of the instrument at 9:30 am")] public class OpeningPriceIndicator : Indicator { private double openingPrice; private System.Windows.Shapes.Line line; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = "Displays a horizontal line at the price of the instrument at 9:30 am"; Name = "OpeningPriceIndicator"; IsOverlay = true; line = new System.Windows.Shapes.Line { Stroke = Brushes.White, StrokeThickness = 2, StrokeDashArray = new DoubleCollection(new double[] { 4, 3 }), }; AddChartObject(line); } } protected override void OnBarUpdate() { if (Bars == null || CurrentBar < 1) return; if (Time[0].TimeOfDay == new TimeSpan(9, 30, 0)) { openingPrice = Open[0]; line.Y1 = openingPrice; line.Y2 = openingPrice; } } private void AddChartObject(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor chartAnchor, object chartObject) { chartControl.Dispatcher.InvokeAsync(() => chartControl.AddChartObject(chartPanel, chartScale, chartAnchor, chartObject)); } } }
When I try to compile it, the following error appears: "The type or namespace name 'ChartAnchor' could not be found"
ChatGPT suggest the following:
"I apologize for the continued issues. In this case, I believe the issue may be related to the version of NinjaTrader you're using.
In some versions of NinjaTrader, ChartAnchor is defined in the NinjaTrader.Gui.Chart namespace. In other versions, ChartAnchor is defined in the NinjaTrader.NinjaScript namespace.
To work around this issue, you can try using the ChartAnchor enum directly without the namespace. This should work for any version of NinjaTrader.
Please try replacing the AddChartObject method with the following:
csharpCopy code
private void AddChartObject(ChartControl chartControl, ChartPanel chartPanel, ChartScale chartScale, ChartAnchor chartAnchor, object chartObject) { chartControl.Dispatcher.InvokeAsync(() => chartControl.AddChartObject(chartPanel, chartScale, (int)chartAnchor, chartObject)); }
This should resolve the issue and allow you to compile the indicator. If you're still having issues, please let me know the specific error message you're seeing, and I'll do my best to help you resolve it."
I did it but the problem remains. Do you have any solution for this code error?. Or a way to solve the strategy issue? I just need to buy below 9:30 price and sell above it.
Thanks!
Comment