TMAのダウンロードと解説|MT4インジケーター

TMAアイキャッチ
  • URLをコピーしました!

TMAというMT4インジケーターがほしいです。
TMAはどんなインジケーターですか?

ホシノ

FXの不労所得だけで年収2000万を達成しました。
このお悩みに誠意をもって回答します。

BBF_MQL5-202400601
リアルトレード公開|EA BBF

このページでわかること・できること

◯TMAのダウンロード

◯TMAの詳しい解説

目次

TMAのダウンロード

TMAインジケーターのファイルはここからダウンロードできる。
ダウンロードするファイルは.ex4ファイルとなっているため、MT4のインジケーターフォルダへ移動すれば使用可能となる。

TMAインジケーターのインストール

ダウンロードしたTMAインジケーターはMT4のデータフォルダからindicatorsフォルダを探しファイルを移動する。

ファイル>データフォルダを開く>MQL4>indicators

indicatorsフォルダにファイルを移動し、MT4を再起動するとインストールが完了する。

TMAはどんなインジケーターか?

TMAチャート画像
TMA

TMA(Triangular Moving Average、三角移動平均)は、移動平均の一種であり、データの平滑化に用いられる。TMAは、シンプル移動平均(SMA)や指数移動平均(EMA)に比べて滑らかな曲線を描く特徴がある。これは、データの中心部分に重みを置くことによって達成されている。

TMAの基本概念

TMAは通常、移動平均を二度取ることで計算される。つまり、まず価格データの単純移動平均(SMA)を計算し、その後再びそのSMAの移動平均を取ることで得られる。

計算手順

  1. 単純移動平均 (SMA) の計算: 期間[math]n[/math] のSMAは次のように定義される:
    [math]{SMA}_t = \frac{1}{n} \sum_{i=0}^{n-1} P_{t-i}[/math]

    ​ここで、[math]Pt[/math]は時点[math]t[/math]における価格となる。つまり、直近の[math]n[/math]期間の価格の平均を計算する。
  2. 二重移動平均 (TMA) の計算: 次に、SMAのSMAを取ることでTMAを計算する。期間[math]n[/math]のTMAは次のように定義される:
    [math]{TMA}_t = \frac{1}{n} \sum_{i=0}^{n-1} \text{SMA}_{t-i}[/math]

    ​ここで、[math]{SMA}_{t-i}[/math]は時点[math]{t-i}[/math]におけるSMA。つまり、直近[math]n[/math]期間のSMAから平均を計算する。

具体例

期間[math]{n=3}[/math]のTMAを具体例として計算する。

  1. 価格データ: 価格データ[math]P[/math]が次のように与えられているとする:
    [math]P = \{ P_t, P_{t-1}, P_{t-2}, P_{t-3}, P_{t-4}, \ldots \}[/math]
  2. SMAの計算: まず、期間3のSMAを計算する:
    [math]{SMA}_t = \frac{1}{3} (P_t + P_{t-1} + P_{t-2})[/math]

    [math]{SMA}_{t-1} = \frac{1}{3} (P_{t-1} + P_{t-2} + P_{t-3})[/math]

    [math]{SMA}_{t-2} = \frac{1}{3} (P_{t-2} + P_{t-3} + P_{t-4})[/math]

  3. TMAの計算: 次に、これらのSMAを使ってTMAを計算する:
    [math]{TMA}_t = \frac{1}{3} (\text{SMA}_t + \text{SMA}_{t-1} + \text{SMA}_{t-2})[/math]

    具体的な値を代入すると:
    [math]{TMA}_t = \frac{1}{3} \left( \frac{1}{3} (P_t + P_{t-1} + P_{t-2}) + \frac{1}{3} (P_{t-1} + P_{t-2} + P_{t-3}) + \frac{1}{3} (P_{t-2} + P_{t-3} + P_{t-4}) \right)[/math]

    この式を簡略化すると:
    [math]{TMA}_t = \frac{1}{9} (P_t + 2P_{t-1} + 3P_{t-2} + 2P_{t-3} + P_{t-4})[/math]

