Trailing Stop with Commission

 

Hi,

I have a problem,

my broker use commissions, when I use in my EA trail stop it close the trade without profit finaly because it from Open price to close price standpoint its ok  but than

the commission is not included and the net trade is loss.

how can I tell the EA only if net pips is more than X pips start trail,

 

thanks

Roi 

 
Don't start the trailing stop until it is x pips in profit the x being the amount of pips for the TS plus an allowance in pips that will cover the commission.
 

so you mean, I'll check (for BUY order for example)  if  OrderProfit() > = 0 and (OrderOpenPrice - TrailStop) > Bid 

than if yes , I'll  start trail?

 
roi_:

so you mean, I'll check (for BUY order for example)  if  OrderProfit() > = 0 and (OrderOpenPrice - TrailStop) > Bid 

than if yes , I'll  start trail?

No, for a buy

if(OrderClosePrice()-OrderOpenPrice()>=TrailStop+allowance for commisison) 

 

OrderClosePrice() can't be because it still running, you mean Bid?

 

OrderClosePrice()  is the most recent price for the order, for a Buy, it will be Bid, for a Sell, Ask.

Same as Close[0], The 0 bar has not closed yet, but Close[0] holds the most recent price. 

 

Hi @roi,

Were you able to add commission on your TrailStop? Even I've been trying this on my code on both buy & Sell but never got success, below is my code snip,


void TrailingPositions() {
  double pBid, pAsk, pp;

  pp = MarketInfo(OrderSymbol(), MODE_POINT);
  if (OrderType()==OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber()==EAMagicNumber) {
    pBid = MarketInfo(OrderSymbol(), MODE_BID);
    if (!ProfitTrailing || (pBid-OrderOpenPrice())>TrailingStop*pp) {
      if (OrderStopLoss()<pBid-(TrailingStop+TrailingStep-1)*pp) {
      if((OrderClosePrice()-OrderOpenPrice())>=((TrailingStop*pp)+OrderCommission()))     //sathya mfd#3
        ModifyStopLoss(pBid-TrailingStop*pp);
        return;
      }
    }
  }
  if (OrderType()==OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber()==EAMagicNumber) {
    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
    if (!ProfitTrailing || OrderOpenPrice()-pAsk>TrailingStop*pp) {
      if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {  
   if((OrderClosePrice()+ OrderOpenPrice())>=((TrailingStop*pp)+OrderCommission()))     //sathya mfd#3
        ModifyStopLoss(pAsk+TrailingStop*pp);
        return;
      }
    }
  }
}

void ModifyStopLoss(double ldStopLoss) {
  bool fm;
  fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
 
}


-Sathya-

 



Hi Sathy

wow, necro-bump.

Let us know if this works for you, see below for what I use to work out what the commission will total up to;

Cheers, 

Chris

// I use an input into my EA
input double m_commission_per_minlot = 0.035; // Commission per minimum lot size

// in my example; 3.5c to open a position plus 3.5c to close it (per min lot size), so the total commission will end up being 7c per round trip.  


// then, in your function, you can check like this;

double pos_vol_lots = PositionGetDouble(POSITION_VOLUME);
double min_vol_lots = SymbolInfoDouble( _Symbol , SYMBOL_VOLUME_MIN );
double pos_commission = MathRound(200.0 * m_commission_per_minlot * pos_vol_lots/min_vol_lots )/100.0;
 

Try this

double commission=((OrderCommission()*-1)/(OrderLots()*MarketInfo(Symbol(),MODE_TICKVALUE)))*Point;

commission variable equals how many pips you would need to cover the amount of commission for a given lot size.

if((OrderClosePrice()+ OrderOpenPrice())>=((TrailingStop*pp)+commission)) 
 
plewright:


Hi Sathy

wow, necro-bump.

Let us know if this works for you, see below for what I use to work out what the commission will total up to;

Cheers, 

Chris

Thanks @plewright, I'll try this
 
Chad Magruder:

Try this

commission variable equals how many pips you would need to cover the amount of commission for a given lot size.

Thanks Chad,

Modified as below, but seems no change on TS placement,  1.  TS placed exactly on the OrderOpenPrice() 2, If OrderLots= 0.03 also TS --> 0.07(equal pips) only


double commission;        
   commission=((OrderCommission()*-1)/(OrderLots()*MarketInfo(Symbol(),MODE_TICKVALUE)))*Point; 


 if (OrderType()==OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber()==EAMagicNumber) {
    pAsk = MarketInfo(OrderSymbol(), MODE_ASK);
    if (!ProfitTrailing || OrderOpenPrice()-pAsk>TrailingStop*pp) {
      if (OrderStopLoss()>pAsk+(TrailingStop+TrailingStep-1)*pp || OrderStopLoss()==0) {  
  if((OrderClosePrice()+ OrderOpenPrice())>=((TrailingStop*pp)+commission))   
       ModifyStopLoss(pAsk+TrailingStop*pp);
        return;
      }
    }
  }
}



-Sathya-