I was experiencing some issues with strategies that I'd created, which backtested fine but then when I ran them live, the stop losses didn't seem to be setting correctly, which resulted in losing trades greater than the stop loss I'd set. I found some other forum posts from people with similar issues and the advice to enter all logic into OnExecutionUpdate().
Could someone please confirm that this is the correct way to set a currency stop loss, which will work correctly when running a strategy through a Rithmic account?
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order.OrderState == OrderState.Filled)
{
if (execution.Order.Name == "Long")
{
SetStopLoss("Long", CalculationMode.Currency, StopLoss, false);
SetProfitTarget("Long", CalculationMode.Currency, ProfitTarget);
}
else if (execution.Order.Name == "Short")
{
SetStopLoss("Short", CalculationMode.Currency, StopLoss, false);
SetProfitTarget("Short", CalculationMode.Currency, ProfitTarget);
}
}
}

Comment