まとめ

TMAの計算は次の手順で行う:

  1. 指定した期間[math]n[/math]の価格データの単純移動平均 (SMA) を計算する。
  2. 得られたSMAの値を使い、再度指定した期間[math]n[/math]の単純移動平均 (SMAのSMA) を計算する。

TMAは、通常の単純移動平均よりも平滑化されており、価格のトレンドをより滑らかに表示する。そのため、価格の短期的な変動に左右されず、より長期的なトレンドの把握に適している。

TMAのプログラム

//+------------------------------------------------------------------+
//|                                                          TMA.mq4 |
//|                                     Copyright 2024, FX-Bonus.net |
//|                                            https://fx-bonus.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, FX-Bonus.net"
#property link      "https://fx-bonus.net/"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property strict

//--- input parameters
input int Period = 14; // TMA period
input color LineColor = clrMagenta; // Line color parameter

//--- indicator buffers
double TmaBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   //--- indicator buffers mapping
   SetIndexBuffer(0, TmaBuffer);

   //--- setting the indicator name and drawing properties
   IndicatorShortName("TMA(" + IntegerToString(Period) + ")");
   SetIndexLabel(0, "TMA");
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, LineColor); // Use the LineColor parameter
   SetIndexDrawBegin(0, Period - 1);

   //--- set the indicator to calculate values for each tick
   IndicatorDigits(Digits);

   //---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   //--- cleanup code
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   //--- check if enough bars
   if (rates_total < Period) return(0);

   int begin = 0;
   if (prev_calculated > 0) begin = prev_calculated - 1;

   //--- calculate TMA
   for (int i = begin; i < rates_total; i++)
     {
      double sum = 0.0;
      int count = 0;
      for (int j = i; j >= i - Period + 1 && j >= 0; j--)
        {
         sum += close[j];
         count++;
        }
      TmaBuffer[i] = sum / count;
     }

   //--- return the number of calculated bars
   return(rates_total);
  }
//+------------------------------------------------------------------+

ソースコードを詳しく解説

このコードは、MetaTrader 4 (MT4) で動作するカスタムインジケーターを作成するためのMQL4プログラムだ。インジケーターは、Triple Moving Average (TMA) を計算し、チャート上に描画する。以下に各部分の詳細な説明を示す。

各部分の説明

プロパティ設定

#property strict
#property indicator_chart_window
  • #property strict は、厳密な型チェックを有効にする。
  • #property indicator_chart_window は、インジケーターの描画をチャートウィンドウに指定。

入力パラメータ

input int Period = 14; // TMA period
input color LineColor = clrMagenta; // Line color parameter
  • Period は、TMAの計算に使用する期間を指定。初期値は14。
  • LineColor は、インジケーターラインの色を指定。初期値はマゼンタ。

インジケーターバッファ

double TmaBuffer[];

  • TmaBuffer は、TMAの計算結果を格納するバッファ。

初期化関数 (OnInit)

int OnInit()
  {
   //--- indicator buffers mapping
   SetIndexBuffer(0, TmaBuffer);

   //--- setting the indicator name and drawing properties
   IndicatorShortName("TMA(" + IntegerToString(Period) + ")");
   SetIndexLabel(0, "TMA");
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, LineColor); // Use the LineColor parameter
   SetIndexDrawBegin(0, Period - 1);

   //--- set the indicator to calculate values for each tick
   IndicatorDigits(Digits);

   //---
   return(INIT_SUCCEEDED);
  }
  • SetIndexBuffer(0, TmaBuffer) は、インジケーターバッファをチャートにマッピングする。
  • IndicatorShortName("TMA(" + IntegerToString(Period) + ")") は、インジケーターの名前を設定。
  • SetIndexLabel(0, "TMA") は、インジケーターラインのラベルを設定。
  • SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2, LineColor) は、インジケーターラインのスタイルと色を設定。LineColor パラメータを使用している。
  • SetIndexDrawBegin(0, Period - 1) は、インジケーターの描画開始位置を設定。
  • IndicatorDigits(Digits) は、計算結果の小数点以下の桁数を設定。

