The post suggests using stop orders instead so you can set your own signal names, I unfortunately have not been able to figure out how to implement that suggestion. I will paste my code governing order handling below so you can see what I am trying to do. I can set specific stop losses to specific entries, but I cannot name those stop losses as mentioned above.
In order for this to work I would need to find some kind of way to name my stops. That way, the program knows that the previous order status was a filled stop out from a long position and won't be allowed to go long again until the OnOrderUpdate() designation changes.
If you could show me how to make and implement the stop orders with custom names into this code I would greatly appreciate it. My hope is that they would replace
SetStopLoss(@"Buy", CalculationMode.Currency, 250, false); and SetStopLoss(@"Short", CalculationMode.Currency, 250, false); while maintaining their functionality. Thank you very much.
public class SmoothZLEMAandZLTEMAcrossover : Strategy
{
private bool DoNotReEnterLong = false;
private bool DoNotReEnterShort = false;
.
.
.
else if (State == State.Configure)
{
//Stop Loss (These are what I am trying to rename so they match the designation in OnOrderUpdate)
SetStopLoss(@"Buy", CalculationMode.Currency, 250, false);
SetStopLoss(@"Short", CalculationMode.Currency, 250, false);
}
.
.
.
protected override void OnBarUpdate()
{
.
.
.
//Order Logic
if (CurrentBars[0] < BarsRequiredToTrade) return;
//Long Entry
if ((SmoothZLTEMA[0] > SmoothZLEMA[0]) && (SmoothZLTEMA[0] > SmoothZLTEMA[1]) && (DoNotReEnterLong == false))
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"Buy");
}
//Long Exit
if ((SmoothZLTEMA[0] < SmoothZLEMA[0]))
{
ExitLong(Convert.ToInt32(DefaultQuantity), @"Sell", @"Buy");
}
//Short Entry
if ((SmoothZLTEMA[0] < SmoothZLEMA[0]) && (SmoothZLTEMA[0] < SmoothZLTEMA[1]) && (DoNotReEnterShort == false))
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"Short");
}
//Short Exit
if ((SmoothZLTEMA[0] > SmoothZLEMA[0]))
{
ExitShort(Convert.ToInt32(DefaultQuantity), @"Cover", @"Short");
}
}
protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
int quantity, int filled, double averageFillPrice,
Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
{
if(order.OrderState == OrderState.Filled && order.Name == "Stop loss long")
DoNotReEnterLong = true;
if(order.OrderState == OrderState.Filled && order.Name == "Stop loss short")
DoNotReEnterShort = true;
}
Comment