stopping an EA

 

hi,

i am writing an EA which should only work on a 15 minute chart. i would like to check the period in the init() function and if it is not correct (ie. 15 minutes) then the EA should produce an error message and refuse to start. at present i am circumventing this by making a check on the period each time that start() is called, but this does not really solve the problem since the EA still runs for the wrong period (although it does nothing). is it possible to just make the EA stop dead if the initial conditions are not met?

thanks a lot,

andrew.

 
if Period( )!=15; return(0);

this will kill your ea, if the period is not 15min,


place this code right after the start()

 
c0d3 wrote >>

this will kill your ea, if the period is not 15min,


place this code right after the start()


the OP should place your code in the init(), not the start(), no need to check chart time period on every tick and the init() will be re-ran if someone were to change the chart after attaching the EA to it.

 

And please correct me if I'm wrong, but placing

if Period( )!=15; return(0);

in init() won't stop the EA. Init returns 0 anyway. is it not better

 bool trade=false;
  if (Period()=={desired timeframe})trade=true;

placed in init() and then start start() with if (trade==true) { //do stuff}

V

 
Viffer:

And please correct me if I'm wrong [...]

Yeah, sounds about right. Variable 'trade' should be on a global scope for this to work... Alternatively u can have the EA stuck in a loop in init() if the condition is not met.
Reason: