Hi all. I’m working on a simple script for Gold futures. I want to buy at Prior day highs and sell at prior day lows. Sounds like a simple but I can’t seem to get the strategy to run haha. Can someone take a look at what I have so far and help me out please. Thank you guys. Glad to be here!
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class Gold : Strategy
{
private PriorDayOHLC PriorDayOHLC1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Previous Day Break";
Name = "Gold";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 0;
IsFillLimitOnTouch = true;
MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Day;
TraceOrders = true;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 1;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
PriorDayOHLC1 = PriorDayOHLC(Close);
PriorDayOHLC1.Plots[0].Brush = Brushes.SteelBlue;
PriorDayOHLC1.Plots[1].Brush = Brushes.DarkCyan;
PriorDayOHLC1.Plots[2].Brush = Brushes.Crimson;
PriorDayOHLC1.Plots[3].Brush = Brushes.SlateBlue;
AddChartIndicator(PriorDayOHLC1);
SetProfitTarget("", CalculationMode.Ticks, 20);
SetStopLoss("", CalculationMode.Ticks, 50, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (CrossAbove(Close, PriorDayOHLC1.PriorHigh, 1))
{
EnterLongStopLimit(10, 0, 0, "");
}
// Set 2
if (CrossBelow(Close, PriorDayOHLC1.PriorLow, 1))
{
EnterShortStopLimit(10, 0, 0, "");
}
}
}
}