MQL4 - automated forex trading   /  

Forum

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

Back to topics list To post a new topic, please log in or register

avatar
18
gomer 2008.11.25 00:35 

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

article

A Pattern Trailing Stop and Exit the Market

Developers of order modification/closing algorithms suffer from an imperishable woe - how to compare results obtained by different methods? The mechanism of checking is well known - it is Strategy Tester. But how to make an EA to work equally for opening/closing orders? The article describes a tool that provides strong repetition of order openings that allows us to maintain a mathematically correct platform to compare the results of different algorithms for trailing stops and for exiting the market.


avatar
308
abstract_mind 2008.11.25 00:55 


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.







avatar
18
gomer 2008.11.25 00:58 

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.


avatar
2462
phy 2008.11.25 01:03 

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.


avatar
18
gomer 2008.11.25 01:27 
phy, thanks so much great instructions. That is exactly what I was looking for.

avatar
25
ucheujah 2008.12.04 00:55 
gomer wrote >>

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


avatar
25
ucheujah 2008.12.04 01:04 
i sell a robot that i programed. it works perfectly well only when u follow my instructions. +2348036860370
Back to topics list  

To add comments, please log in or register