質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MQL4

MQL4とは、MT4(MetaTrader4)で用いられるプログラム言語です。MT4は無料で使えるチャートソフトあり、MQL4を使うことで分析ツールのオリジナルスクリプトの作成ができます。

MQL

MQL(Meta Quotes Language)は、Meta Trader4(MT4)で用いられるプログラミング用語です。MQLによりEAやインジケーターの作成が可能。C言語で書かれているため、C言語の知識があれば簡単に扱うことができます。

Q&A

解決済

1回答

1731閲覧

MQL4でチャート上にRSIの値をラベルとして表示させたい。

harawan

総合スコア1

MQL4

MQL4とは、MT4(MetaTrader4)で用いられるプログラム言語です。MT4は無料で使えるチャートソフトあり、MQL4を使うことで分析ツールのオリジナルスクリプトの作成ができます。

MQL

MQL(Meta Quotes Language)は、Meta Trader4(MT4)で用いられるプログラミング用語です。MQLによりEAやインジケーターの作成が可能。C言語で書かれているため、C言語の知識があれば簡単に扱うことができます。

0グッド

0クリップ

投稿2020/09/30 18:04

前提・実現したいこと

高値安値を取得した後に、その高値安値の位置(時間)にあるRSIの値を取得して、
その値をラベルとしてチャート上に表示させたいのですが、
なぜかRSIの値を取得することができません・・・。

ちなみに、高値安値の値は、ラベルとしてチャートに表示されました。

コメントアウトしているRSIバッファのところはいろいろ試した結果できませんでした。

発生している問題・エラーメッセージ

エラーは出ていません。

該当のソースコード

mql4

