I haven't been able to run this using the Playback Connection to test it out but would like to have it ironed out by Monday morning. Thanks for looking and any advice you can give.
public class EMACrossOverParabolicStop : Strategy
{
private EMA EMA1;
private SMA SMA1;
private Order stopLossOrder = null;
private Order entryOrder = null;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "EMACrossOverParabolicStop";
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.IgnoreAllErrors; //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)
{
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, 10);
SMA1 = SMA(Close, 30);
EMA1.Plots[0].Brush = Brushes.SeaShell;
SMA1.Plots[0].Brush = Brushes.Yellow;
AddChartIndicator(EMA1);
AddChartIndicator(SMA1);
SetParabolicStop(CalculationMode.Ticks, 30);
}
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice,
OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
// Assign stopLossOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
// This is more reliable than assigning Order objects in OnBarUpdate,
// as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
if (order.Name == "myStopLoss" && orderState == OrderState.Filled)
stopLossOrder = order;
if (stopLossOrder != null && stopLossOrder == order)
{
// Rejection handling
if (order.OrderState == OrderState.Rejected)
{
ExitLong(); // Stop loss order was rejected !!!!
ExitShort(); // Do something about it here
}
}
}