Please help my EA script

 

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);

  }


 

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.

https://www.mql5.com/en/docs
MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
MQL5 Reference - How to use algorithmic/automated trading language for MetaTrader 5
  • www.mql5.com
MetaQuotes Language 5 (MQL5) is a high-level language designed for developing technical indicators, trading robots and utility applications, which automate financial trading. MQL5 has been developed by MetaQuotes Software Corp. for their trading platform. The language syntax is very close to C++ enabling programmers to develop applications in...
 
tangzius:

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

  1. 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

  2. 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?

  3. Help you with what? You haven't stated a problem.
    You have only four choices: We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
              No free help
              urgent help.
 
Enrique Dangeroux:
https://www.mql5.com/en/docs

thank you for your reply

 
tangzius:

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);

  }

 
tangzius:

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);   
  }
//+------------------------------------------------------------------+
 
Nikolaos Pantzos:

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);   
  }
//+------------------------------------------------------------------+
 
Biantoro Kunarto:

There is a mistype in the EA, please try this :


Correct!!

i<OrdersTotal() not i>... :)

 
Biantoro Kunarto:

There is a mistype in the EA, please try this :


Thank you so much