Download MetaTrader 5
To add comments, please log in or register
Register as a seller and start offering your signals!
sami awan
79
sami awan 2016.04.18 19: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.
whroeder1
13641
whroeder1 2016.04.19 01:55  
If it returns INIT_FAILED, it won't run. Otherwise it will run forever.
Alain Verleyen
Moderator
28652
Alain Verleyen 2016.04.19 05: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.
sami awan
79
sami awan 2016.04.19 18: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.
Fernando Carreiro
1523
Fernando Carreiro 2016.04.19 20: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.
whroeder1
13641
whroeder1 2016.04.20 01: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.
sami awan
79
sami awan 2016.04.21 20: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.. 
Keith Watford
Moderator
7985
Keith Watford 2016.04.21 20: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.
Tecuciztecatl
70
Tecuciztecatl 2016.04.22 20: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;
   }
Fernando Carreiro
1523
Fernando Carreiro 2016.04.22 22: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.
Tecuciztecatl
70
Tecuciztecatl 2016.04.23 07: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.
/
To add comments, please log in or register