指标: Fib_SR_6

 

Fib_SR_6:

Fib_SR 指标有两个额外的支撑和阻力区域。

Fib_SR_6

作者: Nikolay Kositsin

 

你好,尼古拉斯先生、


我加了 "相对时间框架"。


//+------------------------------------------------------------------+
//|Fib_SR_6.mq5
//|版权所有 © 2006, Eli hayun |
//|http://www.elihayun.com ||
//+------------------------------------------------------------------+
//---- 指标作者
#property 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, // 当前时间框架
   tf_m1  = PERIOD_M1,      // 1 分钟
   tf_m2  = PERIOD_M2,      // 2 分钟
   tf_m3  = PERIOD_M3,      // 3 分钟
   tf_m4  = PERIOD_M4,      // 4 分钟
   tf_m5  = PERIOD_M5,      // 5 分钟
   tf_m6  = PERIOD_M6,      // 6 分钟
   tf_m10 = PERIOD_M10,     // 10 分钟
   tf_m12 = PERIOD_M12,     // 12 分钟
   tf_m15 = PERIOD_M15,     // 15 分钟
   tf_m20 = PERIOD_M20,     // 20 分钟
   tf_m30 = PERIOD_M30,     // 30 分钟
   tf_h1  = PERIOD_H1,      // 1 小时
   tf_h2  = PERIOD_H2,      // 2 小时
   tf_h3  = PERIOD_H3,      // 3 小时
   tf_h4  = PERIOD_H4,      // 4 小时
   tf_h6  = PERIOD_H6,      // 6 小时
   tf_h8  = PERIOD_H8,      // 8 小时
   tf_h12 = PERIOD_H12,     // 12 小时
   tf_d1  = PERIOD_D1,      // 每天
   tf_w1  = PERIOD_W1,      // 每周
   tf_mn  = PERIOD_MN1,     // 每月
   tf_cp1 = -1,             // 下一个更高时间段
   tf_cp2 = -2,             // 第二个更高的时间框架
   tf_cp3 = -3,             // 第三个更高的时间框架
   tf_cp4 = -4,             // 第四个更高的时间框架
   tf_cp5 = -5,             // 第五个更高的时间框架
   tf_cp6 = -6              // 第六个更高的时间框架
  };

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; // 指标 计算指标的下一个时间框架
input uint NumberofBar = 1; // 计算指标的条形码
input double Ratio1 = 0.618; // 第一比率
input double Ratio2 = 1.382; // 第二比率
input double Ratio3 = 2.764; // 第二比率
input double Step = 0.50; // 扩展步骤
input color Color_Res3 = clrAqua; // 第三阻力区的颜色
input color Color_Res2 = clrLime; // 第二阻力区的颜色
input color Color_Res1 = clrGreen; // 第一个阻力区的颜色
input color Color_Sup1 = clrRed; // 第一个支撑区的颜色
input color Color_Sup2 = clrMagenta; // 第二支撑区的颜色
input color Color_Sup3 = clrYellow; // 第三支撑区的颜色
input uint RightTail = 60; // 超出零横线的矩形向右突出,以分钟为单位
input uint LeftTail = 60; // 起始横线后的矩形向左突出,以分钟为单位
//+----------------------------------------------+
uint SecondRightTail,SecondLeftTail;
//--- 全局变量
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);
     }
//----
  }
//+------------------------------------------------------------------+
//| 自定义指示器初始化函数
//+------------------------------------------------------------------+ 
int OnInit()
  {
//--计算指标时间框架 
   Timeframe = MathMax(timeFrameGet((int)InpTimeframe),_Period);
  
//----
   SecondRightTail=RightTail*60;
   SecondLeftTail=LeftTail*60;
//---- 确定显示指标值的准确性
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- 创建在数据窗口中显示的标签,以及在单独的子窗口和工具提示中显示的名称
   IndicatorSetString(INDICATOR_SHORTNAME,"Fib_SR");
//---- 初始化完成
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 自定义指标去初始化功能
//+------------------------------------------------------------------+ 
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);
  }
//+------------------------------------------------------------------+
//| 自定义指标迭代函数
//+------------------------------------------------------------------+
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)]);
  }
//
//---