How to get a value from an indicator in code?

 

Hello, I'm playing around with my first advisor. I am using a stochastic indicator. I created the handler for it:

stochastic = iStochastic(Symbol(), PERIOD_M1, periodK, periodD, slowing, MODE_SMA, STO_LOWHIGH);

And now I want to get the values for Main and Signal.

I read about IndicatorParameters. I tried it out myself:

MqlParam parameters[];
      ENUM_INDICATOR indicatorType;
      int params = IndicatorParameters(stochastic, indicatorType, parameters);
      //--- The header of the message
         string par_info="Short name EURUSD, type "
                         +EnumToString(ENUM_INDICATOR(indicatorType))+"\r\n";
         //--- 
      for(int p=0;p<params;p++)
           {
            par_info+=StringFormat("parameter %d: type=%s, long_value=%d, double_value=%G,string_value=%s\r\n",
                                   p,
                                   EnumToString((ENUM_DATATYPE)parameters[p].type),
                                   parameters[p].integer_value,
                                   parameters[p].double_value,
                                   parameters[p].string_value
                                   );
           }
         Print(par_info);
         
         Print(stochastic);
      
      return(INIT_SUCCEEDED);

And in the console I got:

Short Name EURUSD, type ENUM_INDICATOR::0

(empty row where I assume par_info should've been)

10 (which is the int value of the stochastic handler)

I tried doing it in OnInit and OnTick, but both gave the same result.

I tried this to see what the output is and try to reverse engineer where the value I need is, but I've no clue how to do this.

Any help will be appreciated.

Documentation on MQL5: Timeseries and Indicators Access / IndicatorParameters
Documentation on MQL5: Timeseries and Indicators Access / IndicatorParameters
  • www.mql5.com
//| Script program start function                                    | //
 
How to start with MQL5
How to start with MQL5
  • 2020.04.09
  • www.mql5.com
This thread discusses MQL5 code examples. There will be examples of how to get data from indicators, how to program advisors...
 
Awesome. This is exactly what I was looking for.
 

Do you have an example like this one, that works on iCustom? Because I've been trying to follow the same steps as this one, (I don't see anything in the documentation that would stop me from doing this) for a custom indicator that has one buffer.

Instead I use:

!iGetArray(fisher, 0, startPos, count, fisherArr))

So the buffer at index 0.

Weirdly enough, when I attach the indicator to a graph, I get values for it, but when I try to run it from the EA, I only get 0.0 as values from the buffer.

Reason: