I have this custom made indicator, that is working as needed:
namespace NinjaTrader.NinjaScript.Indicators
{
public class EMAX2Alert : Indicator
{
private EMA ema20;
private EMA ema50;
private EMA ema200;
[Range(1, int.MaxValue), NinjaScriptProperty]
public int EMAPeriod1 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
public int EMAPeriod2 { get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
public int EMAPeriod3 { get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Start Time", GroupName = "Trading Period 1", Order = 0)]
public TimeSpan TradingPeriodStartTime1 { get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "End Time", GroupName = "Trading Period 1", Order = 1)]
public TimeSpan TradingPeriodEndTime1 { get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Start Time", GroupName = "Trading Period 2", Order = 0)]
public TimeSpan TradingPeriodStartTime2 { get; set; }
[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "End Time", GroupName = "Trading Period 2", Order = 1)]
public TimeSpan TradingPeriodEndTime2 { get; set; }
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "EMA X2 Alert";
IsOverlay = true;
EMAPeriod1 = 20;
EMAPeriod2 = 50;
EMAPeriod3 = 200;
TradingPeriodStartTime1 = new TimeSpan(3, 00, 0);
TradingPeriodEndTime1 = new TimeSpan(8, 0, 0);
TradingPeriodStartTime2 = new TimeSpan(12, 00, 0);
TradingPeriodEndTime2 = new TimeSpan(14, 00, 0);
}
ema20 = EMA(EMAPeriod1);
ema50 = EMA(EMAPeriod2);
ema200 = EMA(EMAPeriod3);
}
protected override void OnBarUpdate()
{
if (Time[0].TimeOfDay >= new TimeSpan(3, 00, 0) && Time[0].TimeOfDay <= new TimeSpan(17, 00, 0))
// OVERALL TRADING TIMES with paramter user defined: if (Time[0].TimeOfDay >= StartTime1 && Time[0].TimeOfDay <= EndTime1)
{
if (Time[0].TimeOfDay >= TradingPeriodStartTime1 && Time[0].TimeOfDay <= TradingPeriodEndTime1 ||
Time[0].TimeOfDay >= TradingPeriodStartTime2 && Time[0].TimeOfDay <= TradingPeriodEndTime2)
{
if(CurrentBar == Bars.Count -2 && ((CrossAbove(ema20, ema50, 1) && ema20[0] > ema200[0] && ema50[0] > ema200[0]) ||
(CrossBelow(ema20, ema50, 1) && ema20[0] < ema200[0] && ema50[0] < ema200[0]) ||
(CrossAbove(ema50, ema200, 1) && ema20[0] > ema50[0]) ||
(CrossBelow(ema50, ema200, 1) && ema20[0] < ema50[0])))
{
Print("EMA X2 on: " + Instrument.FullName + " at: " + Time[0]);
Alert("EMA X2", Priority.High, "EMA X2", NinjaTrader.Core.Globals.InstallDir+@"\sounds\AlertX2.wav", 20, Brushes.SpringGreen, Brushes.Black);
System.Windows.Forms.MessageBox.Show("Get ready to make some MONEY! EMAs just did the X2! " + Instrument.FullName + " at " + Time[0].ToString("HH:mm"));
}
}
else if (CurrentBar == Bars.Count -2 && ((CrossAbove(ema20, ema50, 1) && ema20[0] > ema200[0] && ema50[0] > ema200[0]) ||
(CrossBelow(ema20, ema50, 1) && ema20[0] < ema200[0] && ema50[0] < ema200[0]) ||
(CrossAbove(ema50, ema200, 1) && ema20[0] > ema50[0]) ||
(CrossBelow(ema50, ema200, 1) && ema20[0] < ema50[0])))
{
Print("EMA X2 off period: " + Instrument.FullName + " at: " + Time[0]);
Alert("EMA X2 off", Priority.High, "EMA X2 off", NinjaTrader.Core.Globals.InstallDir+@"\sounds\AlertX2off.wav", 20, Brushes.Gainsboro, Brushes.Black);
System.Windows.Forms.MessageBox.Show("EMAs X2 off trading period: " + Instrument.FullName + " at " + Time[0].ToString("HH:mm"));
}
}
}
}
}
Anything else works with no issues.
Hope anyone can help.
Thanks
Peter


Comment