Note: For education purpose. use as your own risk
copy from another website
copy from another website
PHP:
//------------------------------------------------------------------
#property copyright "mladen"
#property link "www.forex-tsd.com"
//indicators-expert-systems-tools/14880-rsi-indicator-47.html#post626857
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LimeGreen
extern int RsiPeriod = 3;
extern int UpDownPeriod = 2;
extern int ROCPeriod = 100;
extern int Price = PRICE_CLOSE;
//
//
//
//
//
double rsi[];
double prices[];
double updown[];
double roc[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(4);
SetIndexBuffer(0,rsi);
SetIndexBuffer(1,prices);
SetIndexBuffer(2,updown); SetIndexEmptyValue(2,0);
SetIndexBuffer(3,roc);
return(0);
}
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
//
//
//
//
//
for(int i=limit; i>=0; i--)
{
prices[i] = iMA(NULL,0,1,0,MODE_SMA,Price,i);
if (prices[i] == prices[i+1]) updown[i] = 0;
if (prices[i] < prices[i+1]) if (updown[i+1] > 0) updown[i] = -1; else updown[i] = updown[i+1]-1;
if (prices[i] > prices[i+1]) if (updown[i+1] < 0) updown[i] = 1; else updown[i] = updown[i+1]+1;
}
for(i=limit; i>=0; i--)
{
double trsi = iRSI(NULL,0,RsiPeriod,Price,i);
double ursi = iRSIOnArray(updown,0,UpDownPeriod,i);
roc[i] = 0;
if (prices[i+1]!=0) roc[i] = (prices[i]/prices[i+1]-1.0)*100.0;
double ROC_Percent = 0;
for (int k=1; k<=ROCPeriod; k++)
if (roc[i] >= roc[i+k]) ROC_Percent++;
ROC_Percent = (ROC_Percent / ROCPeriod) * 100;
//
//
//
//
//
rsi[i] = (trsi + ursi + ROC_Percent) / 3.0;
}
return(0);
}