Navigation:Home > Content >

Forex_Tyrannosaurus-3.mq4

Time: 2018-10-08 | Download file:Forex_Tyrannosaurus-3.mq4

//+------------------------------------------------------------------+
//|                                              Tyrannosaurus-3.mq4 |
//|                                Copyright © 2014, Tyrannosaurus-3 |
//|                                         [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, Tyrannosaurus-3"
#property link      "[email protected]"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 3
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Red
//---- indicator parameters
int StochCount=7;
int Stoch_D=45;
int Stoch_K=3;
int Stoch_S=3;
double Koef=1.8;
bool ShowAverage = false;
bool ShowStoch = true;
//---- indicator buffers
double Buf[], Average[], Stoch[];
double D[], K[], S[];

int draw_begin1=0;
int draw_begin2=0;

//+------------------------------------------------------------------+
void CloseGroupingOfShots(double &Massiv[], double& res1, double& res2)
{
	res1 = 0; res2 = 0;
	int i = 0;
	double j = 0;
	double Min = 0, Max = 0, Sred = 0;
	double tmp;
	
	j = ArraySize(Massiv);
	if (j == 0)
		return;
	for (i = 0; i < j; i++)
	{
		tmp = Massiv[i];
		Sred += tmp;
		if (i == 0)
		{
			Min = tmp;
			Max = tmp;
		} else {
			Min = MathMin(Min, tmp);
			Max = MathMax(Max, tmp);
		}
	}
	Sred /= j;
	if ( (Sred == 0) || (Max == 0) )
		return;
	
	res1 = 100 - (Max - Min);
	res2 = Sred;
}
//+------------------------------------------------------------------+
void GetResultForInstrument(string Instrument, int timeframe, datetime ontime, double& var1, double& var2, double& var3)
{
	int shift = iBarShift(Instrument, timeframe, ontime, false);
	double Value[];
	ArrayResize(Value, StochCount);
	for (int i = 0; i < StochCount; i++)
	 {
		Value[i] = iStochastic(Instrument, timeframe, D[i], K[i], S[i], 3, 1, 0, shift);
		if (i == (StochCount-1))
			var3 = Value[i];
	 }
	double res1 = 0;
	double res2 = 0;
	CloseGroupingOfShots(Value, res1, res2);
	var1 = res1;
	var2 = res2;
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(1);
   string short_name="Forex Tyrannosaurus-3";
   IndicatorShortName(short_name);
   
   IndicatorBuffers(3);
   SetIndexBuffer(0, Buf);
   SetIndexLabel(0, "Stoch ("+Ds_0(D[0])+", "+Ds_0(K[0])+", "+Ds_0(S[0])+")\n");
   SetIndexBuffer(1, Average);
   SetIndexLabel(1, "Average");
   SetIndexBuffer(2, Stoch);
   SetIndexLabel(2, "Stoch");

	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;
	 	 }
	 }
   
	//---- 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 var1, var2, var3;
   for(int i = 0; i < iend; i++)
   {
	 	GetResultForInstrument(Symbol(), 0, Time[i], var1, var2, var3);
	 	Buf[i] = 100-var1;
	 	if (ShowAverage)
	 		Average[i] = 100-var2;
	 	if (ShowStoch)
	 		Stoch[i] = 100-var3;
    }
   return(0);
  }
//+------------------------------------------------------------------+
string Ds_0(double DOUBLE) {return(DoubleToStr(DOUBLE,0));}
//+------------------------------------------------------------------+

Recommend