How do I programmatically stop an EA from trading?

 

Suppose an EA begins the init process and realizes that the "ABC_abc" indicator is not available in the ..\experts\indicators folder.

How would the EA "shut itself down" and remove itself from the chart?

 

int start(){

if ( I_Want_To_Stop == true) return(0);

 
phy wrote >>

int start(){

if ( I_Want_To_Stop == true) return(0);

Sorry, but I don't understand.

return(0) merely ends the init() process and does not stop the EA.

 

the code above is in start, not init. if condition is no good exit.

you can't remove an EA programmatically.

 

phy, excuse below, see u answer - not mean hijack. i just say same in non-concise way cmp to u ;)

chaff: look on forum - loads stuff on this - over and over it gets chewed over. i been done same thing more than once. but phy says like it is full stop.

EA never stop unless forcedly removed [by system or user] - there is no legit mechanism to programmatically physically stop EA. it called every data tick... [if of course not in start() ]

phy says it all. U got to set state memory [non transient function memory - but function static or EA global memory] flag when U want to stop and do early exit from start() just like he show.

return(0) if in start() ends start() function and returns control back to terminal. nothing to do with init(). init() is not a process - is simply a callable function. eg, like i been told in past, u can call deinit() anytime want - is function...

loads system errors state u must abandon further execution of EA code. only way you do is eg, code detects fatal error and sets true --> I_Want_To_Stop and like shown, early exit IF .T. THEN return(0), likewise IF .F. THEN continue with start() body.

simple but bullet proof

 
That's what I mean to say...
 

yes, but u anwsers [for me] require grey matter workings and that is good, if i can [finally] understand then is good chance i remember - i must sweat to gain and gain is the more sweet for this.

maybe your is koan, concise... unstated meaning... full of insight...

but damn hard understand :o)

 

I was a "teacher" for a brief time long long ago.

My findings:

The people who need endless explanations never learn anyway.

The people who do learn don't need much explanation, just a good hint now and then, because they got stuck.

So, I start with a hint.

Might explain that if it is too obscure.

Many people come in the door ask a question, and are never seen again, too, so, I don't waste too much on initial response.

Oh, and some people just like to argue, too.

 

that good ideas phy. yes, i see many times ur short 1st post. makes sense now ;) i must realize such method.

yes, i sometimes get raised blood pressure over 'phy' single liners - u have helped me understand the whys...

is resonable way and guess self protection too.

nice u spend keystrokes on this. see?

i learn even on ur last post - is good!

in many eyes here - those that understand... U are still vmuch our teacher/mentor - long may it be so :o)

.

arrrgghhhh, argue people is crazy stuff, they post yet bite outstretched friendly hand

.

if i do - i want be told so, for me would be wakey wakey to real world telling off !

 
phy:

the code above is in start, not init. if condition is no good exit.

you can't remove an EA programmatically.

Well,


here How to terminate .. in this forum I read in order to get a 'full stop' just divide by 0.


calli

 

gooly - have u tried?

result will maybe diff than u think

i say because i try and maybe not do as may think?

1. EA still gets called each data tick.

2. if divByZero gets executed, still get "zero divide" message each time new data tick.

test o/p:

2008.12.12 14:41:28 _test GBPUSD,H1: removed
2008.12.12 14:41:28 _test GBPUSD,H1: uninit reason 1
2008.12.12 14:41:28 _test GBPUSD,H1: deinitialized
2008.12.12 14:41:28 _test GBPUSD,H1: deinit(called)
2008.12.12 14:41:26 _test GBPUSD,H1: zero divide
2008.12.12 14:41:26 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:22 _test GBPUSD,H1: zero divide
2008.12.12 14:41:22 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:22 _test GBPUSD,H1: zero divide
2008.12.12 14:41:22 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:21 _test GBPUSD,H1: zero divide
2008.12.12 14:41:21 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:19 _test GBPUSD,H1: zero divide
2008.12.12 14:41:19 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:18 _test GBPUSD,H1: zero divide
2008.12.12 14:41:18 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:17 _test GBPUSD,H1: zero divide
2008.12.12 14:41:17 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:14 _test GBPUSD,H1: zero divide
2008.12.12 14:41:14 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:12 _test GBPUSD,H1: zero divide
2008.12.12 14:41:12 _test GBPUSD,H1: doing: iNum /= 0;
2008.12.12 14:41:12 _test GBPUSD,H1: initialized
2008.12.12 14:41:12 _test GBPUSD,H1: init(called)
2008.12.12 14:41:11 _test GBPUSD,H1: loaded successfully
code:

//_test.mq4
//
/*
https://forum.mql4.com/13337

stringo 2008.06.17 11:16  
Divide by zero in the EA stops your EA permanently. See https://docs.mql4.com/runtime/errors
*/

int init()
{
  Print("init(called)");
  return(0);
}

int deinit()
{
  Print("deinit(called)");
  return(0);
}

bool bOnce=true;
int iNum=1;

int start()
{
  if(bOnce) {Print("doing: iNum /= 0;");iNum /= 0;}
  bOnce = false;
  Print("start(called)");
  return(0);
}

divByZero done first time around because flag set true; Print() > /=0 is done but must falt out in interpreter and not go onto next statement.

second+ times around since flag 'remains' true ; Print() > /=0 is done but must falt out in interpreter and not go onto next statement.

if did next statement, flag get set false and Print() > /=0 would not be done.

.

issue is divBy Zero repeats.

.

so i not understand how works or if even i demonstrate correctly.

maybe side effects of /=0 are more but what and when... effects happen?

.

seems messy way to 'attempt' kill EA.

far easier and 100% under EA control when and where to go no further each time called.

.

phy say somewhere, not remember [again ;] that just accept the system warts and all. live with it and work around it.

plenty of tools to do anything want to do with MQL4, maybe long winded at times but no limitations really imho.

Reason: