4[i過]RSI漢譯

//[i]RSI漢譯

property indicator_separate_window

property indicator_minimum 0

property indicator_maximum 100

property indicator_buffers 1

property indicator_color1 DodgerBlue

property indicator_level1 30.0

property indicator_level2 70.0

property indicator_levelcolor clrSilver

property indicator_levelstyle STYLE_DOT

//--- input parameters
input int 周期=14; // RSI Period
//--- buffers
double RSI值組[];
double 正和均組[];
double 負(fù)和均組[];
//+------------------------------------------------------------------+
//| 初始化 |
//+------------------------------------------------------------------+
int OnInit(void)
{
string 名稱;
//--- 用在計(jì)算中的兩個(gè)附加緩存
IndicatorBuffers(3);
SetIndexBuffer(1,正和均組);
SetIndexBuffer(2,負(fù)和均組);
//---指標(biāo)線
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,RSI值組);
//---數(shù)據(jù)窗口名與指標(biāo)標(biāo)簽
名稱="RSI("+string(周期)+")";
IndicatorShortName(名稱);
SetIndexLabel(0,名稱);
//---檢查
if(周期<2)
{
Print("無效的周期參數(shù)= ",周期);
return(INIT_FAILED);
}
//---
SetIndexDrawBegin(0,周期);
//---完成初始化
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 主函數(shù) |
//+------------------------------------------------------------------+
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 i,pos;
double 差幅;
//---
if(Bars<=周期 || 周期<2)
return(0);
//--- 從0到rates總數(shù)計(jì)數(shù)
ArraySetAsSeries(RSI值組,false);
ArraySetAsSeries(正和均組,false);
ArraySetAsSeries(負(fù)和均組,false);
ArraySetAsSeries(close,false);
//---準(zhǔn)備計(jì)算
pos= prev_calculated-1;

if(pos<=周期)
{
//---首個(gè)RSI周期值不計(jì)算
RSI值組[0]= 0.0;
正和均組[0]= 0.0;
負(fù)和均組[0]= 0.0;
double 正和= 0.0;
double 負(fù)和= 0.0;

  for(i=1; i<=周期; i++)
    {
     RSI值組[i]= 0.0;
     正和均組[i]= 0.0;
     負(fù)和均組[i]= 0.0;
     差幅= close[i]-close[i-1];
     if(差幅>0)
        正和 += 差幅;
     else
        負(fù)和 -= 差幅;
    }
  //---計(jì)算首個(gè)可見值
  正和均組[周期]= 正和/周期;
  負(fù)和均組[周期]= 負(fù)和/周期;
  if(負(fù)和均組[周期]!= 0.0)
     RSI值組[周期]= 100.0-(100.0/(1.0+正和均組[周期]/負(fù)和均組[周期]));
  else
    {
     if(正和均組[周期]!=0.0)
        RSI值組[周期]= 100.0;
     else
        RSI值組[周期]= 50.0;
    }
  //---準(zhǔn)備位置數(shù)給主循環(huán)計(jì)算
  pos= 周期+1;
 }

//---主循環(huán)內(nèi)容
for(i=pos; i<rates_total && !IsStopped(); i++)
{
差幅= close[i]-close[i-1];
正和均組[i]= (正和均組[i-1](周期-1)+(差幅>0.0?差幅:0.0))/周期;
負(fù)和均組[i]= (負(fù)和均組[i-1]
(周期-1)+(差幅<0.0?-差幅:0.0))/周期;
if(負(fù)和均組[i]!=0.0)
RSI值組[i]= 100.0-100.0/(1+正和均組[i]/負(fù)和均組[i]);
else
{
if(正和均組[i]!=0.0)
RSI值組[i]= 100.0;
else
RSI值組[i]= 50.0;
}
}
//---
return(rates_total);
}
//+----------------------------------謝謝點(diǎn)贊--------------------------------+

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容