CloseSymbol_byProfit
without error handling maybe 10 lines of code.
try to read the documentation, the book on this site and the scripts in your metatrader.
i don't think you gonna finde here somebody which "works" for you for free. but i and many others will help you for shure with your code when we see you are trying to understand how it could be done.
Choose a piece of code from the codebase or the forum posts which loops (down) through the open orders and use this as your condition to close each order. if (OrderSymbol() == "EURUSD" &&OrderProfit() > 0) CB
I'm using these codes:
for(i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
//if(OrderSelect(i,SELECT_BY_POS))
{
type=OrderType();
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol() == "EURUSD" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="GBPUSD" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="AUDUSD" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="EURGBP" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="USDJPY" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="USDCAD" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="USDCHF" && OrderProfit()>SymbolProfit)
... but I have impression that it is not working..
I'm maybe stating the obvious here, but you are missing the instruction to close. https://docs.mql4.com/trading/OrderClose
You also need to watch when hard coding a symbol name as some brokers put additional letters on like m for micro or sb for spread bet.
Would be worth calling and printing GetLastError() to help track down any problems. https://docs.mql4.com/check/GetLastError
hth
V
I'm maybe stating the obvious here, but you are missing the instruction to close. https://docs.mql4.com/trading/OrderClose
You also need to watch when hard coding a symbol name as some brokers put additional letters on like m for micro or sb for spread bet.
Would be worth calling and printing GetLastError() to help track down any problems. https://docs.mql4.com/check/GetLastError
hth
V
Hi,
U was right. I'm using Man Financial Canada
and they added mfu:
Now is working. Thanks.
type=OrderType();
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="EURUSDmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="GBPUSDmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="AUDUSDmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="EURGBPmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="USDJPYmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="USDCADmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="USDCHFmfu" && OrderProfit()>SymbolProfit)
if ((type==OP_BUY || type==OP_SELL) && OrderSymbol()=="EURJPYmfu" && OrderProfit()>SymbolProfit)
Hello All,
I'm looking for an EA that will close only one Symbol e.g. (EURUSD) if it is in profit.
I'm trading 5 pairs, every with 3-5 max.trades.
Thnak.
FXMan77