expiry of EA

Back to topics list To post a new topic, please log in or register
avatar
19
sammiawan999 2016.04.18 21:52
 
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.
avatar
12983
WHRoeder 2016.04.19 03:55 #
 
If it returns INIT_FAILED, it won't run. Otherwise it will run forever.
avatar
Moderator
3206
angevoyageur 2016.04.19 07:58 #
 
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.
avatar
19
sammiawan999 2016.04.19 20:55 #
 
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.
avatar
1197
FMIC 2016.04.19 22:47 #
 
  • 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.
avatar
12983
WHRoeder 2016.04.20 03:25 #
 
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.
avatar
19
sammiawan999 2016.04.21 22:06 #
 
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.. 
avatar
Moderator
3404
GumRai 2016.04.21 22:46 #
 
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.
avatar
69
Tecuciztecatl 2016.04.22 22:16 #
 

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;
   }

 

avatar
1197
FMIC 2016.04.23 00:24 #
 
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.
avatar
69
Tecuciztecatl 2016.04.23 09:27 #
 
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.
Back to topics list  

To add comments, please log in or register