aisaki_FTJ/ind Psychological Line.mq5
super.admin 3100c322e4 convert
2025-05-30 14:39:35 +02:00

73 lines
4.6 KiB
MQL5

//+------------------------------------------------------------------+
//|
//| サイコロジカルライン
//|
//| 指定期間の陽線の本数とローソク足の本数の割合を計算するインジケータです
//|
//+------------------------------------------------------------------+
//#property indicator_chart_window //チャートウィンドウに表示
#property indicator_separate_window //別ウィンドウに表示
#property indicator_buffers 1 //指標バッファの数
#property indicator_plots 1 //表示させる指標バッファの数
#property indicator_type1 DRAW_LINE //指標の種類
#property indicator_width1 1 //ラインの太さ
#property indicator_style1 STYLE_SOLID //ラインの種類
#property indicator_color1 clrCornflowerBlue //ラインの色
#property indicator_level1 50 //指標のレベル
#property indicator_level2 70 //指標のレベル
#property indicator_level3 30 //指標のレベル
#property indicator_levelcolor clrGray //レベルの色
#property indicator_levelwidth 1 //レベルの太さ
#property indicator_levelstyle STYLE_DOT //レベルの種類
input int period = 12; // 期間
double Buf0[]; //指標バッファ用の配列の宣言
int OnInit()
{
//配列を指標バッファに関連付ける
if( !SetIndexBuffer(0, Buf0)|| !ArraySetAsSeries(Buf0,true)){
Print("エラーコード:",GetLastError());
return(INIT_FAILED);
}
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[])
{
int limit = rates_total - prev_calculated; //プロットするバーの数
int count = 0;
for(int i=0; i<limit; i++){
for(int j=0; j<period; j++){
// 陽線の本数をカウント
if(iOpen(_Symbol,PERIOD_CURRENT,i+j) < iClose(_Symbol,PERIOD_CURRENT,i+j) ) count++;
}
// 陽線の本数/ローソク足の本数
Buf0[i] = (double)count/period *100 ;
count = 0;
}
return(rates_total-1);
}