Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 974

 
Hali:
Good day to all! I hope very much for your help. I think the solution to my question will be interesting to many traders. When the market is very active, the Expert Advisor often sets the Stop and Take levels incorrectly. Is it possible to write code that would force the EA to check if the close levels are set correctly after the order is opened, and if they are different from those originally set, then the EA will set the stop and take levels correctly. For example, I want a trade to be opened with equal stop and take levels of 50 units, which has been set in the EA. But because of the strong oscillations a trade opens with stop loss at 47 and take profit at 53 which does not suit me. Please help me to write a code that will make the close levels equal to 50 after the deal is opened. I would be very grateful and I am sure I am not the only one.

I'm sure there is one.

In addition to OrderSend(), there is OrderModify() in the same group of functions"Trading functions". Besides, there are account types where you cannot open orders with nonzero stop and take positions simultaneously. This means that we first open an order and then place a stop and a take order using the OrderModify() function, and the take and stop levels should be calculated from the price OrderOpenPrice().

I hope this answer is clear enough.

 
The answer is clear, but unfortunately I don't know how to do it(. Can you show me a code example where this is implemented. I would be very grateful to you.
 
Hali:
The answer is clear, but unfortunately I don't know how to do it(. Can you show me a code example where this is implemented. I would be very grateful to you.

Well, there are examples in the documentation

void OnStart()
  {
   int TrailingStop=50;
//--- модифицирует цену Stop Loss ордера на покупку №12345
   if(TrailingStop>0)
     {
      OrderSelect(12345,SELECT_BY_TICKET);
      if(Bid-OrderOpenPrice()>_Point*TrailingStop)
        {
         if(OrderStopLoss()<Bid-_Point*TrailingStop)
           {
            bool res=OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-_Point*TrailingStop,_Digits),OrderTakeProfit(),0,Blue);
            if(!res)
               Print("Ошибка модификации ордера. Код ошибки=",GetLastError());
            else
               Print("Цена Stop Loss ордера успешно модифицирована.");
           }
        }
     }
  }
 

Question removed.

 
Alligator:

Question removed.

Thanks for the answers. Unfortunately, I'm quite new at this. I have an EA (written not without the help of members of this forum) I would like to supplement it with a modification of the take and stop, as described in the posts above, but I have no way of doing it. If it's not too much trouble, someone please help me with this task.
 

I can't see the "search by site" button on mql4.com now.

On mql5.com this button is still there.

Is it a coincidence or should we switch to mql5 completely?

 
Hali:
Thanks for the answers. Unfortunately, I'm a complete novice at this. I've got an EA (written with some help from the members of this forum). I would like to modify it by modifying the take and stop, as described in the above posts, but I can't do it. If it's not too much trouble, someone please help me with this task.

Write it yourself! If you lose on the martin, you'll blame yourself! Nobody wants to be blamed! Or go to Freelance, they'll do anything professionally and inexpensively!

 
BAS581:

I can't see the "search by site" button on mql4.com now.

On mql5.com this button is still there.

Is it a coincidence or should we switch to mql5 completely?

There is a search! Hover your cursor over the magnifying glass and write what you need!
 
borilunad:
There is a search! Hover your cursor over the magnifier and write what you need!

Thank you for your help. If you know there is a solution, it's easier to find it. )))

In this case, the solution was this: in FireFox, zoom out the page, and then the magnifying glass appears.

It's just not available at normal scale.

 
BAS581:

Thank you for your help. If you know there is a solution, it's easier to find it. )))

In this case, the solution was this: in FireFox, zoom out the page, and then the magnifier appears.

It's just not available at normal zoom.

Change your browser to a standard one!
Reason: