About iStochasic inMQL5!

 

What is wrong:

ouble GetStochasicValue(string cPair, int nPeriod, ENUM_MA_METHOD, ENUM_STO_PRICE price, int bar)

  {

   double sto[1];

   int stoHandle = iStochastic(cPair,nTimeFrame1,nPeriod,price);

   if(stoHandle!=INVALID_HANDLE)

     {

      CopyBuffer(stoHandle,0,bar,1,sto);

     }

   return(sto[0]);

  }

//+------------------------------------------------------------------+


string TestStochastic(int nPeriod, string cPair)

  {

   double cumSTO1;

   double cumSTO2;


   cumSTO1 = GetStochasticValue(cPair,3,3,2,1,0) ; 

   cumSTO2 = GetStochasticValue(cPair,3,3,2,1,1) ;


   if(cumSTO1 < cumSTO2  &&  cumSTO2 >20  )

      return("SELL");

   if(cumSTO1 > cumSTO2  &&  cumSTO2 < 80  )

      return("BUY");

   return("");

  }
 

handles are normally loaded/initialised in the OnInit function. What errors have you got mentioned in editor?

looks like you got this written by an AI or online generator? am i right? These are ridiculed on this forum. There are several threads describing the problems and issues of using these.

I recommend that you look in codebase. There is many free codes there for you to look at, copy, and learn how to code better than 99% of the AI's.