Hi everyone!
I'm building an EA that will automate hedge based on the scenario. There are two buttons in my EA for buy and sell, if i press buy, then 2 trades will open 1 is market order and 2nd is pending order i.e. sell stop. No if market moves against my buy order and hit the sell stops and opens it then i want to open an other trade that on the exact position my 1st buy order is placed.
But the issue i'm facing is that i'm not able sort out how to do this. My first two orders get executed successfully i.e. market execution and sell stop but i only want to open 3rd buy order if and only if my sell stop executes. But i'm not able to do this. or found any solutions regarding this.
I'm pasting my approach below but its not making anything better, its still placing new orders while my sell stop is not being executed. Kindly help me through this.
Hi Tamur Taj,
Hope you are well.
In this situation, first get the last running buy price. Example:
double last_buy_price = 0; if(OrdersTotal() > 0) { for(int i = OrdersTotal()-1; i >= 0 && IsStopped() != true; i--) { bool select = OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(select == true && OrderSymbol() == _Symbol && OrderType() == OP_BUY) { last_buy_price = NormalizeDouble(OrderOpenPrice(),_Digits); break; } } }
After activating your sell stop as sell trade, place a buy stop order with the last_buy_price. you can do the same for sell side.
Hope, this will help you.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone!
I'm building an EA that will automate hedge based on the scenario. There are two buttons in my EA for buy and sell, if i press buy, then 2 trades will open 1 is market order and 2nd is pending order i.e. sell stop. No if market moves against my buy order and hit the sell stops and opens it then i want to open an other trade that on the exact position my 1st buy order is placed.
But the issue i'm facing is that i'm not able sort out how to do this. My first two orders get executed successfully i.e. market execution and sell stop but i only want to open 3rd buy order if and only if my sell stop executes. But i'm not able to do this. or found any solutions regarding this.
I'm pasting my approach below but its not making anything better, its still placing new orders while my sell stop is not being executed. Kindly help me through this.