122 lines
No EOL
7.5 KiB
MQL5
122 lines
No EOL
7.5 KiB
MQL5
#include "math_for_pairs_trading.mqh"
|
|
|
|
#property indicator_chart_window //チャートウィンドウに表示
|
|
//#property indicator_separate_window //別ウィンドウに表示
|
|
#property indicator_buffers 1 //指標バッファの数
|
|
#property indicator_plots 1 //表示させる指標バッファの数
|
|
|
|
#property indicator_type1 DRAW_LINE //指標の種類
|
|
#property indicator_width1 1 //ラインの太さ
|
|
#property indicator_style1 STYLE_SOLID //ラインの種類
|
|
#property indicator_color1 clrWhite //ラインの色
|
|
|
|
#property indicator_type2 DRAW_LINE //指標の種類
|
|
#property indicator_width2 1 //ラインの太さ
|
|
#property indicator_style2 STYLE_DASHDOTDOT //ラインの種類
|
|
#property indicator_color2 clrWhite //ラインの色
|
|
|
|
//#property indicator_level1 50 //指標のレベル
|
|
//#property indicator_level2 70 //指標のレベル
|
|
//#property indicator_level3 30 //指標のレベル
|
|
//#property indicator_levelcolor clrGray //レベルの色
|
|
//#property indicator_levelwidth 1 //レベルの太さ
|
|
//#property indicator_levelstyle STYLE_DOT //レベルの種類
|
|
|
|
input int Prd = 20; // 期間
|
|
|
|
double Buf0[], Buf1[]; //指標バッファ用の配列の宣言
|
|
|
|
//+------------------------------------------------------------------+
|
|
//|初期化
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
if(!SetIndexBuffer(0, Buf0) || !ArraySetAsSeries(Buf0, true)) { //配列を指標バッファに関連付ける
|
|
Print("OnInit エラーコード:", GetLastError());
|
|
return(INIT_FAILED);
|
|
}
|
|
if(!SetIndexBuffer(1, Buf1) || !ArraySetAsSeries(Buf1, true)) { //配列を指標バッファに関連付ける
|
|
Print("OnInit エラーコード:", GetLastError());
|
|
return(INIT_FAILED);
|
|
}
|
|
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//|初期化解除
|
|
//+------------------------------------------------------------------+
|
|
void OnDeinit(const int reason)
|
|
{
|
|
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| メイン
|
|
//+------------------------------------------------------------------+
|
|
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[])
|
|
{
|
|
int limit = CalculateBars(rates_total, prev_calculated); //プロットするバーの数
|
|
|
|
ArraySetAsSeries(open, true);
|
|
ArraySetAsSeries(high, true);
|
|
ArraySetAsSeries(low, true);
|
|
ArraySetAsSeries(close, true);
|
|
|
|
for(int i = 0; i < limit - Prd; i++) {
|
|
|
|
}
|
|
|
|
return(rates_total);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| OnCalculate関数で計算するバーの数
|
|
//+------------------------------------------------------------------+
|
|
int CalculateBars(const int rates_total, const int prev_calculated)
|
|
{
|
|
int ret = 1;
|
|
|
|
//--- 最初のTick以外は1を返す
|
|
if(prev_calculated > 0)
|
|
return ret;
|
|
|
|
//--- 日足より上は全期間
|
|
if(_Period > PERIOD_D1)
|
|
{
|
|
ret = rates_total;
|
|
return ret;
|
|
}
|
|
//--- 4時間足より上は2003年以降
|
|
if(_Period > PERIOD_H4)
|
|
{
|
|
ret = Bars(_Symbol, PERIOD_CURRENT, D'2003.01.01', TimeCurrent());
|
|
return ret;
|
|
}
|
|
//--- 1時間足より上は2010年以降
|
|
if(_Period > PERIOD_H1)
|
|
{
|
|
ret = Bars(_Symbol, PERIOD_CURRENT, D'2010.01.01', TimeCurrent());
|
|
return ret;
|
|
}
|
|
//--- 15分足より上は2013年以降
|
|
if(_Period > PERIOD_M15)
|
|
{
|
|
ret = Bars(_Symbol, PERIOD_CURRENT, D'2013.01.01', TimeCurrent());
|
|
return ret;
|
|
}
|
|
//--- それ以下は2016年以降
|
|
ret = Bars(_Symbol, PERIOD_CURRENT, D'2016.01.01', TimeCurrent());
|
|
return ret;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+ |