expiry of EA

 
I want to give my EA on rent for 1 month and e.g i want it to expire on 15th May, 2016.
So should i write in the start funtion "if (TimeCurrent () > D'2016.05.15') return(INIT_FAILED);
Is it OK? Should it stopbon 15th May? Please guide the correct code.
 
If it returns INIT_FAILED, it won't run. Otherwise it will run forever.
 
WHRoeder:
If it returns INIT_FAILED, it won't run. Otherwise it will run forever.
He wrote "in the start function", so it should be ok. Just the INIT_FAILED is useless.
 
angevoyageur:
He wrote "in the start function", so it should be ok. Just the INIT_FAILED is useless.

Then what should i write in place of INIT_FAILED?
I tried it on strategy tester. It stopped trading on a wrong date.. i dont what is going wrong.
 
  • Your example is "TimeCurrent () > D'2016.05.15'" which means it will stop on the 16th and not on the 15th. To be inclusive use ">=" instead of just ">". Please note however, that the 15th is a Sunday.
  • The date "2016.05.15" is in the future, so it will not have any effect in the Strategy Tester and it will simply stop at the end of the data or stop date set on the parameters. Use an earlier date for the strategy tester.
  • To exit the "Start()" function or the "OnTick()" function, simply use a "return;" as there is no return value. However, you can also have the test simultaneously in the "OnInit()" function and there you can return a value of INIT_FAILED;
  • I would also suggest, that besides the "return;" that you also update the Chart Comment with a text message warning about the expiration of the EA, or use an Alert box with a similar text.
 
sammiawan999: I tried it on strategy tester. It stopped trading on a wrong date.. i dont what is going wrong.
  1. That is what you wrote: When datetime is exceeded stop functioning.
  2. You don't know "what is wrong" because you haven't decided what you want done.
 
FMIC:
  • Your example is "TimeCurrent () > D'2016.05.15'" which means it will stop on the 16th and not on the 15th. To be inclusive use ">=" instead of just ">". Please note however, that the 15th is a Sunday.
  • The date "2016.05.15" is in the future, so it will not have any effect in the Strategy Tester and it will simply stop at the end of the data or stop date set on the parameters. Use an earlier date for the strategy tester.
  • To exit the "Start()" function or the "OnTick()" function, simply use a "return;" as there is no return value. However, you can also have the test simultaneously in the "OnInit()" function and there you can return a value of INIT_FAILED;
  • I would also suggest, that besides the "return;" that you also update the Chart Comment with a text message warning about the expiration of the EA, or use an Alert box with a similar text.

Even i tried a past date for strategy tester it did not work.. 
 
sammiawan999:

Even i tried a past date for strategy tester it did not work.. 
If your code is in OnInit() and you start the test before the expiry date, the tester will continue after the date because it does not re-initialize.
 

Verification must be inserted into the OnTick() or OnTimer().

if (TimeCurrent () > D'2016.05.15') 
   {
   Alert("This EA does not work after 2016.05.15");
   ExpertRemove(); 
   //OnDeinit();
   return;
   }
 
Tecuciztecatl:

Verification must be inserted into the OnTick() or OnTimer().

Don't call the event handler "OnDeinit()" in your code. It is an event handler! It will be called by MetaTrader when it has to.
 
FMIC:
Don't call the event handler "OnDeinit()" in your code. It is an event handler! It will be called by MetaTrader when it has to.
ok, thanks.
Reason: