Edit Your Comment
MQL4 Stoploss
forex_trader_294488
Anggota Sejak Dec 28, 2015
8 pos
Feb 10, 2016 at 12:59
Anggota Sejak Dec 28, 2015
8 pos
Hello everyone. I've coded this piece here:
for(int i=0;i<OrdersTotal();i++)
{
bool select = OrderSelect(i,SELECT_BY_POS,MODE_TRADES); //Iteration through every trade
if(OrderMagicNumber()==1 && OrderSymbol()==Symbol()) //if Trade==BUY
{
if(Close[1]>OrderStopLoss()+atr && Close[1]>OrderOpenPrice()+atr) //is the price already greater than the opening price+ATR, and than the stoploss+ATR?
{
bool order = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()+atr-0.0005,5),0,0,clrAquamarine);
if(!order){Alert(GetLastError());}
}
else
{
return;
}
}
}
But the stoploss keeps moving on every tick. I know it is due to the '-0.0005', but I would like to have that added 'margin'. How could I manage it to stop from moving on every tick, without having to remove this -0.0005 margin?
thank you very much in advance.
for(int i=0;i<OrdersTotal();i++)
{
bool select = OrderSelect(i,SELECT_BY_POS,MODE_TRADES); //Iteration through every trade
if(OrderMagicNumber()==1 && OrderSymbol()==Symbol()) //if Trade==BUY
{
if(Close[1]>OrderStopLoss()+atr && Close[1]>OrderOpenPrice()+atr) //is the price already greater than the opening price+ATR, and than the stoploss+ATR?
{
bool order = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderStopLoss()+atr-0.0005,5),0,0,clrAquamarine);
if(!order){Alert(GetLastError());}
}
else
{
return;
}
}
}
But the stoploss keeps moving on every tick. I know it is due to the '-0.0005', but I would like to have that added 'margin'. How could I manage it to stop from moving on every tick, without having to remove this -0.0005 margin?
thank you very much in advance.
Anggota Sejak Nov 21, 2011
1718 pos
Feb 10, 2016 at 13:46
Anggota Sejak Nov 21, 2011
1718 pos
If you wanna place SL when you open orders, then you simply need to adjust SL at this moment using OpenOrder function.
If you wanna place SL at a particular event then you have to add the following condition... Does my SL is null, if so, apply your code else nothing.
So it should do it only once.
If you wanna place SL at a particular event then you have to add the following condition... Does my SL is null, if so, apply your code else nothing.
So it should do it only once.
Anggota Sejak Apr 20, 2010
814 pos
*Penggunaan komersial dan spam tidak akan ditolerir, dan dapat mengakibatkan penonaktifkan akun.
Tip: Memposting gamba /url youtube akan secara otomatis menyematkannya di postingan Anda!
Tip: Ketik tanda @ untuk melengkapi secara otomatis nama pengguna yang ikut serta dalam diskusi ini.