Close all trades if price is reached
mt4 or mt5?
this close at profit not a predefined price
you can change its code or use in this way
https://www.mql5.com/en/code/10597
- www.mql5.com
this close at profit not a predefined price
you can change its code or use in this way
https://www.mql5.com/en/code/10597
This might work! I have to do some testing, but thank you, it's a good bet.
youre welcome
I use MT5. Hope this code is usefull..
#include <Trade\Trade.mqh> CTrade Trd; input double TargetPrice = 0; //fill with the price target. void OnTick() { double v_price = SymbolInfoDouble(_Symbol,SYMBOL_LAST); if ( v_price == TargetPrice ) { Trd.PositionClose(_Symbol); CancelOrders(); } } void CancelOrders() { CTrade mytrade; int o_total = OrdersTotal(); for(int j=o_total-1; j>=0; j--) { ulong o_ticket = OrderGetTicket(j); string sym = OrderGetString(ORDER_SYMBOL); if( o_ticket!=0 && sym == _Symbol ) { // delete the pending order mytrade.OrderDelete(o_ticket); Print(_Symbol," Pending order ",o_ticket," deleted sucessfully!"); } } }
I use MT5. Hope this code is usefull..
I actually need to close all orders if 1 of 2 prices are reached. Can you add this to the code ?
Hi,
Do you know of any EA that closes all open trades and pending orders if a predetermined price is reached ?
Thanks.