Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
This is what I am using in an EA that uses MA line as a trailing stop.
I will not offer any explanations, I think you can work it out.
//this goes inside start
TrailingAlls(TrailStart, SMA1);
void TrailingAlls(int start, double currvalue)
{
int profit;
double stoptrade;
double stopcal;
// if(stop==0) return;
int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
{
if(OrderType()==OP_BUY)
{
profit=NormalizeDouble((Bid-OrderOpenPrice())/Point,0);
if(profit<start)
continue;
stoptrade=OrderStopLoss();
// stopcal=Bid-(stop*Point);
stopcal=NormalizeDouble(currvalue, Digits);
if(stoptrade==0||(stoptrade!=0&&stopcal>stoptrade))
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Blue);
}//Long
if(OrderType()==OP_SELL)
{
profit=NormalizeDouble((OrderOpenPrice()-Ask)/Point,0);
if(profit<start)
continue;
stoptrade=OrderStopLoss();
// stopcal=Ask+(stop*Point);
stopcal=NormalizeDouble(currvalue, Digits);
if(stoptrade==0||(stoptrade!=0&&stopcal<stoptrade))
OrderModify(OrderTicket(),OrderOpenPrice(),stopcal,OrderTakeProfit(),0,Red);
}//Shrt
}
}//for
}
Maji:
Thanks, Would you please writer in MQ program, so we will have no problem to use it?
Thanks again.
Maji:
Thanks, Would you please writer in MQ program, so we will have no problem to use it?
Thanks again.Sorry,
I am not that conversant in MQL.
Maji