You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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);
}
}
}
}
}
}
}