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

Comment