RCI、CCI、RSIの基礎

kabu.com

 

RCI = 1 - (6d / (n(n^2-1))) ×100

d:日付の順位と価格の差を2乗し、合計した数値

n:期間


www.tcom242242.net

こちらだな↑

github.com

 

neulab.co.jp

 

指定期間内の順位をつけるところ

for idx in range(df.shape[0]):
    value = df.iloc[ [idx], 4:9].rank(axis=1, ascending=False)
    value = value.fillna(0.0)
    d = 0

 

plt.xticks(range(xtick0,len(data),12), [x.strftime('%m/%d') for x in df.index][xtick0::30])

最後の12を30にすると表示。

 

http://www.openu-hyogodousoukai.com/club/c-lang/c201812.pdf

c言語のほうがMQL化しやすいから検索してみるとこんなかんじか。

/*
    順位付け 98 頁
    成績処理などを行うとき、得点を順位付けするする必要がある。
    点数を上から順位付けするプログラムを考えてみましょう。
    juni.c
*/
#include <stdio.h>
int main(){
    int ten[10] = {66, 56, 78, 55, 88, 90, 56, 76, 73, 58};
    int juni[10];
    int i;
    int n;
    for(i = 0; i < 10; i++){
         juni[i] = 1;
        for(n = 0; n < 10; n++){
            if(ten[n] > ten[i]){
                juni[i]++;
            }
        }
    }
    printf(" 番号 点 順位\n");
    for(i = 0; i < 10; i++){
        printf("%6d%6d%6d\n", i + 1, ten[i], juni[i]);
    }
    return 0;
}

 

いやこれでいいんだな。

qiita.com

多少MQL5化して、

double iRCI(const string symbol, int timeframe, int period, int index){
   int rank;
   double d = 0;
   double close_arr[];
   ArrayResize(close_arr, period);

   for (int i = 0; i < period; i++) {
       close_arr[i] = iClose(symbol, 0, index + i);
   }

//   ArraySort(close_arr, WHOLE_ARRAY, 0, MODE_DESCEND);
   ArraySetAsSeries(close_arr,false);
   ArraySort(close_arr);

   for (int j = 0; j < period; j++) {
      double close_price = iClose(symbol, 0, index + j);
      double rank_min=0, rank_max=0;
/*      rank = ArrayBsearch(close_arr,
                          close_price, //iClose(symbol, timeframe, index + j);
                          WHOLE_ARRAY,
                          0,
                          MODE_DESCEND
      );*/
      rank = ArrayBsearch(close_arr,
                          close_price
                          );
      
      for (int k = rank; k >= 0 && close_arr[k] == close_price; k--) rank_min = k;
      for (int l = rank; l < period && close_arr[l] == close_price; l++) rank_max = l;
      //d += MathPow(j - rank, 2);
      d += MathPow(j - (rank_min + rank_max) / 2.0, 2);
   }
   return((1 - 6 * d / (period * (period * period - 1))) * 100);
}

少し違うみたい。

 

note.com

もう少し探すか。

 

qiita.com

 

note.com

 

とりあえず、ここらへんでいいか。

 

note.com

CCIはこれでよさそう。

 

www.algo-fx-blog.com

RSI少し違うか

fxinspect.com

要約版。RSI使うときに考えよう。