高値や安値を更新した場合にはついていった方がいい場合ってありますよね?前回高値位置を表示することで、高値安値の更新タイミングをサブウィンドウに出すプログラムです。
チャートの見方は、青い線が高値、赤い線が安値です。0になったタイミングが更新されたタイミングとなります。基本的には高値安値のチャートは反対に動きます。基本的に線が下にある方が更新タイミングが近いことになります。時間が近い方が影響が大きいと考えると、赤の線と青の線がクロスした際、下にいった線の色で売買シグナルとすることも可能だと考えています。
プログラムそのものはものすごく単純です。
着目点は IndicatorSetDouble(INDICATOR_MAXIMUM, Period);
です。
これは、チャートウィンドウのDouble値のプロパティに値を設定する関数です。
今回は最大値の値を期間によって変えたかったため、この関数を使用して設定しています。
設定可能なプロパティは下記ページに書いてあります。
https://www.mql5.com/en/docs/constants/indicatorconstants/customindicatorproperties
//------------------------------------------------------------------
// 高値安値 インデックス幅
#property copyright "Copyright 2015, Daisuke"
#property link "http://mt4program.blogspot.jp/"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_separate_window
#property indicator_maximum +500
#property indicator_minimum 0
//バッファーを指定する。
#property indicator_buffers 2
//プロット数を指定する。
#property indicator_plots 2
#property indicator_label1 "LINE1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_label2 "LINE2"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrIndianRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
// 入力パラメータ 移動平均期間
input int Period = 250;
// バッファー
double highBuffer[];
double lowBuffer[];
//------------------------------------------------------------------
//初期化
int OnInit()
{
// 短縮名を設定
string shortName = "HIGHLOW (" + IntegerToString(Period) +")";
IndicatorShortName(shortName);
SetIndexBuffer(0, highBuffer);
SetIndexBuffer(1, lowBuffer);
SetIndexDrawBegin(0, Period);
IndicatorSetDouble(INDICATOR_MAXIMUM, Period);
return(INIT_SUCCEEDED);
}
//------------------------------------------------------------------
//計算イベント
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[]) //スプレット
{
for( int i = rates_total - prev_calculated - 1 ; i >= 0; i-- )
{
highBuffer[i] = iHighest(Symbol(), PERIOD_CURRENT, MODE_HIGH, Period, i) - i;
lowBuffer[i] = iLowest(Symbol(), PERIOD_CURRENT, MODE_LOW, Period, i) - i;
}
return(rates_total - 1);
}