The code of the strategy for the alerts upon bar color change is as follows:
namespace NinjaTrader.NinjaScript.Strategies
{
public class Dynobarsalerts : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Dynobarsalerts";
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)
{
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((Close[0] > Open[0])
&& (Close[1] < Open[1]))
{
PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert1.wav");
SendMail(@"blanked [email protected]", @"+Instrument.Fullname", "");
}
// Set 2
if ((Close[0] < Open[0])
&& (Close[1] > Open[1]))
{
SendMail(@"blanked [email protected]", @"+Instrument.Fullname", "");
PlaySound(@"C:\Program Files (x86)\NinjaTrader 8\sounds\Alert1.wav");
}
}
}
}
Comment