This is like the standard trailing stop code that is everywhere.
Works for broker that does not charge commission. When I try testing on an ECN broker, some of the stop losses ended with negative profit because of the commissions. how to edit the code to taking into consideration of the commission? I had set my trailing stop at 25.
Thanks!
void LongTrailingStop()
{
int lcnt;
int ltotal = OrdersTotal();
for(lcnt=ltotal-1; lcnt >= 0; lcnt--)
{
OrderSelect(lcnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>(Point*TrailingStop))
{
if(OrderStopLoss()<Bid-(Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop),OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
}
}
}
http://i89.photobucket.com/albums/k2...ingstopecn.jpg
Works for broker that does not charge commission. When I try testing on an ECN broker, some of the stop losses ended with negative profit because of the commissions. how to edit the code to taking into consideration of the commission? I had set my trailing stop at 25.
Thanks!
void LongTrailingStop()
{
int lcnt;
int ltotal = OrdersTotal();
for(lcnt=ltotal-1; lcnt >= 0; lcnt--)
{
OrderSelect(lcnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY) // long position is opened
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>(Point*TrailingStop))
{
if(OrderStopLoss()<Bid-(Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop),OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
}
}
}
http://i89.photobucket.com/albums/k2...ingstopecn.jpg