Switch from a long to short position or vice versa

 

Hello,

It happens that I need to switch from a long to a short trading position or the other way around. I'd like to know if there is a simple click that allows me to do so, rather than manually reversing my trading position.

Thank you. Very much appreciated. 

 
zeno1:

Hello,

It happens that I need to switch from a long to a short trading position or the other way around. I'd like to know if there is a simple click that allows me to do so, rather than manually reversing my trading position.

Thank you. Very much appreciated. 

 

 


A script should do the job.
 
kronin:

A script should do the job.


Is such a script - or other function - available for this 'standard' change? It is used frequently in trading.

Thank you. 

 
zeno1:


Is such a script - or other function - available for this 'standard' change? It is used frequently in trading.

Thank you. 


Look in the codebase, there are many scripts doing similar things. E.g. these scripts are close to what you're looking for. You can adjust/combine it for your needs (and don't forget to make it ready for 5-digit brokers).
 

Thank you kronin. I have the version from https://www.mql5.com/en/code/8058

However, having added the mq4 format to scripts in navigator and then compiled, I cannot execute it? I ran a test with an order and it would not reverse when I would drag the script over the chart? Any idea why that is?

Looking in the journal of terminal, I see that the script is loaded successfully and immediately is removed. But the removal makes sense to me, since the script should only be executed once?

Thank you for your advice. 

 
zeno1:

Thank you kronin. I have the version from https://www.mql5.com/en/code/8058

However, having added the mq4 format to scripts in navigator and then compiled, I cannot execute it? I ran a test with an order and it would not reverse when I would drag the script over the chart? Any idea why that is?

Looking in the journal of terminal, I see that the script is loaded successfully and immediately is removed. But the removal makes sense to me, since the script should only be executed once?

Thank you for your advice. 


Your suggested script works for me. You draged it to the chart with the symbol with your open order? And you have ticked the Allow live trading box?


And yes, it gets removed after execution.

 

I did not have that box checked under options/expert advisors.

I tested and it works. Thanks so much. 

Reason: