//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class mcadbbemastrategy : Strategy
{
private EMA EMA1;
private ImpMACDBB ImpMACDBB1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "mcadbbemastrategy";
Calculate = Calculate.OnEachTick;
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;
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, 4);
ImpMACDBB1 = ImpMACDBB(Close, 12, 26, 6, 10, 1, Brushes.Green, Brushes.Red);
EMA1.Plots[0].Brush = Brushes.Goldenrod;
ImpMACDBB1.Plots[0].Brush = Brushes.Black;
ImpMACDBB1.Plots[1].Brush = Brushes.Yellow;
ImpMACDBB1.Plots[2].Brush = Brushes.Aqua;
ImpMACDBB1.Plots[3].Brush = Brushes.Aqua;
ImpMACDBB1.Plots[4].Brush = Brushes.Aqua;
AddChartIndicator(EMA1);
AddChartIndicator(ImpMACDBB1);
SetProfitTarget("", CalculationMode.Ticks, 32);
SetStopLoss("", CalculationMode.Ticks, 8, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
if (CrossAbove(EMA1, ImpMACDBB1.Lower, 1) && CrossAbove(ImpMACDBB1.MACDPlot, EMA1, 1))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
if (CrossBelow(EMA1, ImpMACDBB1.Upper, 1) && CrossBelow(ImpMACDBB1.MACDPlot, EMA1, 1))
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
}
}
}
Comment