What's new

Trailing stop loss working only on Buy orders not on Sell orders

doctor786

New Member
Hello everyone,

Greetings for the day!

First of all, I would like to thank you for the wonderful website. I really appreciate the hard work of the team and members.

I have made an EA from a website by entering my settings but when am testing the EA, The Trailing stop loss works only on Buy orders, and it is not working or activating on Sell orders in spite of price movements.

Kindly help me in correcting it.

________________________________________________________________________________________________________________________________________________________________________________________________________



int posTotal=PositionsTotal();
for(int posIndex=posTotal-1; posIndex>=0; posIndex--)
{
ulong ticket=PositionGetTicket(posIndex);
if(PositionSelectByTicket(ticket) && PositionGetInteger(POSITION_MAGIC)==MagicNumber)
{
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
{
if(TrailingStop>0)
{
if(SymbolInfoDouble(_Symbol,SYMBOL_BID)-PositionGetDouble(POSITION_PRICE_OPEN)>MyPoint*TrailingStop)
{
if(PositionGetDouble(POSITION_SL)<SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop)
{
trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_BID)-MyPoint*TrailingStop,PositionGetDouble(POSITION_TP));
return;
}
}
}
}

if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
{
if(TrailingStop>0)
{
if(PositionGetDouble(POSITION_PRICE_OPEN)-SymbolInfoDouble(_Symbol,SYMBOL_ASK)>MyPoint*TrailingStop)
{
if(PositionGetDouble(POSITION_SL)>SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop)
{
trade.PositionModify(ticket,SymbolInfoDouble(_Symbol,SYMBOL_ASK)+MyPoint*TrailingStop,PositionGetDouble(POSITION_TP));
return;
}
}
}
}
}
}
return;
}
 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Similar threads

Replies
0
Views
362K
Replies
0
Views
181

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)

Top