forked from kimboqi/stock-indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator.min.js
1 lines (1 loc) · 1.99 KB
/
indicator.min.js
1
var Indicator=function(){var r=function(r){var a,s=[],t=r.length;for(var u=0;u<t;u++){var n=0,e=r[u];if(u!=0){var i=s[u-1];if(e[0]>=a[0]){n=i+e[1]}else{n=i-e[1]}}s.push(n);a=e}return s};var a=function(r,a,s){return(r*(s-1)+a*2)/(s+1)};var s=function(r,a){return(r*8+a*2)/10};var t=function(r){var t=[],u=[],n=[],e=[],i=[];for(var v=0;v<r.length;v++){var h=r[v];if(v==0){t.push(h);u.push(h);e.push(0)}else{t.push(a(t[v-1],h,12));u.push(a(u[v-1],h,26))}n.push(t[v]-u[v]);if(v!=0){e.push(s(e[v-1],n[v]))}i.push((n[v]-e[v])*2)}return{diffs:n,deas:e,bars:i}};var u=function(r){var a=r[0][0],s=r[0][1];for(var t=0;t<r.length;t++){var u=r[t],n=u[0],e=u[1];if(n>a){a=n}if(e<s){s=e}}return[a,s]};var n=function(r){var a=[],s=9,t=[];var n=[],e=[],i=[];var v,h,f,p;var l,o,c;for(var S=0;S<r.length;S++){var d=r[S],g=d[2];a.push(d);l=u(a);o=l[0];c=l[1];if(o==c){t.push(0)}else{t.push((g-c)/(o-c)*100)}if(a.length==s){a.shift()}if(S==0){v=h=t[S]}f=2/3*v+1/3*t[S];n.push(f);v=f;p=2/3*h+1/3*f;e.push(p);h=p;i.push(3*f-2*p)}return{k:n,d:e,j:i}};var e=function(r,a){var s=0,t=0;var u=[];for(var n=0;n<r.length;n++){s+=r[n];e=s/a;u.push(e)}return u};var i=function(r){var a=20,s=a-1,t=0,u=0;var n=[],e=[],i=[];for(var v=0;v<r.length;v++){var h=r[v],f,p,l,o;t+=h;if(v>=s){t=t-u;f=t/a;e.push(f);l=v-s;u=r[l];o=r.slice(l,l+a).reduce(function(r,a){return r+Math.pow(a-f,2)},0);p=Math.sqrt(o/a);n.push(f+2*p);i.push(f-2*p)}else{n.push(-1);e.push(-1);i.push(-1)}}return{upper:n,mid:e,lower:i}};var v=function(r){var a=r[0];var s=[6,12,24],t={};for(var u=0;u<r.length;u++){var n=r[u];var e=Math.max(n-a,0),i=Math.abs(n-a);for(var v=0;v<s.length;v++){var h=s[v];if(!t.hasOwnProperty("rsi"+h)){t["lastSm"+h]=t["lastSa"+h]=0;t["rsi"+h]=[0]}else{t["lastSm"+h]=(e+(h-1)*t["lastSm"+h])/h;t["lastSa"+h]=(i+(h-1)*t["lastSa"+h])/h;if(t["lastSa"+h]!=0){t["rsi"+h].push(t["lastSm"+h]/t["lastSa"+h]*100)}else{t["rsi"+h].push(0)}}}a=n}return{rsi6:t["rsi6"],rsi12:t["rsi12"],rsi24:t["rsi24"]}};return{OBV:r,MACD:t,KDJ:n,BOLL:i,RSI:v,MA:e}}();if(module){module.exports=Indicator}