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.

 
Thanks!
 

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate/OnStart (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)