关于rsi背离指标源码内容导航:
1、rsi背离指标源码
#include
#include
//定义RSI指标
#define RSI_LEN 14
//计算RSI指标
double getRSI(double *price, int len)
{
double up = 0.0;
double down = 0.0;
double diff = 0.0;
double rs = 0.0;
double rsi = 0.0;
int i;
for (i = 1; i < len; i++)
{
diff = price[i] - price[i - 1];
if (diff > 0)
{
up += diff;
}
else
{
down -= diff;
}
}
rs = up / down;
rsi = 100.0 - (100.0 / (1.0 + rs));
return rsi;
}
//计算RSI背离
int getRSIDivergence(double *price, int len)
{
int i;
double rsi[RSI_LEN];
int divergence = 0;
for (i = 0; i < len - RSI_LEN; i++)
{
rsi[i] = getRSI(price + i, RSI_LEN);
if (price[i] > price[i + 1] && rsi[i] < rsi[i + 1])
{
divergence = 1;
break;
}
else if (price[i] < price[i + 1] && rsi[i] > rsi[i + 1])
{
divergence = -1;
break;
}
}
return divergence;
}
int main()
{
double price[] = {
10.0,
10.2,
10.3,
10.1,
10.2,
10.3,
10.4,
10.5,
10.6,
10.7,
10.8,
10.9,
11.0,
11.1,
11.2,
11.3,
11.4,
11.5,
11.6,
11.7,
11.8,
11.9,
12.0};
int len = sizeof(price) / sizeof(price[0]);
int divergence = getRSIDivergence(price, len);
printf("RSI背离:%d
2、rsi指标背离什么意思
1.RSI>80 为超买,RSI<20 为超卖;
2.RSI 以50为中界线,大于50视为多头行情乐养国战困儿门蛋石友械,小于50视为空头行情;
3.R尽别渐复SI 在80以上形成M头或头肩顶形态时,视为向皮皇差察委下反转信号;
4.RSI 在2投固吃论香认鸡洲0以下形成W底或头肩底形态时,视为向上反转信号;
5.RSI 向上突破其高点连线时,买进;RSI 向分半刘下跌破其低点连线时至获,卖出。