XMの仮想通貨取引をしながら
自動売買のプログラムを毎日考えています。
さて今日はMT5でのHighLowバンドインジを
作ってみました。
MT4ならiHighestとかiLowestとか
便利な関数があったのに
MT5では何故か消えてしまいました。
今回は普通のHighLowバンドですが
次回はMTFで1時間ずらしたりした
インジケータを作ろうと思います。
MT5 HighLowバンド インジケータ
BandPeriod期間の中の
高値安値ラインを表示する
インジケータです。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// プリプロセッサ命令(プログラム全体の設定)
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 3
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
#property indicator_type3 DRAW_LINE
#property indicator_color1 clrNONE
#property indicator_color2 clrCoral
#property indicator_color3 clrCyan
// 指標バッファ用の配列の宣言
double BufMain[]; // ベースラン
double BufUpper[]; // 上位ライン
double BufLower[]; // 下位ライン
// 外部パラメータ
input int BandsPeriod = 20; // HLバンドの期間
// 初期化関数
int OnInit()
{
// 指標バッファの割り当て
SetIndexBuffer(0, BufMain, INDICATOR_DATA);
SetIndexBuffer(1, BufUpper, INDICATOR_DATA);
SetIndexBuffer(2, BufLower, INDICATOR_DATA);
ArraySetAsSeries(BufMain, true);
ArraySetAsSeries(BufUpper, true);
ArraySetAsSeries(BufLower, true);
return(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[])
{
// 時間並びの変更
ArraySetAsSeries(High, true);
ArraySetAsSeries(Low, true);
// カスタム指標の範囲
int limit = rates_total - prev_calculated;
if(limit == 0) limit = 1;
for(int i=limit-1; i>=0; i--)
{
BufUpper[i]=High[ArrayMaximum(High,i,BandsPeriod)];
BufLower[i]=Low[ArrayMinimum(Low,i,BandsPeriod)];
BufMain[i]=(BufUpper[i]+BufLower[i])/2;
}
return(rates_total);
}
|
上記コードをコピーしてMetaEditorに
貼り付けてご利用ください。
ちなみに素人作成なので不具合が生じても
当サイトは責任を取りかねます。
コードの内容
ArrayMaximumやArrayMinimumが
最大最小の配列を探す関数になります。
inputで期間を外部入力できます。
仮想通貨との相性
仮想通貨は騙しが少なく
高値ブレイクで走る傾向が強いです。
高値ラインブレイクと
安値でのトレールなら
それなりの優位性がありそう。
短い足より長い足の方が良いでしょうね。
まとめ
XMの仮想通貨取引で使う
MT5プラットフォームで動く
HighLowバンドインジケータの
紹介でした。