#property indicator_separate_window
#property indicator_minimum -10
#property indicator_maximum 100
#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Magenta
#property indicator_color5 DodgerBlue
extern int Ma周期= 14;
extern int 开买水平线= 80;
extern int 开卖水平线= 20;
extern int MainTrendLong= 51;
extern int MainTrendShort= 49;
double 蓝RSI[];
double 正缓组[];
double 负缓组[];
double bdn[];
double bup[];
double sdn[];
double sup[];
//-----------初始化-----------+
int init()
{
string 简称;
IndicatorBuffers(7);
SetIndexBuffer(0, 蓝RSI);
SetIndexBuffer(2, bup);
SetIndexBuffer(1, bdn);
SetIndexBuffer(3, sdn);
SetIndexBuffer(4, sup);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 3);
SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 1);
SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 1);
SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 1);
SetIndexStyle(4, DRAW_HISTOGRAM, STYLE_SOLID, 1);
SetIndexBuffer(5, 正缓组);
SetIndexBuffer(6, 负缓组);
简称= "RSIOMA("+Ma周期+")";
IndicatorShortName(简称);
SetIndexDrawBegin(0, Ma周期);
return(0);
}
//------------主函数-------------+
int start()
{
SetLevelValue(0, 开买水平线);
SetLevelValue(1, 开卖水平线);
SetLevelValue(2, MainTrendLong);
SetLevelValue(3, MainTrendShort);
SetLevelStyle(STYLE_DOT, 1, Yellow);
int 已计= IndicatorCounted();
double 前后差幅;
double 负向均值;
double 正向均值;
if(Bars<=Ma周期)
return(0);
if(已计<1)
for(int i=1; i<=Ma周期; i++)
蓝RSI[Bars-i]= 0.0;
i= Bars-Ma周期-1;
if(已计>=Ma周期)
i= Bars-已计-1;
while(i>=0){
double 跌差和= 0.0,
涨差和= 0.0;
//--使用
if(i==Bars-Ma周期-1){
int k= Bars-2;
while(k>=i){
double 现Mak= iMA(Symbol(), 0, Ma周期, 0, MODE_EMA, PRICE_CLOSE, k);
double 前Mak= iMA(Symbol(), 0, Ma周期, 0, MODE_EMA, PRICE_CLOSE, k+1);
前后差幅= 现Mak-前Mak;
if(前后差幅>0)
涨差和 += 前后差幅; // +涨差幅和
else
跌差和 -= 前后差幅; // -跌差幅和
k--;
}
正向均值= 涨差和/Ma周期; // 正向均值
负向均值= 跌差和/Ma周期; // 负向均值
}
//--使用
else{
double 现Mai= iMA(Symbol(), 0, Ma周期, 0, MODE_EMA, PRICE_CLOSE, i);
double 前Mai= iMA(Symbol(), 0, Ma周期, 0, MODE_EMA, PRICE_CLOSE, i+1);
前后差幅= 现Mai-前Mai;
if(前后差幅>0)
涨差和= 前后差幅;
else
跌差和= -前后差幅;
正向均值= (正缓组[i+1]*(Ma周期-1)+涨差和)/Ma周期;
负向均值= (负缓组[i+1]*(Ma周期-1)+跌差和)/Ma周期;
}
//--
正缓组= 正向均值;
负缓组= 负向均值;
//--计算RSI
if(负向均值==0.0) // 先过滤除数为0的情况
蓝RSI= 0.0;
else{
蓝RSI= 100.0-100.0/(1+正向均值/负向均值);
//--按条件显示区域色柱
bdn= 0;
bup= 0;
sdn= 0;
sup= 0;
if(蓝RSI>MainTrendLong)
bup= -10;
if(蓝RSI<MainTrendShort)
bdn= -10;
if(蓝RSI<20 && 蓝RSI>蓝RSI[i+1])
sup= -10;
if(蓝RSI>80 && 蓝RSI<蓝RSI[i+1])
sdn= -10;
}
i--;
}
return(0);
}
//+----------------------------------------------+
|