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

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

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

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

Q&A

0回答

171閲覧

MQL4についての質問です。カスタムインジケーターを作成中なのですが、アローが上手くでないです。

macky_zzz

総合スコア0

MQL4

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

0グッド

0クリップ

投稿2024/04/08 15:15

実現したいこと

・BB1σ外に移動平均線期間100がローソク足50本分以上推移した後に、BB内に移動平均線が入ってきた時にアラート&アローを出したいです。

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

・bool関数を設定しているのですが上手くアローが表示されないです。

該当のソースコード

MQL4

1#property strict 2#property indicator_chart_window 3#property indicator_buffers 2 4 5#property indicator_color1 clrRed // 6#property indicator_color2 clrRed // 7 8#property indicator_width1 3 // 9#property indicator_width2 3 // 10 11extern string ___音声アラート・ポップ___="-----音声アラート&ポップ表示欄-----"; 12extern bool alert = true; //音声アラートのon/off 13extern bool push = true; //ポップ表示のon/off 14extern bool haikei = true; //背景変化お知らせon/off 15 16extern string ****時間****="・・・・・時間制御・・・・・"; 17extern ENUM_TIMEFRAMES period_15M=PERIOD_M15;//時間足設定 18 19extern string ****移動平均線****="・・・・・移動平均線制御・・・・・"; 20input int ma_l_MA_period = 200; //長期MA期間 21input int ma_vl_MA_period = 480; //超長期MA期間 22extern ENUM_MA_METHOD ma_mode = MODE_EMA; //MAモード 23 24extern string ****RSI****="・・・・・RSI制御・・・・・"; 25input double RSI_UP_line = 70; //RSIの上限ライン 26input double RSI_DOWN_line = 30; //RSIの下限ライン 27input double RSI_center_line = 50; //RSIの中央ライン 28input int RSI_period = 14; //RSIの期間 29 30extern string ****ボリンジャーバンド****="・・・・・ボリバン制御・・・・・"; 31extern int BB_period = 20; //BBの期間 32extern double BB_1_deviation = 1.0; //1σBBの偏差 33extern double BB_2_deviation = 2.0; //2σBBの偏差 34extern string ****ローソク足****="・・・・・ローソク足制御・・・・・"; 35extern int kankaku = 3; //アロー連続表示制御 36extern int Maxbars = 50000; //ローソク足計算本数(7200→1ヶ月) 37extern int limitation = 100; //ローソク足計算の本数 38extern ENUM_BASE_CORNER labelcorner = CORNER_LEFT_LOWER; //ラベル位置 39extern int labelsize = 20; //ラベルサイズ 40extern double pips = 10; //アロー位置調整 41extern int cognitoBars = 0; //スパン調整 42extern string Note1 = ""; 43 44//+------------------------------------------------------------------+ 45//| 変数定義 | 46//+------------------------------------------------------------------+ 47double up_entry_true_1[], down_entry_true_1[]; 48int begin_shift; 49int last_shift; 50 51int NowBars, RealBars, a, b, i, p, q; 52bool upentryflag_1, downentryflag_1 = false; 53//+------------------------------------------------------------------+ 54//| | 55//+------------------------------------------------------------------+ 56int OnInit() 57 { 58 IndicatorBuffers(2); 59 60 SetIndexBuffer(0, up_entry_true_1); 61 SetIndexBuffer(1, down_entry_true_1); 62 63 SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID); 64 SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID); 65 66 SetIndexArrow(0, 233); 67 SetIndexArrow(1, 234); 68 return(INIT_SUCCEEDED); 69 } 70//+------------------------------------------------------------------+ 71//| | 72//+------------------------------------------------------------------+ 73int OnCalculate(const int rates_total, 74 const int prev_calculated, 75 const datetime &time[], 76 const double &open[], 77 const double &high[], 78 const double &low[], 79 const double &close[], 80 const long &tick_volume[], 81 const long &volume[], 82 const int &spread[]) 83 { 84 int limit = Bars - IndicatorCounted() - 1; 85 limit = MathMin(limit, Maxbars); 86 for(int shift = limit; shift >= 0; shift--) 87 { 88 //15分足 89 int bar_M15 = iBarShift(Symbol(), PERIOD_M15, Time[shift]); 90 91 double open_15M_3 = iOpen(Symbol(), period_15M, bar_M15+3); 92 double close_15M_3 = iClose(Symbol(), period_15M, bar_M15+3); 93 double open_15M_2 = iOpen(Symbol(), period_15M, bar_M15+2); 94 double close_15M_2 = iClose(Symbol(), period_15M, bar_M15+2); 95 double open_15M_1 = iOpen(Symbol(), period_15M, bar_M15+1); 96 double close_15M_1 = iClose(Symbol(), period_15M, bar_M15+1); 97 double open_15M_0 = iOpen(Symbol(), period_15M, bar_M15); 98 double close_15M_0 = iClose(Symbol(), period_15M, bar_M15); 99 100 double ma_l_15M_0 = iMA(NULL, period_15M, ma_l_MA_period, 0, MODE_EMA, PRICE_CLOSE, bar_M15); 101 double ma_l_15M_1 = iMA(NULL, period_15M, ma_l_MA_period, 0, MODE_EMA, PRICE_CLOSE, bar_M15+1); 102 double ma_l_15M_2 = iMA(NULL, period_15M, ma_l_MA_period, 0, MODE_EMA, PRICE_CLOSE, bar_M15+2); 103 double ma_l_15M_3 = iMA(NULL, period_15M, ma_l_MA_period, 0, MODE_EMA, PRICE_CLOSE, bar_M15+3); 104 105 double BB1_UP_15M_0 = iBands(Symbol(), period_15M, BB_period, BB_1_deviation, 0, PRICE_CLOSE, MODE_UPPER, bar_M15); 106 double BB1_DOWN_15M_0 = iBands(Symbol(), period_15M, BB_period, BB_1_deviation, 0, PRICE_CLOSE, MODE_LOWER, bar_M15); 107 double BB1_UP_15M_1 = iBands(Symbol(), period_15M, BB_period, BB_1_deviation, 0, PRICE_CLOSE, MODE_UPPER, bar_M15+1); 108 double BB1_DOWN_15M_1 = iBands(Symbol(), period_15M, BB_period, BB_1_deviation, 0, PRICE_CLOSE, MODE_LOWER, bar_M15+1); 109 110 double RSI_15M_0 = iRSI(NULL, period_15M, RSI_period, PRICE_CLOSE, bar_M15); 111 double RSI_15M_1 = iRSI(NULL, period_15M, RSI_period, PRICE_CLOSE, bar_M15+1); 112 113 up_entry_true_1[shift] = EMPTY_VALUE; 114 down_entry_true_1[shift] = EMPTY_VALUE; 115//+------------------------------------------------------------------+ 116//| | 117//+------------------------------------------------------------------+ 118 //現在足の集計 119 if(shift == 0) 120 { 121 up_entry_true_1[shift] = EMPTY_VALUE; 122 down_entry_true_1[shift] = EMPTY_VALUE; 123 124 if(a >= kankaku && Period() == period_15M && (isBB_MA_GreaterAll(i + 1,i + 50))) 125 { 126 up_entry_true_1[shift] = Low[shift] - pips * Point; 127 if(haikei == true) 128 { 129 ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrOrange); 130 } 131 if(cognitoBars < Bars) 132 { 133 if(alert == true) 134 { 135 Alert(Symbol()+" UP Sign"); 136 cognitoBars = Bars; 137 } 138 if(push == true) 139 { 140 SendNotification(Symbol()+" UP Sign"); 141 } 142 } 143 } 144 else 145 { 146 ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrBlack); 147 } 148 if(b >= kankaku && Period() == period_15M && (isBB2_MA_GreaterAll(i + 1,i + 50))) 149 { 150 down_entry_true_1[shift] = High[shift] + pips * Point; 151 if(haikei == true) 152 { 153 ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrOrange); 154 } 155 if(cognitoBars < Bars) 156 { 157 if(alert == true) 158 { 159 Alert(Symbol()+" DOWN Sign"); 160 cognitoBars = Bars; 161 } 162 if(push == true) 163 { 164 SendNotification(Symbol()+" DOWN Sign"); 165 } 166 } 167 } 168 } 169 else 170 { 171 ChartSetInteger(0, CHART_COLOR_BACKGROUND, clrBlack); 172 } 173//+------------------------------------------------------------------+ 174//| | 175//+------------------------------------------------------------------+ 176 //過去足の集計 177 if(shift > 1 || (shift == 1 && NowBars < Bars)) 178 { 179 NowBars = Bars; 180 a++; 181 b++; 182 if(a >= kankaku && Period() == period_15M && (isBB_MA_GreaterAll(i + 1,i + 50))) 183 { 184 up_entry_true_1[shift] = Low[shift] - pips * Point; 185 upentryflag_1 = true; 186 a = 0; 187 } 188 189 if(b >= kankaku && Period() == period_15M && (isBB2_MA_GreaterAll(i + 1,i + 50))) 190 { 191 down_entry_true_1[shift] = High[shift] + pips * Point; 192 downentryflag_1 = true; 193 b = 0; 194 } 195 } 196 } 197 return(rates_total); 198 } 199//+------------------------------------------------------------------+ 200//| | 201//+------------------------------------------------------------------+ 202bool isBB_MA_GreaterAll(int begin_shift, int last_shift) 203 { 204 for(int i=begin_shift; i<=last_shift;i++) 205 { 206 double ma_0 = iMA(NULL, PERIOD_CURRENT, 100, 0, MODE_EMA, PRICE_CLOSE, i); 207 double BB_UP_0 = iBands(Symbol(), PERIOD_CURRENT, 14, 1.0, 0, PRICE_CLOSE, MODE_UPPER, i); 208 if(!(ma_0 > BB_UP_0))return false;//どれかが大きくない時 209 } 210 return true;//全部大きかった時 211 }; 212//+------------------------------------------------------------------+ 213//| | 214//+------------------------------------------------------------------+ 215bool isBB2_MA_GreaterAll(int begin_shift, int last_shift) 216 { 217 for(int i=begin_shift; i<=last_shift;i++) 218 { 219 double ma_1 = iMA(NULL, PERIOD_CURRENT, 100, 0, MODE_EMA, PRICE_CLOSE, i); 220 double BB_Down_15M_0 = iBands(Symbol(), PERIOD_CURRENT, 14, 1.0, 0, PRICE_CLOSE, MODE_LOWER, i); 221 if((ma_1 < BB_Down_15M_0))return false;//どれかが大きくない時 222 } 223 return true;//全部大きかった時 224 }; 225//+------------------------------------------------------------------+ 226//| | 227//+------------------------------------------------------------------+ 228int deinit() 229 { 230 for(int shift = ObjectsTotal()-1; 0<= shift; shift--) 231 { 232 string ObjName = ObjectName(shift); 233 if(StringFind(ObjName, "counttotal") >=0) 234 ObjectDelete(ObjName); 235 } 236 Comment(""); 237 return(0); 238 } 239//+------------------------------------------------------------------+

どなたか、MQLについて知識が豊富な方、ご助力をお願い致します。
関数がおかしいのか、はたまた別の場所に問題があるなど教えていただけたら幸いです。
よろしくお願い致します。

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

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

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

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

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

mah

2024/04/11 18:04

isBB_MA_GreaterAllとisBB2_MA_GreaterAllに渡す引数はiではなくshiftなのではないでしょうか。 あと、上記関数の判定のどちらかが判定が逆になっているような気が。 >BB1σ外に移動平均線期間100がローソク足50本分以上推移した後に、BB内に移動平均線が入ってきた時に とありますが、「BB1σ外に移動平均線期間100がローソク足50本分以上推移した」時点で関数はtrueを返すので、 BB内に移動平均線が入ってきた時にtrueにしたい場合は処理を変える必要があります。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問