要使用聊天,请登录。

MQL4 Stoploss

Feb 10, 2016 at 12:59
647浏览
4 Replies
Yurin92
forex_trader_294488
会员从Dec 28, 2015开始   8帖子
Feb 10, 2016 at 12:59
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.
会员从Nov 21, 2011开始   1718帖子
Feb 10, 2016 at 13:46
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.
forex_trader_25447
会员从Dec 21, 2010开始   131帖子
Feb 10, 2016 at 15:46
I think, hi wanted to realize Trailing Stop at distance (ATR-0.0005)
会员从Mar 02, 2010开始   97帖子
Feb 13, 2016 at 09:56
you should separate your conditions from ordermodify command!
ixbone@
会员从Apr 20, 2010开始   814帖子
Feb 14, 2016 at 07:47
You need add the StopLoss Condition.

double stoplossBuy;
if(stoplossBuy < Bid- Close[1]- atr ) stoplossBuy = Bid- - Close[1]- atr ;

// This ensure your stopLossBuy will only move up
Information is Gold when come to organised.
登录 / 注册 to comment
You must be connected to Myfxbook in order to leave a comment
*商业用途和垃圾邮件将不被容忍,并可能导致账户终止。
提示:发布图片/YouTube网址会自动嵌入到您的帖子中!
提示:键入@符号,自动完成参与此讨论的用户名。