i need it because i am working with many pairs and using hedge , using EA more easy for my trading styleWhy do you need an EA if you have a script? What would EA do? Just wait until an order with a matching comment appears and close it?
if i want to use script i have to watch the market while if i use EA i do not need to watch marketI still don't understand how such an EA would function. Could you please explain in details?
//----if i want to use script i have to watch the market while if i use EA i do not need to watch market
void CloseMagic(int MagicNumber,string comment) { RefreshRates(); int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); if(OrderMagicNumber() != MagicNumber) continue; if(OrderComment() != comment) continue; RefreshRates(); int type = OrderType(); bool result = false; switch(type) { case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); break; case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } }
The problem is that if you set up an EA to close all orders with a given comment, the affected order will be closed immediately upon opening. So, the EA will be just preventing any trades with a given comment from actually staying for more than 1 second. I don't think that's what you need.if i want to use script i have to watch the market while if i use EA i do not need to watch market
you are right but i will write the profit which i want to close all orders has the same commentThe problem is that if you set up an EA to close all orders with a given comment, the affected order will be closed immediately upon opening. So, the EA will be just preventing any trades with a given comment from actually staying for more than 1 second. I don't think that's what you need.
Hello//----
hey almo.... that part we get.....
but you must explain in far greater detail.... what triggers the order closure function....such as, is it a dollar value target, hour of the day, indicator crossing a signal line, is a total account profit or loss level..... are you under fifo rules.... is deleting pending orders involved.... and many more type things must be clearly laid out...... very clearly.....
otherwise we are just guessing..... guessing and coding will not end well......h
//-----
MQL4:void CloseMagic(int MagicNumber,string comment) { RefreshRates(); int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); if(OrderMagicNumber() != MagicNumber) continue; if(OrderComment() != comment) continue; RefreshRates(); int type = OrderType(); bool result = false; switch(type) { case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red ); break; case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red ); } if(result == false) { Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() ); Sleep(3000); } } }
HelloNow it's clear. Actually, I am planning to release an EA that will do something like this and even more soon.
https://www.earnforex.com/metatrader-expert-advisors/Account-Protector/Hello
did you work on this EA ?
if yes where i can find it pleas
Thank you