インディケータ: Fib_SR_6

 

Fib_SR_6:

2つの追加支持抵抗領域を持つFib_SR指標です。

Fib_SR_6

作者: Nikolay Kositsin

 

こんにちは、ニコラスさん、


相対タイムフレーム」を追加しました。


//+------------------------------------------------------------------+
//|Fib_SR_6.mq5
//|著作権 © 2006, イーライ・ハユン
//|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, // 現在の時間枠
   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,             // 2番目に高い時間枠
   tf_cp3 = -3,             // 第3の時間枠
   tf_cp4 = -4,             // 4つ上の時間枠
   tf_cp5 = -5,             // 第5の時間枠
   tf_cp6 = -6              // 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; // 第2比率
input double Ratio3 = 2.764; // 第2比率
input double Step = 0.50; // 拡張ステップ
input color Color_Res3 = clrAqua; // 第3抵抗帯の色
input color Color_Res2 = clrLime; // 第二抵抗帯の色
input color Color_Res1 = clrGreen; // 最初の抵抗帯の色
input color Color_Sup1 = clrRed; // 最初のサポートゾーンの色
input color Color_Sup2 = clrMagenta; // 第2サポートゾーンの色
input color Color_Sup3 = clrYellow; // 第3サポートゾーンの色
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);
//---- DataWindowに表示するラベルと、別のサブウィンドウとツールチップに表示する名前を作成する。
   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)]);
  }
//
//---