平均からの乖離
公開日:
:
マネー
平均(移動平均線)からの乖離をトレードシグナルにしていらっしゃる人が結構います。
ということで、乖離率を表示するインディケーターを自作してみました。
ついでに、乖離率の移動平均であるシグナルも表示します。
乖離率の計算に使用する移動平均線の種類も4種類から選べるようにしました。
サブウィンドウが乖離率です。
え、ボリンジャーバンドを見るから要らない!?
プログラムソース
//+------------------------------------------------------------------+
//| yasciiKairi01.mq4
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Orange
#property indicator_color2 Violet
#property indicator_level1 0
//---- input parameters
extern int MA_period = 20;
extern int Sig_period = 9;
extern int MA_method = 0; // SMA(0), EMA(1), SMMA(2), LWMA(3)
//---- buffers
double kairi[];
double kairiX[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
IndicatorShortName("Kairi(" + MA_period + ")");
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, kairi);
SetIndexBuffer(1, kairiX);
SetIndexStyle(1, DRAW_LINE);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int i, j, limit ;
// to prevent possible error
if(counted_bars < 0)
{
return(-1);
}
if(MA_method >= 4)
{
MA_method = 0;
}
limit = Bars - counted_bars;
for(i = limit - MA_period ; i >= 0; i--)
{
double sma20 = iMA(NULL, 0, MA_period, 0 , MA_method , PRICE_CLOSE, i) ;
kairi[i] = 100.0 * (Close[i]- sma20) / sma20 ;
}
for(j = limit - MA_period - Sig_period; j >= 0; j--)
{
kairiX[j] = iMAOnArray(kairi,0,Sig_period,0,MODE_EMA,j);
}
return(0);
}
//+------------------------------------------------------------------+
###
関連記事
-
-
小さな会社が一瞬で顧客とキャッシュをつかむ5つの成功戦略
原題は「Instant Income」、邦題が「小さな会社が一瞬で顧客とキャッシュをつ
-
-
アメリカ株投資 2025-09-11
なぜか好調(?)なアメリカ株の現時点での保有状況がこちら。 項目は 銘柄名 株数
-
-
【FX】ボリンジャーバンドを逆張りで(2)
昨日の記事「【FX】ボリンジャーバンドを逆張りで」の続きです。 本日、バグをつぶして、少し改良
-
-
確定申告やっと終わり
昨日は確定申告書の作成に時間が掛かり、ブログ更新ができませんでした。 本日郵便局から郵送。
-
-
[FX] 来週は yasciiHA04c.ex4 を投入
来週稼働予定の EA をご紹介。 yasciiHA04b.ex4 を改良したものです。
-
-
【FX】高頻度トレーダー(HFT)タイプの EA の評価方法(2)
以前の記事「【FX】高頻度トレーダー(HFT)タイプの EA の評価方法」の続きです。 そこでは高
-
-
2014/12/5 FX 取引サーバー飛んだ!
本日はアメリカの雇用統計が発表の日(第一金曜日ですね)。 お昼は円安トレンドが続き、易々と
-
-
アメリカ株投資 2021-10-18
「アメリカ株投資 2021-9-2」の続きです。 しばらくアメリカ株投資は波乱の日々が
-
-
FX は画像診断なのかも
FX は画像診断に似ているなあと思っています。 画像診断 知識を体系的に仕入れる







