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