Navigation:Home > Content >

AlexSTAL_Stochastic-X8.mq4

Time: 2018-11-23 | Download file:AlexSTAL_Stochastic-X8.mq4

//+------------------------------------------------------------------+
//|                                        Custom Moving Average.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 110
#property indicator_level1 0
#property indicator_level2 100
#property indicator_buffers 8
#property indicator_color1 C'255,0,0'
#property indicator_color2 C'255,25,25'
#property indicator_color3 C'255,50,50'
#property indicator_color4 C'255,75,75'
#property indicator_color5 C'255,100,100'
#property indicator_color6 C'255,125,125'
#property indicator_color7 C'255,150,150'
#property indicator_color8 C'255,175,175'
//---- indicator parameters
extern int StochCount = 7;
extern int Stoch_D = 12;
extern int Stoch_K = 8;
extern int Stoch_S = 5;
extern double Koef = 1.2;
//---- indicator buffers
double Buf0[],Buf1[],Buf2[],Buf3[],Buf4[],Buf5[],Buf6[],Buf7[];
double D[], K[], S[];

int draw_begin1=0;
int draw_begin2=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(1);
   string short_name="Stochastic X8";
//---- indicator short name
   IndicatorShortName(short_name+"*"+DoubleToStr(Koef,1)+" ("+Stoch_D+", "+Stoch_K+", "+Stoch_S+")");
   
   SetIndexBuffer(0, Buf0);
   SetIndexBuffer(1, Buf1);
   SetIndexBuffer(2, Buf2);
   SetIndexBuffer(3, Buf3);
   SetIndexBuffer(4, Buf4);
   SetIndexBuffer(5, Buf5);
   SetIndexBuffer(6, Buf6);
   SetIndexBuffer(7, Buf7);

  	// Инициализация вспомогательных переменных
	ArrayResize(D, StochCount);
	ArrayResize(K, StochCount);
	ArrayResize(S, StochCount);
	for (int i = 0; i < StochCount; i++)
	 {
	 	if (i == 0)
	 	 {
	 	 	D[0] = Stoch_D;
	 	 	K[0] = Stoch_K;
	 	 	S[0] = Stoch_S;
	 	 } else {
	 	 	D[i] = D[i-1] * Koef;
	 	 	K[i] = K[i-1] * Koef;
	 	 	S[i] = S[i-1] * Koef;
	 	 }
	   SetIndexLabel (i, "Stoch ("+Ds_0(D[i])+", "+Ds_0(K[i])+", "+Ds_0(S[i])+")\n");
	 }
   
	//---- initialization done
   draw_begin1 = Stoch_K + Stoch_S;
   draw_begin2 = draw_begin1 + Stoch_D;
   
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();
   if (Bars <= draw_begin2)
   	return(0);
   int i1 = Bars - Stoch_K;
   if (counted_bars > Stoch_K) i1 = Bars - counted_bars - 1;
   int i2 = Bars - draw_begin1;
   if (counted_bars > draw_begin1) i2 = Bars - counted_bars - 1;
   int iend = MathMax(i1, i2);
	
	double tmp;
   for(int i = 0; i < iend; i++)
	 {
		for (int j = 0; j < StochCount; j++)
		 {
		 	tmp = iStochastic(NULL, 0, D[j], K[j], S[j], 3, 1, 0, i);
		 	switch(j)
		 	 {
				case 0: Buf0[i] = tmp; break;
				case 1: Buf1[i] = tmp; break;
				case 2: Buf2[i] = tmp; break;
				case 3: Buf3[i] = tmp; break;
				case 4: Buf4[i] = tmp; break;
				case 5: Buf5[i] = tmp; break;
				case 6: Buf6[i] = tmp; break;
				case 7: Buf7[i] = tmp; break;
		 	 }
		 }
      
    }
   return(0);
  }
//+------------------------------------------------------------------+
string Ds_0(double DOUBLE) {return(DoubleToStr(DOUBLE,0));}
//+------------------------------------------------------------------+

Recommend