I'm having two strange problems with a strategy I'm backtesting.
1. I'm having trouble with ToTime. I have the following code:
// Long trades
if (condition
&& ToTime(Time[0])> ToTime(08,30,00)
&& ToTime(Time[0])< ToTime(14,0,000)
&& more conditions
);
{
EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "LongEntry1");
SetStopLoss("LongEntry1", CalculationMode.Price, Low[0]-1*TickSize, false);
SetProfitTarget("LongEntry1", CalculationMode.Price, (High[0]-Low[0])*1.55+High[0]);
StopMoveTriggerLong = (High[0]-Low[0])*0.9+High[0];
//Move stop loss to half risk if 1.9x target is achieved
if (High[0] >= StopMoveTriggerLong
&& Position.MarketPosition == MarketPosition.Long)
{
SetStopLoss("LongEntry1", CalculationMode.Price,Position.AvgPrice,false);
}
//Reset StopMoveTrigger if no position
if (Position.MarketPosition == MarketPosition.Flat);
{
StopMoveTriggerLong = 0;
}
2. As you can see, this strategy is only meant to take long trades. However, when I run a backtest and pull up the performance report, on the summary tab it shows that the strategy is taking short trades, and on the Trades tab it shows that the strategy is the strategy is treating some of my stop loss orders as short trades (see attached screenshot). I'm guessing when I dynamically move the stop loss up when a price target is hit, it's not cancelling the original stop loss (see code above)? How do I fix this?
Thanks in advance.

Comment