1#property copyright "Copyright 2020, MetaQuotes Software Corp." 2#property link "https://www.mql5.com" 3#property version "1.00" 4#property strict 5#property indicator_chart_window 6 7#property indicator_buffers 5 8#property indicator_color1 clrYellow 9#property indicator_width1 2 10#property indicator_color2 clrYellow 11#property indicator_width2 2 12#property indicator_color3 clrYellow 13#property indicator_width3 2 14 15extern int BBPeriod = 10; //期間 16extern int RSI_Period = 14; //RSI期間 17 18extern bool boolPriceLabel = true; //RSI数値ラベル表示オン 19extern color PriceLabelColor = clrWhite; //色 20extern int PriceLabelWidth = 1; //大きさ 21 22//インジケーターバッファ 23double ZigzagHighBuffer[]; 24double ZigzagLowBuffer[]; 25double RSI[]; 26string indiName = "RSI"; 27//+------------------------------------------------------------------+ 28//| Custom indicator initialization function | 29//+------------------------------------------------------------------+ 30int OnInit() 31 { 32//--- indicator buffers mapping 33 IndicatorBuffers(3); 34 35 SetIndexStyle(0, DRAW_SECTION); 36 SetIndexBuffer(0, ZigzagHighBuffer, INDICATOR_DATA); 37 ArraySetAsSeries(ZigzagHighBuffer, true); 38 ArrayInitialize(ZigzagHighBuffer, EMPTY_VALUE); 39 40 SetIndexStyle(1, DRAW_SECTION); 41 SetIndexBuffer(1, ZigzagLowBuffer, INDICATOR_DATA); 42 ArraySetAsSeries(ZigzagLowBuffer, true); 43 ArrayInitialize(ZigzagLowBuffer, EMPTY_VALUE); 44 45 SetIndexStyle(2, DRAW_LINE); 46 SetIndexBuffer(2, RSI); 47 ArraySetAsSeries(RSI, true); 48 ArrayInitialize(RSI, EMPTY_VALUE); 49 50 51//--- 52 return(INIT_SUCCEEDED); 53 } 54//+------------------------------------------------------------------+ 55//| Custom indicator iteration function | 56//+------------------------------------------------------------------+ 57int OnCalculate(const int rates_total, 58 const int prev_calculated, 59 const datetime &time[], 60 const double &open[], 61 const double &high[], 62 const double &low[], 63 const double &close[], 64 const long &tick_volume[], 65 const long &volume[], 66 const int &spread[]) 67 { 68//--- 69 int limit = rates_total - prev_calculated; 70 71 if(limit>0){ 72 limit = rates_total - BBPeriod -1; 73 } 74 75 int flag = 1; 76 int index = rates_total - 1; 77 78 for(int i=limit; i>=0; i--){ 79 80 ZigzagHighBuffer[i] = EMPTY_VALUE; 81 ZigzagLowBuffer[i] = EMPTY_VALUE; 82 83 //RSI[i] = iRSI(Symbol(),0,RSI_Period,PRICE_CLOSE,i); 84 85 double upBand = iBands(NULL, 0, BBPeriod, 1, 0, PRICE_HIGH, MODE_UPPER, i); 86 double lowBand = iBands(NULL, 0, BBPeriod, 1, 0, PRICE_LOW, MODE_LOWER, i); 87 88 89 if(lowBand > Low[i] && upBand < High[i]) continue; 90 91 if(flag > 0 && lowBand > Low[i]){ 92 93 index = iHighest(NULL, 0, MODE_HIGH, index-i, i); 94 95 ZigzagHighBuffer[index] = High[index]; 96 97 flag = -1; 98 } 99 100 if(flag < 0 && upBand < High[i]){ 101 102 index = iLowest(NULL, 0, MODE_LOW, index-i, i); 103 104 ZigzagLowBuffer[index] = Low[index]; 105 106 flag = 1; 107 } 108 } 109 110 for(int j=limit; j>=0; j--) 111 { 112 RSI[j] = iRSI(Symbol(),0,RSI_Period,PRICE_CLOSE,j); 113 } 114 115 if(limit>1) 116 { 117 for(int t=0; t<rates_total; t++) 118 { 119 //RSI[t] = iCustom(Symbol(),0,"Relative Strength Index",RSI_Period,PRICE_CLOSE,0,t); 120 121 if(ZigzagHighBuffer[t] != EMPTY_VALUE) 122 { 123 if(boolPriceLabel) 124 { 125 Label(indiName+IntegerToString(t), t, RSI[t], PriceLabelColor, PriceLabelWidth, true); 126 } 127 } 128 129 if(ZigzagLowBuffer[t] != EMPTY_VALUE) 130 { 131 if(boolPriceLabel) 132 { 133 Label(indiName+IntegerToString(t), t, RSI[t], PriceLabelColor, PriceLabelWidth, true); 134 } 135 } 136 } 137 } 138 139 140 141 142 143//--- return value of prev_calculated for next call 144 return(rates_total); 145 } 146//+------------------------------------------------------------------+ 147 148//+------------------------------------------------------------------+ 149//|ラベルを付与。 150//+-------------------------------------------------------------------+ 151void Label(string Label_name, int position, double price, color Label_color, int Label_width, bool boolRight){ 152 153 long current_chart_id = ChartID(); 154 155 if (ObjectFind(Label_name) >= 0) ObjectDelete(current_chart_id, Label_name); 156 157 if(boolRight) ObjectCreate(current_chart_id, Label_name, OBJ_ARROW_RIGHT_PRICE, 0, Time[position], price); 158 else ObjectCreate(current_chart_id, Label_name, OBJ_ARROW_LEFT_PRICE, 0, Time[position], price); 159 160 ObjectSetInteger(current_chart_id, Label_name, OBJPROP_COLOR, Label_color); 161 ObjectSetInteger(current_chart_id, Label_name, OBJPROP_WIDTH, Label_width); 162 ObjectSetInteger(current_chart_id, Label_name, OBJPROP_SELECTABLE, false); 163 ObjectSetInteger(current_chart_id, Label_name, OBJPROP_HIDDEN, true); 164}

試したこと

コメントアウトしているRSIバッファのところはいろいろ試した結果できませんでした。
ちなみに、高値安値の値はラベルとしてチャート上に表示されました。

補足情報(FW/ツールのバージョンなど)

MT4、MQL4。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

RSIの値をObjectCreateに渡しているため、ラベルがチャートの範囲外になっているのではないでしょうか。
NZDJPYやAUDJPYに表示してみるとわかりやすいです。

任意の位置にRSIの値を表示するのであればOBJ_TEXTを使うことになると思います。

投稿2020/09/30 20:27

mah

総合スコア591

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

harawan

2020/10/02 09:20

ご回答ありがとうございます! 少し時間がかかってしまいましたが、 表示することができました。ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問