Can someone please provide some suggestions for a solution?
Here's what I have
namespace NinjaTrader.NinjaScript.Strategies
{
public class xFastSMAoverUnder : Strategy
{
private bool BullishHourly;
private bool BearishHourly;
private SMA SMA3;
private SMA SMA4;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Buy when price crosses about the fast SMA (7 or 8). Sell visvers";
Name = "xFastSMAoverUnder";
Calculate = Calculate.OnPriceChange;
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;
PositionQty = 1;
FastSMA = 8;
SlowSMA = 20;
BullishHourly = false;
BearishHourly = false;
}
else if (State == State.Configure)
{
AddDataSeries("NQ DEC24", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
AddDataSeries("NQ DEC24", Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);
}
else if (State == State.DataLoaded)
{
SMA1 = SMA(Close, Convert.ToInt32(FastSMA));
SMA2 = SMA(Close, Convert.ToInt32(FastSMA));
EMA1 = EMA(Close, 200);
SMA3 = SMA(Closes[2], Convert.ToInt32(FastSMA));
SMA4 = SMA(Close, Convert.ToInt32(SlowSMA));
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 10
|| CurrentBars[1] < 0)
return;
if (IsFirstTickOfBar == true)
{
}
if (CrossAbove(SMA3, SMA4, 1))
{ // Bullish
Draw.VerticalLine(this, "Hourly Cross" + CurrentBar, 0, Brushes.Lime, DashStyleHelper.Dash, 2);
Print("Bar Close: " + Close[0] + " At Time: " + Time[0]);
BullishHourly = true;
BearishHourly = false;
}
}
}
}​
Comment