namespace NinjaTrader.NinjaScript.Strategies
{
public class ZZZ : Strategy
{
private RSI RSI1;
private MACD MACD1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "ZZZ";
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)
{
RSI1 = RSI(2,1);
MACD1 = MACD(12,26,9);
}
}
protected override void OnBarUpdate()
{
// Set 1
if ((CrossAbove(RSI1.Default, 10, 0))
&& (MACD1.Diff[0] > 0))
{
EnterLong(10, "");
}
// Set 2
if (CrossAbove(RSI1.Default, 80, 0))
{
ExitLong(10, "", "");
}
}
}
}
Comment