子猫に大判!
節約と投資のかけ算
開発

RSI、色の変わるインジケーターの作成

RSIの色の変わるインジケーターを作ったのでコードを公開します。

なお、開発環境はMQL4です。

このインジケーターを入れると下記のようになります。

写真のようにRSIが70以上とRSIが30以下の時に赤く光ります。一目見た瞬間にどこが70以上で、どこが30以下か分かるのはちょっと便利かもしれません。

また、パラメーターの設定、色の設定、レベル表示の設定もできます。

 

解説めんどいのでコードを貼り付けます。自由に使ってください。

#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "https://oneyearblog.com/"
#property description "Relative Strength Index"
#property strict

#property indicator_separate_window

#property indicator_buffers 3
#property indicator_color1 clrYellow
#property indicator_color2 clrRed
#property indicator_color3 clrRed
#property indicator_minimum    0
#property indicator_maximum    100
#property indicator_level1     30.0
#property indicator_level2     70.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT


double rsi1[];
double rsi2[];
double rsi3[];
//--- input parameters
extern int InpRSIPeriod=14; // RSI Period
//--- buffers
double ExtRSIBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
     
	SetIndexBuffer(0, rsi1);   //0番目のバッファにrsi[]を指定
	SetIndexBuffer(1, rsi2);   //1番目のバッファにrsi[]を指定   
	SetIndexBuffer(2, rsi3);   //2番目のバッファにrsi[]を指定
	
	SetIndexStyle(0, DRAW_LINE,STYLE_SOLID,2);   //0番目のバッファの各種設定を記載
	SetIndexStyle(1, DRAW_LINE,STYLE_SOLID,2);   //1番目のバッファの各種設定を記載
	SetIndexStyle(2, DRAW_LINE,STYLE_SOLID,2);   //2番目のバッファの各種設定を記載
	
   return(0);
  }

int start()
{
   
   //「counted_bar」という変数を定義して、インジケータとして計算された本数の値を代入
   int counted_bar = IndicatorCounted();     
   if(counted_bar == 0)
   {
      counted_bar = counted_bar + 14;//※← このプラスの数値を手前の本数分変更
   }  
   //「limit」という変数を定義して、現在のローソク足の総数からインジケータ起動時の本数を引いた値を代入
   int limit = Bars- counted_bar;  
  
   //売買シグナルの作成
	for(int i = 0; i < limit; i++)
	{

        
      //RSIの値を「rsi」という変数に定義して代入   
      double rsi   = iRSI(NULL,0,14,PRICE_CLOSE,i);
      
      //BBをチャートに表示
      rsi1[i] = rsi;  //黄色
      rsi2[i] = rsi;  //赤色
      rsi3[i] = rsi;  //赤色
      
      
		if(rsi >= 70)
		{
		   //rsi3の赤を表示する
		   rsi2[i] = EMPTY_VALUE;
		}
		else if(rsi <= 30)
		{
		//rsi2の赤を表示する
		rsi3[i] = EMPTY_VALUE;
		}
		else
		{
		   //rsi1の黄色の表示
		   rsi2[i] = EMPTY_VALUE;
		   rsi3[i] = EMPTY_VALUE;		   
		   }
				
   }
   return(0);
}

 

LINEに登録すると、特別な資料が読めます。

友だち追加
ABOUT ME
子猫に大判!公式LINE
子猫に大判!公式LINE
公式LINEに登録すると無料で超優良級の情報をGETすることができます。煩わしいメッセージは一切送りません。【ノーリスクハイリターン】
:)