How to add a stoploss to an already open MT4 position

Hello Everyone,

This is my first question on the forum and I thank you all in advance for the help. I am new to robots and may be asking some ignorant questions, so please bear with me.

IF THE ANSWER TO THE QUESTION BELOW IS DIFFERENT FOR MT 4 vs MT 5, PLEASE SPECIFY.

I have a robot that is mostly completed. The robot identifies a resistance level and then puts a BUY STOP, let’s say 1 pip (i.e. 10 micropips) above the resistance. As a result it has a BUY STOP at a specific level that is sitting there statically. In our example, say we have a BUY STOP at 1.20550 for 1 lot. The price crosses this critical level and we open the position -so we bought 1 lot at some price which we cannot be sure of until the order gets executed. We of course cannot assume that we will buy at exactly 1.20550. The price might have moved up rapidly or gapped up and we may have bought at a different price. Assume we bought at 1.20560

What we want the robot to do is to go in and enter some kind of instruction to automatically close the order 20 micropips below the level at which the order was actually executed, so at 1.20540 in this case. However, we do not want to rely on the robot to execute the closing trade when the critical level happens. instead, we want to send the STOP order to the broker so that if the computer crashes, or our internet crashes*** we can still close the position. I.e. can the robot go in and send such an instruction to the broker to “CLOSE STOP” (just made that up now) in case price comes down to 1.20540 or lower.

Again, I know this is an ignorant question, but right now, I cannot even manually make that adjustment in MT 4. Once the demo version of my robot opens the order at 1.20560, I right click on the order and hit “Close Order” and then when I enter a pending SELL STOP, that is entered as a separate order. What I mean is that when the stop level is hit, the program opens a separate sell order as opposed to closing the existing open buy order. I do not think this is related to the robot, because it happens even when I try to enter the SELL STOP order after stopping auto trading and removing the robot.

*** I know the few issues I mentioned above can be eliminated by running the robot off a server. That is a separate issue, which I will please ask about a little later. I do not want to throw in two things simultaneously and make it more complex than it needs to be.

Once again thank you very much

Elliot

Yes, you can program your robot so that it will modify just opened order (MT4) or position (MT5) with a stoploss level calculated from the actual open price. Use OrderModify function in MT4 and equivalent request action in MT5.

To add/move stops and target in mt4 you have the function OrderModify().

But in mt5 it is different as you use for everything OrderSend().

You need to use a stoploss and not a stop order.

Stop orders can only work is you describe above on a MT5 netting account. With MT4 or MT5 hedging account, a stop order will always result in a new trade/position and will not interact with any already existing trade/position.

Hi hmarkos2,

Do I understand you correctly in that in MT4, the robot cannot go in and modify an already open order in such fashion that the broker receives the instruction to close the open order if the price hits certain levels?

Elliot

You misunderstood. Of course you can, but using a stoploss (or takeprofit) attached to the order, and not a stop order (pending). That’s how MT4 (or MT5 hedging account) is working, please check the documentation.

And as Stanislav and Carl said you need to use OrderModify() for that.

Robots CAN do this. See short directions above.

Got you; thanks a lot.

Can you use OrderModify() in order to take an order (which is still open) that was originally placed with a specific stop loss level and modify it such that the order now uses a trailing stop instead?

Yes, that is how trailing-stops are implemented in MT4 EA’s, buy calling OrderModify() for each change in trailing stop price. In MT5 it is different depending on whether it is a “netting” account or a “hedging” account.

However, this line of questioning is not really getting you anywhere! You should instead consider your true intentions. So either, you are planning to make your own EAs or you are going to hire someone to do it for you.

If you plan to hire someone, then just know that the EA can do it and it will be up to the coder to properly implement it depending on whether it is MT4, MT5 Hedging or MT5 Netting.
If you plan to code yourself, then it is best that your first learn the basics of MQL and then slowly build up your knowledge to the point that you will be able to answer these questions yourself. However, this will not take hours or days, especially if you have never coded before. It will take you months to reach an average amateur level and years to reach professional coding levels.

All clear now.

Never intended to code myself and have someone do it for me at the moment. We had some kind of miscommunication with the programmer though and there is some language barrier too. So i wanted to clarify just this part.

Many, many thanks…