Download MetaTrader 5

Failing iCustom returns handle instead of INVALID_HANDLE??

To add comments, please log in or register
graziani
2065
graziani  

I have an indicator:

int OnInit()
{  if (aFStep <= 0.0)
   {  Alert(MQL5InfoString(MQL5_PROGRAM_NAME) + ": init failed: aFStep <= 0");
      //return (INIT_FAILED); // INIT_FAILED == 1 ???????
      return (-1);
   }

....

   //return (INIT_SUCCEEDED); // malo morgen
   return (0);
}

And EA:

...

   handles[tF] = iCustom(Symbol(), timeFrame[tF], parabolicName, parabolicAFStep, parabolicAFMaximum, parabolicSpread, alterStartPosition, alterAFCalculationMethod);

   if (handles[tF] == INVALID_HANDLE)
      Alert("InitParabolic: Failed!!");
   else
      Alert("InitParabolic: Success!!");


....


 And although  indicator gives an alert and fails with return (-1),

 iCustom() gives a regular handle, and alerts about success.

 

 so i just lost another 2 hours on nothing.  and i will lose another hour on bypassing this behaviour.

 

and ...  INIT_FAILED and INIT_AGENT_NOT_SUITABLE should have negative values.
this way i don't see a reason to use this values. Oh, never mind.

phi nuts
2181
phi nuts  

You have indicator that does not call any indicator handle, so when the EA call that indicator through OnInit(), the call for that indicator is success, not the call for the indicator inside OnInit().


 

Say we have indicator A that call indikator B in A's OnInit(), and we comment out indikator B like this :

int OnInit() //--- OnInit of indicator A
  {
   handle = 0;

   //handle = indikator_B(...);  //--- create handle of the indicator
  
   //if(handle==INVALID_HANDLE)  //--- if the handle is not created
   //  {
      Print("Failed to create a handle of indikator B);
      return(-1);
   //  }
  
   return (0);
  }

An iCustom call to indicator A from EA will tell that the call of indicator A is success, that because the EA/MT detect that there's no other indicator except indicator A itself (read there is no indikator B).

If we remove all comments, the call will be also for indikator B. So if iCustom call indicator A and indikator B if failed, iCustom will return INVALID_HANDLE.


 

You can try that, say we deliberately miscalculate Moving Average indicator so it will return INVALID_HANDLE. Then create another indicator (indicator A) that call that MA indicator. An iCustom from EA call indicator A will fail because MA indicator is failed inside indicator A.

I hope you get that, coz I have problem explaining more in English  :)

Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Named Constants / Other Constants - Documentation on MQL5
graziani
2065
graziani  

Hi phi.nuts,

thank you on energy you spent in trying to solve this.

I have already solved this by copying the code that checks for error from Indicator to EA.

 

I am just frustrated that i am loosing too much time  on solving a number of faults instead of working on a something useful.


To add comments, please log in or register