Индикаторы: Fib_SR_6

 

Fib_SR_6:

Индикатор Fib_SR с двумя дополнительными зонами поддержки и сопротивления.

Fib_SR_6

Автор: Nikolay Kositsin

 

привет мр.николай,


Я добавил «относительные таймфреймы».


//+------------------------------------------------------------------+
//|                                                     Fib_SR_6.mq5 |
//|                                      Copyright © 2006, Eli hayun |
//|                                          http://www.elihayun.com |
//+------------------------------------------------------------------+
//---- авторство индикатора
#property copyright "Copyright © 2006, Eli hayun"
//---- ссылка на сайт автора
#property link      "http://www.elihayun.com"
//---- номер версии индикатора
#property version   "1.00"
//---- отрисовка индикатора в главном окне
#property indicator_chart_window 
//---- для расчёта и отрисовки индикатора не использовано ни одного буфера
#property indicator_buffers 0
//---- использовано ноль графических построений
#property indicator_plots   0
//+----------------------------------------------+ 
//|  объявление констант                         |
//+----------------------------------------------+
#define RESET     0            // Константа для возврата терминалу команды на пересчет индикатора
#define FIB_RES3 "FIB_RES_3"
#define FIB_RES2 "FIB_RES_2"
#define FIB_RES1 "FIB_RES_1"
#define FIB_SUP1 "FIB_SUP_1"
#define FIB_SUP2 "FIB_SUP_2"
#define FIB_SUP3 "FIB_SUP_3"


//---
//
enum enTimeFrames
  {
   tf_cu  = PERIOD_CURRENT, // Current time frame
   tf_m1  = PERIOD_M1,      // 1 minute
   tf_m2  = PERIOD_M2,      // 2 minutes
   tf_m3  = PERIOD_M3,      // 3 minutes
   tf_m4  = PERIOD_M4,      // 4 minutes
   tf_m5  = PERIOD_M5,      // 5 minutes
   tf_m6  = PERIOD_M6,      // 6 minutes
   tf_m10 = PERIOD_M10,     // 10 minutes
   tf_m12 = PERIOD_M12,     // 12 minutes
   tf_m15 = PERIOD_M15,     // 15 minutes
   tf_m20 = PERIOD_M20,     // 20 minutes
   tf_m30 = PERIOD_M30,     // 30 minutes
   tf_h1  = PERIOD_H1,      // 1 hour
   tf_h2  = PERIOD_H2,      // 2 hours
   tf_h3  = PERIOD_H3,      // 3 hours
   tf_h4  = PERIOD_H4,      // 4 hours
   tf_h6  = PERIOD_H6,      // 6 hours
   tf_h8  = PERIOD_H8,      // 8 hours
   tf_h12 = PERIOD_H12,     // 12 hours
   tf_d1  = PERIOD_D1,      // daily
   tf_w1  = PERIOD_W1,      // weekly
   tf_mn  = PERIOD_MN1,     // monthly
   tf_cp1 = -1,             // Next higher time frame
   tf_cp2 = -2,             // Second higher time frame
   tf_cp3 = -3,             // Third higher time frame
   tf_cp4 = -4,             // Fourth higher time frame
   tf_cp5 = -5,             // Fifth higher time frame
   tf_cp6 = -6              // Sixth higher time frame
  };

ENUM_TIMEFRAMES _tfsPer[]={PERIOD_M1,PERIOD_M2,PERIOD_M3,PERIOD_M4,PERIOD_M5,PERIOD_M6,PERIOD_M10,PERIOD_M12,PERIOD_M15,PERIOD_M20,PERIOD_M30,PERIOD_H1,PERIOD_H2,PERIOD_H3,PERIOD_H4,PERIOD_H6,PERIOD_H8,PERIOD_H12,PERIOD_D1,PERIOD_W1,PERIOD_MN1};
  
//
//---
//  

//+----------------------------------------------+
//| Входные параметры индикатора                 |
//+----------------------------------------------+
input enTimeFrames      InpTimeframe  =  tf_cp1; // Indicator Next timeframe for calculating the indicator
input uint NumberofBar = 1; // Bar number to calculate the indicator
input double Ratio1 = 0.618; // first ratio
input double Ratio2 = 1.382; // second ratio
input double Ratio3 = 2.764; // second ratio
input double Step = 0.50; // extension step
input color Color_Res3 = clrAqua; // color of the third resistance zone
input color Color_Res2 = clrLime; // color of the second resistance zone
input color Color_Res1 = clrGreen; // color of the first resistance zone
input color Color_Sup1 = clrRed; // color of the first support zone
input color Color_Sup2 = clrMagenta; // color of the second support zone
input color Color_Sup3 = clrYellow; // color of the third support zone
input uint RightTail = 60; // protrusion of rectangles beyond the zero bar to the right in minutes
input uint LeftTail = 60; // protrusion of rectangles behind the starting bar to the left in minutes
//+----------------------------------------------+
uint SecondRightTail,SecondLeftTail;
//--- global variables
ENUM_TIMEFRAMES   Timeframe;


//+------------------------------------------------------------------+
//|  Создание прямоугольного объекта                                 |
//+------------------------------------------------------------------+
void CreateRectangle
(
 long     chart_id,      // идентификатор графика
 string   name,          // имя объекта
 int      nwin,          // индекс окна
 datetime time1,         // время 1
 double   price1,        // цена 1
 datetime time2,         // время 2
 double   price2,        // цена 2
 color    Color,         // цвет линии
 bool     background,    // фоновое отображение линии
 string   text           // текст
 )
