I am back testing using MB trading demo. Th standard trailing stop code will not take into consideration of the commission and order swap.
Anyone had tried successful to have the trailing stop not take losses with negative profit?
typical trailing stop code:
void ShortTrailingStop()
{
int scnt;
int stotal = OrdersTotal();
for(scnt=stotal-1; scnt >= 0; scnt--)
{
OrderSelect(scnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_SELL) // short position is opened
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+(Point*TrailingStop))) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Point*TrailingStop),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}
Anyone had tried successful to have the trailing stop not take losses with negative profit?
typical trailing stop code:
void ShortTrailingStop()
{
int scnt;
int stotal = OrdersTotal();
for(scnt=stotal-1; scnt >= 0; scnt--)
{
OrderSelect(scnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_SELL) // short position is opened
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+(Point*TrailingStop))) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+(Point*TrailingStop),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}