素晴らしいインジケーターですね!バッファを使用して同じものを作成しましたが、現在の日だけでなく、各日のサポート・レベルとレジスタンス・レベルをプロットする方法について何かアイデアはありますか?
これが私のバージョンです。しかし、各「現在のタイムフレーム」のバーについて、10日分の日足バーを取得する方法が見つかりません。
//+------------------------------------------------------------------+ //|B_ATR_Levels.mq5 //+------------------------------------------------------------------+ #property copyright "Skullnick" #property link "https://www.mql5.com" #property version "1.00" //--- インジケーター・プロットの設定 #property indicator_chart_window #property indicator_buffers 6 #property indicator_plots 6 #property indicator_type1 DRAW_LINE #property indicator_color1 clrDeepSkyBlue #property indicator_width1 1 #property indicator_label1 "Resistance 1" #property indicator_style1 STYLE_DASH #property indicator_type2 DRAW_LINE #property indicator_color2 clrDeepSkyBlue #property indicator_width2 1 #property indicator_label2 "Resistance 2" #property indicator_style2 STYLE_DASH #property indicator_type3 DRAW_LINE #property indicator_color3 clrDeepSkyBlue #property indicator_width3 1 #property indicator_label3 "Resistance 3" #property indicator_style3 STYLE_DASH #property indicator_type4 DRAW_LINE #property indicator_color4 clrOrangeRed #property indicator_width4 1 #property indicator_label4 "Support 1" #property indicator_style4 STYLE_DASH #property indicator_type5 DRAW_LINE #property indicator_color5 clrOrangeRed #property indicator_width5 1 #property indicator_label5 "Support 2" #property indicator_style5 STYLE_DASH #property indicator_type6 DRAW_LINE #property indicator_color6 clrOrangeRed #property indicator_width6 1 #property indicator_label6 "Support 3" #property indicator_style6 STYLE_DASH //--- 入力 input int inpAtrPeriod = 21; // ATR期間 //--- インジケータ・バッファ double ExtR1Buffer[]; double ExtR2Buffer[]; double ExtR3Buffer[]; double ExtS1Buffer[]; double ExtS2Buffer[]; double ExtS3Buffer[]; // 平均トゥルー・レンジの重み double dWeights[]; // グローバル変数 double dATR = 0; double dPreviousClose = 0; //+------------------------------------------------------------------+ //| カスタムインジケータ初期化関数 //+------------------------------------------------------------------+ int OnInit() { //--- インジケータ・バッファのマッピング SetIndexBuffer(0,ExtR1Buffer, INDICATOR_DATA); // 抵抗レベル1 SetIndexBuffer(1,ExtR2Buffer, INDICATOR_DATA); // 抵抗レベル2 SetIndexBuffer(2,ExtR3Buffer, INDICATOR_DATA); // 抵抗レベル3 SetIndexBuffer(3,ExtS1Buffer, INDICATOR_DATA); // サポートレベル1 SetIndexBuffer(4,ExtS2Buffer, INDICATOR_DATA); // サポートレベル2 SetIndexBuffer(5,ExtS3Buffer, INDICATOR_DATA); // サポートレベル3 ArraySetAsSeries(ExtR1Buffer, true); ArraySetAsSeries(ExtR2Buffer, true); ArraySetAsSeries(ExtR3Buffer, true); ArraySetAsSeries(ExtS1Buffer, true); ArraySetAsSeries(ExtS2Buffer, true); ArraySetAsSeries(ExtS3Buffer, true); // ウェイトのサイズ変更 ArrayResize(dWeights, inpAtrPeriod); // スムージングを設定する double dSmoothing = 2.0 / (ArraySize(dWeights) + 1); // ウェイト計算 for(int i = 0; i < ArraySize(dWeights); i++) dWeights[i] = dSmoothing * MathPow(1 - dSmoothing, i); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| カスタム・インジケータ反復関数| //+------------------------------------------------------------------+ 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[]) { //--- // デイリーデータを取得し、十分なデータがあるかチェックする MqlRates oDailyRates[]; ArraySetAsSeries(oDailyRates, true); int iLast = 0; if(prev_calculated == 0) iLast = rates_total - 1; else iLast = rates_total - prev_calculated; //--- レベルを計算する for(int i = iLast; i >= 0 && !IsStopped();i--) { int iNumDaysCopied = CopyRates(_Symbol, PERIOD_D1, 1, inpAtrPeriod + 1, oDailyRates); if(iNumDaysCopied >= (inpAtrPeriod+1) && bIsNewDay() == true) { // その日のATRを計算する dATR = dCalculateATR(oDailyRates); dPreviousClose = oDailyRates[0].close; } ExtR1Buffer[i] = dPreviousClose + 0.5 * dATR; ExtR2Buffer[i] = dPreviousClose + 0.75 * dATR; ExtR3Buffer[i] = dPreviousClose + 1.0 * dATR; ExtS1Buffer[i] = dPreviousClose - 0.5 * dATR; ExtS2Buffer[i] = dPreviousClose - 0.75 * dATR; ExtS3Buffer[i] = dPreviousClose - 1.0 * dATR; } //--- 次の呼び出しのためにprev_calculatedの値を返す return(rates_total); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| ATRを計算する| //+------------------------------------------------------------------+ double dCalculateATR(const MqlRates &oRates[]) { double dValue = 0; int iIndex = 0; for (int i = 0; i < ArraySize(dWeights); i++) { double dHL = oRates[i].high - oRates[i].low; double dHCp = MathAbs(oRates[i].high - oRates[i+1].close); double dLCp = MathAbs(oRates[i].low - oRates[i+1].close); double dTR = MathMax(MathMax(dHL, dHCp),dLCp); dValue += dTR * dWeights[iIndex]; iIndex++; } return dValue; } //----------------------------- // チェック・ニュー・デイ //----------------------------- bool bIsNewDay(void) { bool bNewDay = false; static datetime oDateOld; datetime oDateNew[1]; MqlDateTime oStructDateOld; MqlDateTime oStructDateNew; // 現在時刻の配列をNew_Timeにコピーする。 int iCopyHandle = CopyTime(_Symbol, PERIOD_D1, 0, 1, oDateNew); TimeToStruct(oDateNew[0] , oStructDateNew); TimeToStruct(oDateOld , oStructDateOld); // コピーに成功した場合 if(iCopyHandle>0) { // イフ・ニュー・デイ if(oStructDateNew.day != oStructDateOld.day) { bNewDay = true; oDateOld = oDateNew[0]; } } return bNewDay; }
これのMT4バージョンをお願いします。
xy618z 水平線を 短い水平線に変更し、右側のみを表示する方法。
こんにちは
水平線を作成するには
ObjectCreate(0,_name,OBJ_HLINE,0,0,0);
開始時間+'n'ピリオドを停止時間にしてください。
水平線は常にチャート全体に広がります - 時間パラメータで制限することはできません :https://www.mql5.com/ja/docs/constants/objectconstants/enum_object/obj_hline
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_HLINE
- www.mql5.com
OBJ_HLINE - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
ありがとう。
コンパイルできないエラーが4つある
取引の機会を逃しています。
- 無料取引アプリ
- 8千を超えるシグナルをコピー
- 金融ニュースで金融マーケットを探索

ATR確率レベル:
ATRに基づいた確率レベルです。「確率」は、予測されたATRと前の期間の終値に基づいて計算されます。
作者: Mladen Rakic