Input Validation

 

How do people usually validate their input values?

I was "cheating" doing things like using uint instead of int (to prevent negative values) however the compiler doesn't seem to like this much because later on when I compare unit to int variables it gives a "sign mismatch" warning.

 
ycomp:How do people usually validate their input values? I was "cheating" doing things like using uint instead of int (to prevent negative values) however the compiler doesn't seem to like this much because later on when I compare unit to int variables it gives a "sign mismatch" warning.

Please read the documentation on the return value for the OnInit() event handler, specifically the following ...

INIT_PARAMETERS_INCORRECT

Designed to denote an incorrect set of input parameters by a programmer. In the general optimization table, the result string with this return code is highlighted in red.

A test for such a set of EA inputs is not performed. The agent is ready to receive a new task.

When this value is received, the strategy tester does not pass this task to other agents for repeated execution.

Documentation on MQL5: Event Handling / OnInit
Documentation on MQL5: Event Handling / OnInit
  • www.mql5.com
OnInit - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Please read the documentation on the return value for the OnInit() event handler, specifically the following ...

INIT_PARAMETERS_INCORRECT

Designed to denote an incorrect set of input parameters by a programmer. In the general optimization table, the result string with this return code is highlighted in red.

A test for such a set of EA inputs is not performed. The agent is ready to receive a new task.

When this value is received, the strategy tester does not pass this task to other agents for repeated execution.

thanks

[Deleted]  

An option for the Init-Method is something like this:

...
If (variable < minimum) variable = default;
...
 
Benjamin Fotteler #:

An option for the Init-Method is something like this:

yeah this is better. I tried return  INIT_PARAMETERS_INCORRECT and it removes the EA from my template.. so this is not desired behaviour for me

 
ycomp #: so this is not desired behaviour for me

Don't you want to know that you tried wrong values? Ignorance is not bliss.

[Deleted]  

To not be ignorant, there should be an print output like:

...
if (variable < minimum) {
        variable = default;
        Print("variable x was to small, set it to default value", default);
}
...
 
Benjamin Fotteler #: To not be ignorant, there should be an print output like:

Which will be ignored, unless the indicator exits.