Help! - How to make trailing stop loss take into consideration of order commission and order swap? New comment Chee Chua 2009.10.17 14:51 I get negative profit when running trailing stop loss because the code does not account for the commission and swap, I tried the followings which don't work need help, thanks! void LongTrailingStop() { int lcnt; int ltotal = OrdersTotal(); double BuyProfit; 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)) { BuyProfit = (OrderProfit() + OrderCommission() + OrderSwap()); OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop+BuyProfit),OrderTakeProfit(),0,Green); return(0); } } } } } } } Help! How to modify the standard trailing stop code for dealing desk to be used for ecn? Help - need help debugging my function to count total lots bought (total lots in long position) cant get the stop loss to work New comment
I get negative profit when running trailing stop loss because the code does not account for the commission and swap,
I tried the followings which don't work
need help, thanks!
void LongTrailingStop()
{
int lcnt;
int ltotal = OrdersTotal();
double BuyProfit;
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))
{
BuyProfit = (OrderProfit() + OrderCommission() + OrderSwap());
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-(Point*TrailingStop+BuyProfit),OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
}
}
}