I found some calculation formulas for this indicator online.
/*
LC := REF(CLOSE,1); //REF(C,1) 上一周期的收盘价
RSI:=SMA(MAX(CLOSE-LC,0),N,1)/SMA(ABS(CLOSE-LC),N,1) *100;
%K: MA(RSI-LLV(RSI,M),P1)/MA(HHV(RSI,M)-LLV(RSI,M),P1)*100; LLV(l,60)表示:检索60天内的最低价,可适应于检索任何股票
%D:MA(%K,P2);
LC := REF(CLOSE,1);
RSI:=SMA(MAX(CLOSE-LC,0),N,1)/SMA(ABS(CLOSE-LC),N,1) *100;
STOCHRSI:MA(RSI-LLV(RSI,M),P1)/MA(HHV(RSI,M)-LLV(RSI,M),P1)*100;
*/
My God, I've had enough patience to watch it. This description is a general formula. But even with a little programming experience, I can only guess!
After a painful struggle... Summary:
Green is fastline %K, orange is %D.
function LLV(array,period){
if(!array || array.length - period < 0){
throw "error:" + array;
}
var min = array[array.length - period];
for(var i = array.length - period; i < array.length; i++){
if( array[i] < min ){
min = array[i];
}
}
return min;
}
function HHV(array,period){
if(!array || array.length - period < 0){
throw "error:" + array;
}
var max = array[array.length - period];
for(var i = array.length - period; i < array.length; i++){
if( array[i] > max){
max = array[i];
}
}
return max;
}
function DeleteNullEle(initArr){
var dealArr = [];
var initArrLen = initArr.length;
for(var i = 0,j = 0 ; i < initArrLen ; i++,j++){
if(initArr[i] === null || isNaN(initArr[i]) ){
j--;
continue;
}
dealArr[j] = initArr[i];
}
return dealArr;
}
/*
LC := REF(CLOSE,1); //REF(C,1) 上一周期的收盘价
RSI:=SMA(MAX(CLOSE-LC,0),N,1)/SMA(ABS(CLOSE-LC),N,1) *100;
%K: MA(RSI-LLV(RSI,M),P1)/MA(HHV(RSI,M)-LLV(RSI,M),P1)*100; LLV(l,60)表示:检索60天内的最低价,可适应于检索任何股票
%D:MA(%K,P2);
LC := REF(CLOSE,1);
RSI:=SMA(MAX(CLOSE-LC,0),N,1)/SMA(ABS(CLOSE-LC),N,1) *100;
STOCHRSI:MA(RSI-LLV(RSI,M),P1)/MA(HHV(RSI,M)-LLV(RSI,M),P1)*100;
*/
function FstochRSI(records,n,m,p1,p2){
var len = records.length;
//var LC = records[len-2];//上一周期收盘价
//var rsi = TA.RSI(records,n);// RSI 数组 ,talib
var rsi = talib.RSI(records,n);
rsi = DeleteNullEle(rsi);//ceshi
var arr1 = [];
var arr2 = [];
var arr3 = [];
var arr4 = [];
var rsi_a = [];
var rsi_b = [];
var k = [];
var d = null;
/*不包含当前柱
for(var a = 0 ;a < rsi.length ; a++ ){//改造 不用 LLV
for(var aa = 0 ; aa <= a; aa++ ){
rsi_a.push(rsi[aa]);
}
arr1.push(rsi[a] - TA.Lowest(rsi_a,m));
}
for(var b = 0 ;b < rsi.length ; b++ ){//改造 不用 HHV
for(var bb = 0 ; bb <= b; bb++ ){
rsi_b.push(rsi[bb]);
}
arr2.push(TA.Highest(rsi_b,m) - TA.Lowest(rsi_b,m));
}
*/
for(var a = 0 ;a < rsi.length ; a++ ){//改造 不用 LLV
if(a < m){
continue;
}
for(var aa = 0 ; aa <= a; aa++ ){
rsi_a.push(rsi[aa]);
}
arr1.push(rsi[a] - LLV(rsi_a,m));
}
for(var b = 0 ;b < rsi.length ; b++ ){//改造 不用 HHV
if(b < m){
continue;
}
for(var bb = 0 ; bb <= b; bb++ ){
rsi_b.push(rsi[bb]);
}
arr2.push(HHV(rsi_b,m) - LLV(rsi_b,m));
}
arr1 = DeleteNullEle(arr1);
arr2 = DeleteNullEle(arr2);
//Log("arr1:",arr1.length,"-",arr1);//ceshi
//Log("arr2:",arr2.length,"-",arr2);//ceshi
arr3 = talib.MA(arr1,p1);
arr4 = talib.MA(arr2,p1);
arr3 = DeleteNullEle(arr3);
arr4 = DeleteNullEle(arr4);
//Log("ceshi");//ceshi
var c = 0;
var diff = 0;
if(arr3.length !== arr4.length){//实测 长度不相等
throw "error: !=" + arr3.length + "----" + arr4.length;
diff = arr4.length - arr3.length; //example diff = 10 - 6
}else{
//throw "error:" + arr3.length + "----" + arr4.length;
}
for( ;c < arr3.length ; c++ ){
k.push(arr3[c] / arr4[c + diff] * 100);
}
d = talib.MA(k,p2);
return [k,d,rsi];
}
lijingxfdjfunction main (()) {pos (192,210) } exchange.SetContractType (("swap") // is set to permanent contract var records = exchange.GetRecords ((PERIOD_M15)) is the name of the let [k, d, rsi] = FstochRSI ((records, 14, 14, 3, 3); Log (("K", k[k.length-2]) Log (("D", d[d.length-2]) I'm not sure. --- So, I called this function, and the data that was printed was not the same as the actual value of StochRsi on the binary.
JWhen retested, this function was found to be very slow and to be improved.
JI don't know what to do with the data from talib.STOCHRSI))) to correct the data from Bitcoinwisdom?
Inventors quantify - small dreamsThis may be a comparison problem, as the data used to determine the contrast are of the same species, period, parameter, BAR location. This has been tested before and should be the same.
Inventors quantify - small dreamstalib is an indicator library open source. It is used in BotVS, e.g. to search for even-line talib.MA ((records, 10); // records to search for even-line cycles of K-line data. It is calculated as the median of the records K line of 10 bars.
Inventors quantify - small dreamsFstochRSI ((records, n, m, p1, p2) corresponding to OKCoin parameters are the same, except that the first records is K-line data, which is the data source for the calculation of the indicator, and I compared the data calculated in the OK graph to the same data, which is that the algorithm is a bit slower.
Inventors quantify - small dreamsMaybe the algorithm or the code needs optimization.
JVery good, now it's normal. Thank you!
Inventors quantify - small dreamsThe code is already written in the post, you can compare it below.
JSo we're going to use the STOCH function first, and we're going to get the same effect.
Inventors quantify - small dreamsTalib's disagreement, internal calculations, are a bit different. I wrote STOCHRSI myself, and posted it later.