終了関数 (OnDeinit)

void OnDeinit(const int reason)
  {
   //--- cleanup code
  }
  • OnDeinit 関数は、インジケーターが削除されるときのクリーンアップコードを含む。必要に応じてクリーンアップ処理が追加可能。

計算関数 (OnCalculate)

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[])
  {
   //--- check if enough bars
   if (rates_total < Period) return(0);

   int begin = 0;
   if (prev_calculated > 0) begin = prev_calculated - 1;

   //--- calculate TMA
   for (int i = begin; i < rates_total; i++)
     {
      double sum = 0.0;
      int count = 0;
      for (int j = i; j >= i - Period + 1 && j >= 0; j--)
        {
         sum += close[j];
         count++;
        }
      TmaBuffer[i] = sum / count;
     }

   //--- return the number of calculated bars
   return(rates_total);
  }
  • rates_total は、利用可能なバーの総数。
  • prev_calculated は、前回計算されたバーの数。
  • 各配列 (time[], open[], high[], low[], close[], tick_volume[], volume[], spread[]) は、バーごとのデータを含む。
  1. if (rates_total < Period) return(0);:
    • データのバーの数が Period より少ない場合、計算を終了。
  2. int begin = 0; if (prev_calculated > 0) begin = prev_calculated - 1;:
    • 計算の開始位置を設定。前回計算されたバーがある場合、1つ前から開始。
  3. for (int i = begin; i < rates_total; i++):
    • 利用可能な全てのバーに対してループを実行。
  4. 内側のループでTMAを計算:
    double sum = 0.0; int count = 0; for (int j = i; j >= i - Period + 1 && j >= 0; j--) { sum += close[j]; count++; } TmaBuffer[i] = sum / count;
    • sum は指定された期間の価格の合計。
    • count は実際に計算に使用された価格の数。
    • 期間内の価格を合計し、その平均を TmaBuffer に格納。
  5. return(rates_total);:
    • 計算されたバーの数を返す。

このインジケーターは、指定された期間の価格の移動平均を二度計算することでTMAを求め、それをチャート上に描画。ユーザーはパラメーター画面で期間と線の色が設定可能。

MT4インジケーターまとめ

  • URLをコピーしました!
  • URLをコピーしました!

このEAを使って、将来の見通しが立ちました

収入を増やしたい、将来のための資産が欲しい、支払いに縛られない自由な生活がしたい

このEAを使うと将来が見通せます。

22年以上で無敗の安定取引。リスク0%運用も可能なロジック。年利100%越えの上級者向け取引も可能。

マネーマシンとして育て上げることで大きな不労所得を得られます。

BBF-Girl
ドリームEA_BBF 無料ダウンロード
BBF_MQL5-202400601
リアルトレード公開|EA BBF

ポジション監視の時間

集中力は続いてますか?


オートクローズツールを使ってポジション管理を自動化


自動ポジション管理だから万が一でも大丈夫

あなたは空いた時間を自由に、効率的に使えます

自動決済ルールは独自にカスタム可能

ストップ、リミット変更にも対応。

エントリー後のポジション管理をすべて自動化できるトレーディングサポートツール。

トレード中のちょっとした離席など、念のためセットといった使い方も可能。

MT4用自動決済ツール【AutoCloseTool】は無料で入手できます。

オートクローズツール

取引ごとにキャッシュバックが発生します

もらわないだけ損している
取引ごとに毎回発生する現金のキャッシュバック
海外FXのキャッシュバックはメリットしかないサービスです

取引ごとにキャッシュバック
目次