new to MT4 - want my EA to be called only once

 

Hello, I'm very new to MT4 and just wrote and compiled my first EA shown below. When I ran the program in demo mode, it worked and placed my order. However, it kept buying me orders, one after another.

My expectation was that the EA would only be called once (I'm running it inside FXDD if that matters) and only one order would be placed. But it seemed to get called repeatedly. How can I cally me EA only once? Is there something I can put inside the start function that will only allow it to be called once? I'm not sure what init() and deinit() funtions are and why I'm returning zero at the end of the start function.

Is there a setting inside FXDD that can make it only be called once. More logic will be added to this EA but basically, I'm looking to call the EA only once.

Any help is much appreciated.

Thanks.
Gomer

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
OrderSend("EURUSD",0,1,Ask,3,0,0,"Comment",12345,0,Green);

//----
return(0);
}
//+------------------------------------------------------------------+

 

Here is a simple solution.

int start()
{
//----
if(OrdersTotal()==0)
OrderSend("EURUSD",0,1,Ask,3,0,0,"Comment",12345,0,Green);

//----
return(0);
}


ADVISE:

There are many illustrative examples and demos of mql4 programs here in the forum, for which I recommend to start understand them.

Using a tool without knowing it is a recipe for disaster.

 

abstract mind, thank you for your help, this will work.

Thanks also for your advice. I am starting slowly and in demo mode for now.

 

Save your EA as a script...

Save into /experts/scripts

recompile

drag it from Navigator - Scripts onto the chart

it will execute and exit.

EA code is run on every tick.

Script code is run once on demand.

 
phy, thanks so much great instructions. That is exactly what I was looking for.
 
gomer:

Hello, I'm very new to MT4 and just wrote and compiled my first EA shown below. When I ran the program in demo mode, it worked and placed my order. However, it kept buying me orders, one after another.

My expectation was that the EA would only be called once (I'm running it inside FXDD if that matters) and only one order would be placed. But it seemed to get called repeatedly. How can I cally me EA only once? Is there something I can put inside the start function that will only allow it to be called once? I'm not sure what init() and deinit() funtions are and why I'm returning zero at the end of the start function.

Is there a setting inside FXDD that can make it only be called once. More logic will be added to this EA but basically, I'm looking to call the EA only once.

Any help is much appreciated.

Thanks.
Gomer

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
OrderSend("EURUSD",0,1,Ask,3,0,0,"Comment",12345,0,Green);

//----
return(0);
}
//+------------------------------------------------------------------+

i sell a robot that i programed. it works perfectly well only when u follow my instructions. +2348036860370

 
i sell a robot that i programed. it works perfectly well only when u follow my instructions. +2348036860370
Reason: