Script is a program for a single execution of an action. Unlike Expert Advisors, scripts do not handle any event except for trigger, initialization and deinitialization. A script code must contain the OnStart handler function.

- www.mql5.com
but after close order it dose not run again
i want it run immediatly automaatic after close order.
thank you in advance for you helping
- When you post code please use the SRC button! Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum - Of course not, it's a script, not an EA. Why would you always buy after the order closes? What about when you aren't there to set a SL?
- Help you with what? You haven't stated a problem.
You have only four choices:- Search for it,
- learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
- Beg at Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum or Need help with coding - General - MQL5 programming forum or Free MQL4 To MQL5 Converter - General - MQL5 programming forum or Requests & Ideas (MQL5 only!),
- or pay (Freelance) someone to code it.
No free help
urgent help.
Hi, this is so simple script, it's just buy order immediatly after run, but after close order it dose not run again
i want it run immediatly automaatic after close order. thank you in advance for you helping
this is the script:
input double lots = 0.01;
input int magic = 434341;
int OnInit()
{
//---
int ticket = OrderSend(Symbol(),OP_BUY,0.01, Ask,3,0,0, "EA Comment",255,0,CLR_NONE);
//---
return(0);
}
Try to use this code...
//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticket=-1; int MagicNumber=123456; int CountOrders=0; for(int i=0; i>OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderMagicNumber()==MagicNumber) CountOrders++; } } //--- if(CountOrders==0) ticket = OrderSend(Symbol(),OP_BUY,0.01, Ask,3,0,0, "EA Comment",MagicNumber,0,CLR_NONE); } //+------------------------------------------------------------------+
Thank you for your reply, i'm a newbie here, sorry, i want you help me to fix my code,
my concept is i run 2 EA, i open multiple currency pair, the first EA is close equity amount when make profit (i already have this one),the second one what i want is when is closed all equity amount i want the EA buy or sell immediatly as the ask or bid price(depend on my setting)
thank you in advand for your help or any suggestion
input double lots = 0.01; input int magic = 434341; int OnInit() { //--- int ticket = OrderSend(Symbol(),OP_BUY,0.01, Ask,3,0,0, "EA Comment",255,0,CLR_NONE); //--- return(0); }
Here you go...
input int MagicNumber = 123456; input double LotSize = 0.01; input bool OpenBuy = true; input bool OpenSell = false; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticket=-1; int CountBuyOrders=0; int CountSellOrders=0; //--- for(int i = 0; i > OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderMagicNumber() == MagicNumber) { if(OrderType() == OP_BUY) CountBuyOrders++; if(OrderType() == OP_SELL) CountSellOrders++; } } } //--- if((CountBuyOrders == 0) && (OpenBuy == true)) ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 3, 0, 0, "EA Comment", MagicNumber, 0, clrBlue); if((CountSellOrders == 0) && (OpenSell == true)) ticket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 3, 0, 0, "EA Comment", MagicNumber, 0, clrRed); } //+------------------------------------------------------------------+
Here you go...
Thank you so much Nikolaos Pantzosfor your help, but when i run your script, it orders buy too many, as i request i just want 1 order then after it closed then it orders again, thank in advand :)
There is a mistype in the EA, please try this :
input int MagicNumber = 123456; input double LotSize = 0.01; input bool OpenBuy = true; input bool OpenSell = false; //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { int ticket=-1; int CountBuyOrders=0; int CountSellOrders=0; //--- for(int i = 0; i < OrdersTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderMagicNumber() == MagicNumber) { if(OrderType() == OP_BUY) CountBuyOrders++; if(OrderType() == OP_SELL) CountSellOrders++; } } } //--- if((CountBuyOrders == 0) && (OpenBuy == true)) ticket = OrderSend(Symbol(), OP_BUY, LotSize, Ask, 3, 0, 0, "EA Comment", MagicNumber, 0, clrBlue); if((CountSellOrders == 0) && (OpenSell == true)) ticket = OrderSend(Symbol(), OP_SELL, LotSize, Bid, 3, 0, 0, "EA Comment", MagicNumber, 0, clrRed); } //+------------------------------------------------------------------+
There is a mistype in the EA, please try this :
Correct!!
i<OrdersTotal() not i>... :)
There is a mistype in the EA, please try this :
Thank you so much

- 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, this is so simple script, it's just buy order immediatly after run, but after close order it dose not run again
i want it run immediatly automaatic after close order. thank you in advance for you helping
this is the script:
input double lots = 0.01;
input int magic = 434341;
int OnInit()
{
//---
int ticket = OrderSend(Symbol(),OP_BUY,0.01, Ask,3,0,0, "EA Comment",255,0,CLR_NONE);
//---
return(0);
}