Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ScalperAlert Indicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ScalperAlert Indicator

    can someone help me debug the following 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.DrawingTools;
    #endregion

    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class ScalperAlert : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "ScalperAlert";
    Calculate = Calculate.OnBarClose;
    IsOverlay = false;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {


    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class ScalperAlert : Indicator
    {
    private int n = 8;
    private bool showLines = true;
    private bool soundAlerts = true;

    private double highest;
    private double lowest;
    private int firstBar;
    private double a;
    private double b;
    private double al;
    private double bl;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "Scalper Alert";
    Description = "My custom indicator.";
    IsOverlay = true;
    PaintPriceMarkers = false;
    BarsRequiredToPlot = 10;
    }
    else if (State == State.Configure)
    {
    AddPlot(Brushes.Green, "HL");
    AddPlot(Brushes.Red, "LL");
    }
    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < n)
    return;

    if (CurrentBar == n)
    firstBar = CurrentBar;

    highest = High[HighestBar(High, n)];
    lowest = Low[LowestBar(Low, n)];

    a = double.NaN;
    b = double.NaN;

    if (firstBar > n && High[0] == highest)
    a = High[0];

    if (firstBar > n && Low[0] == lowest)
    b = Low[0];

    al = double.IsNaN(a) ? al[1] : a;
    bl = double.IsNaN(b) ? bl[1] : b;

    HL[0] = Math.Round(al, 2);
    HL.SetPaintingStrategy(PaintingStrategy.Horizontal Line);
    HL.SetHiding(!showLines);

    LL[0] = Math.Round(bl, 2);
    LL.SetPaintingStrategy(PaintingStrategy.Horizontal Line);
    LL.SetHiding(!showLines);

    if (soundAlerts && !IsInDrawdown && !IsLastBarOnChart())
    {
    if (!double.IsNaN(a))
    Alert("ScalperAlert Alert", Priority.High, "New high detected: " + a.ToString(), @"alert.wav", 100, Brushes.Green, Brushes.White);
    else if (!double.IsNaN(b))
    Alert("ScalperAlert Alert", Priority.High, "New low detected: " + b.ToString(), @"alert.wav", 100, Brushes.Red, Brushes.White);
    }
    }

    region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name = "N", Order = 1, GroupName = "Parameters")]
    public int N
    { get { return n; } set { n = Math.Max(1, value); } }

    [NinjaScriptProperty]
    [Display(Name = "Show Lines", Order = 2, GroupName =

    }
    }
    }

    region NinjaScript generated code. Neither change nor remove.

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private ScalperAlert[] cacheScalperAlert;
    public ScalperAlert ScalperAlert(int n)
    {
    return ScalperAlert(Input, n);
    }

    public ScalperAlert ScalperAlert(ISeries<double> input, int n)
    {
    if (cacheScalperAlert != null)
    for (int idx = 0; idx < cacheScalperAlert.Length; idx++)
    if (cacheScalperAlert[idx] != null && cacheScalperAlert[idx].N == n && cacheScalperAlert[idx].EqualsInput(input))
    return cacheScalperAlert[idx];
    return CacheIndicator<ScalperAlert>(new ScalperAlert(){ N = n }, input, ref cacheScalperAlert);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.ScalperAlert ScalperAlert(int n)
    {
    return indicator.ScalperAlert(Input, n);
    }

    public Indicators.ScalperAlert ScalperAlert(ISeries<double> input , int n)
    {
    return indicator.ScalperAlert(input, n);
    }
    }
    }

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.ScalperAlert ScalperAlert(int n)
    {
    return indicator.ScalperAlert(Input, n);
    }

    public Indicators.ScalperAlert ScalperAlert(ISeries<double> input , int n)
    {
    return indicator.ScalperAlert(input, n);
    }
    }
    }

    #endregion

    #2
    can anyone help with this de-bug?

    Comment


      #3
      This doesn't look like it would even compile, and has bits of several different indicators in there. Is this ChatGPT?
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Hello mdingram28,

        Thanks for your post.

        From our experience at this time, ChatGpt is not quite adequate to generate valid compilable NinjaScripts that function as the user has intentioned. We often find that the generated code will call non-existent properties and methods, use improper classes or inheritance, and may have incorrect logic. We highly encourage that you create a new NinjaScript yourself using the NinjaScript Editor, and use the code generated by ChatGpt as more as suggestions and guide when coding the script yourself, than using the actual code generated.

        While It would not be within our support model to correct these scripts at user request, we would be happy to provide insight for any direct specific inquiries you may have if you would like to create this script yourself. Our support is able to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services.

        Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​
        <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
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        368 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        571 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X