double iCustom( string symbol, // 通貨ペア int timeframe, // 時間軸 string name // コンパイルしたカスタムインジケータプログラム名(ファイルパス付) ... // カスタムインジケータの入力パラメータ(必要な場合) int mode // ラインインデックス int shift // shift );
引数名 | 初期値 | I/O | 詳細 |
symbol | - | In | インジケータ計算するデータの通貨ペア名。
NULLは現在の通貨ぺアを意味します。 |
timeframe | - | In | 時間軸。
ENUM_TIMEFRAMES列挙の値を指定します。 0は現在の時間軸を意味します。 |
name | - | In | コンパイルされたカスタムインジケータプログラム名。
インジケータディレクトリ(\MQL4\Indicators)から検索されます。 サブディレクトリに配置されている場合は、"サブディレクトリ名\\カスタムインジケータ名"で指定します。 |
... | - | In | カスタムインジケータの入力パラメータ。 渡された入力パラメータの順序は、カスタムインジケータの宣言順に対応させる必要があります。 |
mode | - | In | ラインインデックス。
0~7の範囲で指定できます。 SetIndexBuffer()関数で指定したインデックスと一致する必要があります。 |
shift | - | In | インジケータバッファから取得する値のインデックス。
(現在バーを基準にして、指定した時間軸のバー数分を過去方向へシフト) |
//+------------------------------------------------------------------+ //| test_ind.mq4 | //| yuki | //| https://yukifx.web.fc2.com/ | //+------------------------------------------------------------------+ #property strict // strictは絶対に削除しない事 // インジケータウインドウ設定 #property indicator_separate_window // インジケータをサブウインドウに表示 #property indicator_minimum -1000 // サブウインドウのスケール下限:-1000 #property indicator_maximum 3500 // サブウインドウのスケール上限: 3500 // インジケータ設定 #property indicator_buffers 2 // インジケータバッファ:2つに設定 #property indicator_color1 clrGreen // インジケータ1の色:Green #property indicator_color2 clrWhite // インジケータ2の色:White #property indicator_width1 2 // インジケータ1の太さ:2 #property indicator_width2 1 // インジケータ2の太さ:1 #property indicator_type1 DRAW_HISTOGRAM // インジケータ1の種類:ヒストグラム #property indicator_type2 DRAW_LINE // インジケータ2の種類:線 // レベルライン設定 #property indicator_level1 0 // レベルライン:0 #property indicator_level2 1000 // レベルライン:1000 #property indicator_level3 2000 // レベルライン:2000 #property indicator_level4 3000 // レベルライン:3000 #property indicator_levelcolor clrGray // レベルラインの色:Gray #property indicator_levelwidth 1 // レベルラインの太さ:1 #property indicator_levelstyle STYLE_DOT // レベルラインの種類:ドット線 double ExIndLine[]; // インジケータバッファ:出来高平均値用 double ExIndVol[]; // インジケータバッファ:出来高生値用 // 入力パラメータ sinput int VolumeAvePeriod = 10; // 出来高の平均期間 //+------------------------------------------------------------------+ //| OnInit(初期化)イベント | //|------------------------------------------------------------------| void OnInit() { SetIndexBuffer(0,ExIndVol); // ExIndVolをインジケータ1に登録 SetIndexBuffer(1,ExIndLine); // ExIndLineをインジケータ2に登録 } //+------------------------------------------------------------------+ //| OnCalculate(tick受信)イベント | //+------------------------------------------------------------------+ 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[], // Tick出来高 const long& volume[], // Real出来高 const int& spread[]) // スプレッド { int icount = 0; int icountend; int vcount = 0; int vcountend; double ave_volume; icountend = rates_total - prev_calculated; if ( icountend >= rates_total ) { icountend = rates_total - 1; } for( icount = 0; icount <= icountend ; icount++ ) { ExIndVol[icount] = (double)tick_volume[icount]; // インジケータバッファに出来高を代入 } // 出来高の移動平均を算出 for( icount = 0; icount <= icountend ; icount++ ) { ave_volume = 0; vcountend = icount + VolumeAvePeriod; if ( vcountend < icountend ) { for( vcount = icount; vcount <= vcountend ; vcount++ ) { ave_volume += ExIndVol[vcount]; } ave_volume = (int)(ave_volume / VolumeAvePeriod); } ExIndLine[icount] = ave_volume; // インジケータバッファに出来高(平均値)を代入 } for( icount = 0; icount <= 20 ; icount++ ) { printf( "\"test_ind\"カスタムインジケータ【入力パラメータ1設定=%d】" "(%s,%d分足)の計算値,出来高生値[%d]=%g,出来高平均[%d]=%g", VolumeAvePeriod, Symbol(), Period(), icount, ExIndVol[icount], icount, ExIndLine[icount] ); } return(rates_total); }
//+------------------------------------------------------------------+ //| test_icustom.mq4 | //| yuki | //| https://yukifx.web.fc2.com/ | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| 初期化イベント //|------------------------------------------------------------------| void OnInit() { double get_volume; double get_volume_ma; string cus_symbol = "EURUSD"; int cus_period = PERIOD_M5; string cus_indname = "test_ind"; // iCustomで使用するインジケータ名 int input_para1 = 10; int shift_index = 0; int icount; for (icount = 0 ; icount < 20 ; icount++) { shift_index = icount; get_volume = iCustom( // カスタムインジケータ呼び出し cus_symbol, // 通貨ペア cus_period, // 時間軸 cus_indname, // カスタムインジケータ名 input_para1, // カスタムインジケータの入力パラメータ:1つ目【出来高の移動平均】 0, // カスタムインジケータのインジケータバッファインデックス:【0:出来高生値】 shift_index // バーシフト ); get_volume_ma = iCustom( // カスタムインジケータ呼び出し cus_symbol, // 通貨ペア cus_period, // 時間軸 cus_indname, // カスタムインジケータ名 input_para1, // カスタムインジケータの入力パラメータ:1つ目【出来高の移動平均】 1, // カスタムインジケータのインジケータバッファインデックス:【1:出来高平均値】 shift_index // バーシフト ); printf( "\"%s\"カスタムインジケータ【入力パラメータ1設定=%d】(%s,%d分足)の計算値,出来高生値[%d]=%g,出来高平均[%d]=%g", cus_indname, input_para1, cus_symbol, cus_period, shift_index, get_volume, shift_index, get_volume_ma ); } }
test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[0]=290,出来高平均[0]=176 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[1]=163,出来高平均[1]=183 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[2]=206,出来高平均[2]=193 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[3]=180,出来高平均[3]=188 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[4]=216,出来高平均[4]=193 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[5]=98,出来高平均[5]=197 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[6]=51,出来高平均[6]=206 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[7]=49,出来高平均[7]=222 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[8]=238,出来高平均[8]=247 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[9]=74,出来高平均[9]=242 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[10]=199,出来高平均[10]=262 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[11]=356,出来高平均[11]=270 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[12]=270,出来高平均[12]=263 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[13]=151,出来高平均[13]=280 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[14]=231,出来高平均[14]=280 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[15]=262,出来高平均[15]=277 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[16]=184,出来高平均[16]=276 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[17]=206,出来高平均[17]=288 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[18]=303,出来高平均[18]=325 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[19]=189,出来高平均[19]=345 test_ind EURUSD,M5: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[20]=276,出来高平均[20]=367
test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[0]=290,出来高平均[0]=176 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[1]=163,出来高平均[1]=183 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[2]=206,出来高平均[2]=193 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[3]=180,出来高平均[3]=188 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[4]=216,出来高平均[4]=193 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[5]=98,出来高平均[5]=197 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[6]=51,出来高平均[6]=206 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[7]=49,出来高平均[7]=222 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[8]=238,出来高平均[8]=247 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[9]=74,出来高平均[9]=242 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[10]=199,出来高平均[10]=262 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[11]=356,出来高平均[11]=270 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[12]=270,出来高平均[12]=263 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[13]=151,出来高平均[13]=280 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[14]=231,出来高平均[14]=280 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[15]=262,出来高平均[15]=277 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[16]=184,出来高平均[16]=276 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[17]=206,出来高平均[17]=288 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[18]=303,出来高平均[18]=325 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[19]=189,出来高平均[19]=345 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[19]=189,出来高平均[19]=345 test USDJPY,H1: "test_ind"カスタムインジケータ【入力パラメータ1設定=10】(EURUSD,5分足)の計算値,出来高生値[19]=189,出来高平均[19]=345