Help! How to modify the standard trailing stop code for dealing desk to be used for ecn?

 

How to modify the standard trailing stop code for dealing desk to be used for ecn?

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);
}
}
}

}
}
}
}


On DD MT4, I will not end up with negative profit from trailing stop (please see picture - those are the trailing stop losses generated from an ECN MT4).

How do I compensate for the commission? I assume that is how i get the negative profit from. You will not get that on DD MT4.

Is there a standard trailing stop of ecn?

like the one for dd?

Thanks!

 
Why don't u just use a larger TrailingStop value to compensate?
 
gordon:
Why don't u just use a larger TrailingStop value to compensate?


won't work, there will still be some negative profit.
 
Oh, I see. Your current code modifies stoploss and takeprofit based on original stoploss and takeprofit which are not shown in this code. You should change the original stoploss and takeprofit calculations to take into account the commission and then this code should work.
 

I had set my trailing stop at 25

You are using a 5 digit broker so your stop loss was 2.5 pips (25 points) and (on IBFX) the minimum 3.0 pips

You must either adjust all pip values for 5 digit points or make the EA adjust:

//++++ These are adjusted for 5 digit brokers.
double	pips2points,	// slippage  3 pips	   3=points	   30=points
	pips2dbl;	// Stoploss 15 pips	   0.0015	   0.00150
int	Digits.pips;	// DoubleToStr(dbl/pips2dbl, Digits.pips)
int init() {
	if (Digits == 3 || Digits == 5) {	// Adjust for five (5) digit brokers.
		pips2dbl	= Point*10;	pips2points = 10;	Digits.pips = 1;
	} else {pips2dbl	= Point;	pips2points =  1;	Digits.pips = 0;
	}
//...
	// A pending order price can be no closer to the current price, than this
	// amount.	On IBFX it's equal to 30 (3.0 pips.) A TP or SL, can be no
	// closer to the order price (open, limit, or stop) or closing price (filled
	// order) than this amount.
	minGap.stops	= MarketInfo( Symbol(), MODE_STOPLEVEL )*Point;
	order.SL	= MathMin( Bid  - TrailingStop * pips2dbl, Bid - minGap.stops);
Reason: