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*Tra ilingStop))) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpen Price(),Ask+(Point*TrailingStop),Or derTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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*Tra ilingStop))) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpen Price(),Ask+(Point*TrailingStop),Or derTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}