//---- 
  {
//----
   ObjectCreate(chart_id,name,OBJ_RECTANGLE,nwin,time1,price1,time2,price2);
   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
   ObjectSetInteger(chart_id,name,OBJPROP_FILL,true);
   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
   ObjectSetInteger(chart_id,name,OBJPROP_BACK,background);
   ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,"\n"); //запрет всплывающей подсказки
   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); //объект на заднем плане
//----
  }
//+------------------------------------------------------------------+
//|  Переустановка прямоугольного объекта                            |
//+------------------------------------------------------------------+
void SetRectangle
(
 long     chart_id,      // идентификатор графика
 string   name,          // имя объекта
 int      nwin,          // индекс окна
 datetime time1,         // время 1
 double   price1,        // цена 1
 datetime time2,         // время 2
 double   price2,        // цена 2
 color    Color,         // цвет линии
 bool     background,    // фоновое отображение линии
 string   text           // текст
 )
//---- 
  {
//----
   if(ObjectFind(chart_id,name)==-1) CreateRectangle(chart_id,name,nwin,time1,price1,time2,price2,Color,background,text);
   else
     {
      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
      ObjectMove(chart_id,name,0,time1,price1);
      ObjectMove(chart_id,name,1,time2,price2);
     }
//----
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+  
int OnInit()
  {
//---Calculate indicator timeframe  
   Timeframe = MathMax(timeFrameGet((int)InpTimeframe),_Period);
  
//----
   SecondRightTail=RightTail*60;
   SecondLeftTail=LeftTail*60;
//---- определение точности отображения значений индикатора
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- создание меток для отображения в DataWindow и имени для отображения в отдельном подокне и во всплывающей подсказке
   IndicatorSetString(INDICATOR_SHORTNAME,"Fib_SR");
//---- завершение инициализации
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+    
void OnDeinit(const int reason)
  {
//----
   ObjectDelete(0,FIB_SUP3);
   ObjectDelete(0,FIB_SUP2);
   ObjectDelete(0,FIB_SUP1);
   ObjectDelete(0,FIB_RES1);
   ObjectDelete(0,FIB_RES2);
   ObjectDelete(0,FIB_RES3);
//----
   ChartRedraw(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[]
                )
  {
//---- 
   if(prev_calculated==rates_total && NumberofBar) return(rates_total);
//----
   double nClose[1],nHigh[1],nLow[1];
   datetime nTime[1];
   int to_copy;

//---- индексация элементов в массивах как в таймсериях  
   ArraySetAsSeries(time,true);
//----
   to_copy=1;
//----
   if(CopyTime(NULL,Timeframe,0,to_copy,nTime)<to_copy)return(RESET);
   if(CopyClose(NULL,Timeframe,NumberofBar,to_copy,nClose)<to_copy)return(RESET);
   if(CopyHigh(NULL,Timeframe,NumberofBar,to_copy,nHigh)<to_copy)return(RESET);
   if(CopyLow(NULL,Timeframe,NumberofBar,to_copy,nLow)<to_copy)return(RESET);
//----   
   double C=nClose[0];
   double H=nHigh[0];
   double L=nLow[0];
   double R=(H-L);
//----
   C=(H+L+C)/3;
   double D=C+R*Step;
   double B=C-R*Step;
   double E=C+R*2*Step;
   double A=C-R*2*Step;
//----
   double R2=R*Ratio2;
   double R1=R*Ratio1;
   double B1=C-R1;
   double A1=C-R2;
//----
   double D1=C+R1;
   double E1=C+R2;
//----      
   double R3=R*Ratio3;
   double F=C+R*4*Step;
   double G=C-R*4*Step;  
   double F1=C+R3;
   double G1=C-R3;
//----
   SetRectangle(0,FIB_RES3,0,nTime[0]-SecondLeftTail,F,time[0]+SecondRightTail,F1,Color_Res3,true,FIB_RES3);
   SetRectangle(0,FIB_RES2,0,nTime[0]-SecondLeftTail,E,time[0]+SecondRightTail,E1,Color_Res2,true,FIB_RES2);
   SetRectangle(0,FIB_RES1,0,nTime[0]-SecondLeftTail,D,time[0]+SecondRightTail,D1,Color_Res1,true,FIB_RES1);
   SetRectangle(0,FIB_SUP1,0,nTime[0]-SecondLeftTail,B,time[0]+SecondRightTail,B1,Color_Sup1,true,FIB_SUP1);
   SetRectangle(0,FIB_SUP2,0,nTime[0]-SecondLeftTail,A,time[0]+SecondRightTail,A1,Color_Sup2,true,FIB_SUP2);
   SetRectangle(0,FIB_SUP3,0,nTime[0]-SecondLeftTail,G,time[0]+SecondRightTail,G1,Color_Sup3,true,FIB_SUP3);
//----
   ChartRedraw(0);
   return(rates_total);
  }
//+------------------------------------------------------------------+


//
ENUM_TIMEFRAMES timeFrameGet(int period)
  {
   int _shift=(period<0?MathAbs(period):0);
   if(_shift>0 || period==tf_cu) period=_Period;
   int i; for(i=0;i<ArraySize(_tfsPer);i++) if(period==_tfsPer[i]) break;

   return(_tfsPer[(int)MathMin(i+_shift,ArraySize(_tfsPer)-1)]);
  }
//
//---