#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 Gray
#property indicator_style1 STYLE_DOT
#property indicator_width1 1
//--- indicator
double ExtMapBuffer1[];
double stochBuffer[]; //--- Stochastic buffer
int stoHandle; //--- variable for storing the handle of the iStochastic indicator
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, ExtMapBuffer1, INDICATOR_DATA); //--- indicator buffers mapping
PlotIndexSetInteger(0, PLOT_ARROW, 172); //--- indicator plot windingsstyle
ArraySetAsSeries(ExtMapBuffer1, true); //--- ordered 0 latest, n oldest
ArraySetAsSeries(stochBuffer, true);
stoHandle = iStochastic(NULL, PERIOD_H4, 14, 3, 3, MODE_SMA, STO_CLOSECLOSE); //--- create indicator handle
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
//--- Get Stochastic indicator data in an array stochBuffer []
int copied=CopyBuffer(stoHandle,0,0,rates_total,stochBuffer);
if(copied<=0)
{
Print("Unable to copy the values of the indicator. Error = ",
GetLastError(),", copied =",copied);
return(0);
}
//--- print out the indicator values
for(int i = 0; i < 5; i++)
{
Alert("Stoh values : " + string(i) + " " + string(stochBuffer));
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+