ohlcv-indicators 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see ohlcv-indicators.min.js.LICENSE.txt */
2
- var OHLCV_INDICATORS;(()=>{var t={978:function(t,e){!function(t){"use strict";var e=function(t,i){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])})(t,i)},i=function(){return(i=Object.assign||function(t){for(var e,i=arguments,s=1,n=arguments.length;s<n;s++)for(var o in e=i[s])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function s(){for(var t=arguments,e=0,i=0,s=arguments.length;i<s;i++)e+=t[i].length;var n=Array(e),o=0;for(i=0;i<s;i++)for(var r=arguments[i],h=0,a=r.length;h<a;h++,o++)n[o]=r[h];return n}var n=function(){function t(t,e,i,s,n,o){void 0===o&&(o=null),this.forked=!1,this.forkedAt=0,this.lastForkY=null,this.step=s,this.index=n,this.length=0,this.startPoint=o?{y:t?o.h:o.l,x:o.x}:{y:t||e,x:i},this.init(t,e,i),this.thisPoint=this.startPoint}return t.prototype.init=function(t,e,i){this.type||(this.type=t?"h":"l"),this.candlePoint={y:"h"==this.type?t:e,x:i},this.thisPoint&&(this.prevPoint=this.thisPoint,this.nextPoint&&(this.thisPoint=this.nextPoint),this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step})},t.prototype.update=function(t,e,i){var s=null;if(this.length++,this.init(t,e,i),this.k&&!isNaN(this.k)||(this.k=(this.candlePoint.y-this.startPoint.y)/(this.candlePoint.x-this.startPoint.x),this.b=this.candlePoint.y-this.k*this.candlePoint.x,this.prevPoint=this.startPoint,this.thisPoint=this.candlePoint,this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step},s={condition:"h"==this.type?"lt":"gt",value:this.nextPoint.y,action:"fork",lineIndex:this.index}),"h"==this.type&&this.thisPoint.y<=this.candlePoint.y||"l"==this.type&&this.thisPoint.y>=this.candlePoint.y){this.k=(this.candlePoint.y-this.startPoint.y)/(this.candlePoint.x-this.startPoint.x),this.b=this.candlePoint.y-this.k*this.candlePoint.x,this.thisPoint=this.candlePoint,this.length=0,this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step};var n=this.rollback?this.rollback.length:0,o=this.candlePoint.y-this.prevPoint.y;("h"==this.type?o>0:o<0)?(this.rollback={k:o,b:this.candlePoint.y-o*this.candlePoint.x,length:n+1,lastForkTime:this.forkedAt||(this.rollback?this.rollback.lastForkTime:0),lastForkValue:this.forkedValue||(this.rollback?this.rollback.lastForkValue:0)},this.forked=!1,this.forkedAt=null,this.forkedValue=null):(this.forkedAt=this.candlePoint.x,this.forkedValue=this.candlePoint.y,this.forked=!0,this.rollback=null),s={condition:"h"==this.type?"lt":"gt",value:this.nextPoint.y,action:"fork",lineIndex:this.index}}else this.rollback=null;return s},t.prototype.updateStep=function(t){this.step=t},t}(),o=function(){function t(t){this.lineIndex=0,this.forkDiffH=null,this.forkDiffL=null,this.step=t,this.list=[[],[]],this.id={}}return t.prototype.add=function(t,e,i,s,o){void 0===s&&(s=null),void 0===o&&(o=null);var r,h,a,l=null;if(null==o?(r=this.lineIndex,this.lineIndex++,null!=t?this.list[0].push(r):this.list[1].push(r)):(r=o,l=this.id[r].lastForkY||(null!=t?s.h:s.l)),this.id[r]=new n(t,e,i,this.step,r,s),l&&(this.id[r].lastForkY=l),r>1||null!=o&&null!=this.id[o]){h=null!=o?o:this.list["h"==this.id[r].type?0:1][this.list["h"==this.id[r].type?0:1].indexOf(r)-1],a=null!=o?o:this.list["h"==this.id[r].type?0:1][this.list["h"==this.id[r].type?0:1].indexOf(r)-2];var u=this.id[h].lastForkY;a&&!u&&(u=this.id[a].lastForkY);var p=null!=t?s.h:s.l;u&&(t?this.forkDiffH=u>=p?-h-1:h+1:this.forkDiffL=u>=p?-h-1:h+1),this.id[h].lastForkY=p}return r},t.prototype.update=function(t,e,i,s){return this.id[t].update(e,i,s)},t.prototype.delete=function(t){this.id[t]&&("h"==this.id[t].type?this.list[0].splice(this.list[0].indexOf(t),1):this.list[1].splice(this.list[1].indexOf(t),1),delete this.id[t])},t}(),r=function(){function t(t,e){this.kdiff=[],this.env=e,this.lines=t,this.in={state:null,lineIndex:null,line:null},this.is={state:null,lineIndex:null,line:null,start:null,size:0},this.was={state:null,lineIndex:null,line:null,size:null},this.width=0,this.speed=0,this.at=0}return t.prototype.update=function(t,e){var s=this;if(t.length>1?this.hlMaxDuration=t.map((function(t){return s.lines.id[t]})).filter((function(t){return!s.is.line||(t.forkedAt?t.forkedAt>s.is.line.startPoint.x:!!t.rollback&&t.rollback.lastForkTime>s.is.line.startPoint.x)})).reduce((function(t,e){return t.length>e.length?t:e}),this.lines.id[t[0]]):this.hlMaxDuration=this.lines.id[t[0]],e.length>1?this.llMaxDuration=e.map((function(t){return s.lines.id[t]})).filter((function(t){return!s.is.line||(t.forkedAt?t.forkedAt>s.is.line.startPoint.x:!!t.rollback&&t.rollback.lastForkTime>s.is.line.startPoint.x)})).reduce((function(t,e){return t.length>e.length?t:e}),this.lines.id[e[0]]):this.llMaxDuration=this.lines.id[e[0]],null==this.is.state&&null==this.was.state&&(this.is.line=this.llMaxDuration&&this.llMaxDuration.length>this.env.minLength&&this.hlMaxDuration.length<this.env.minLength?this.llMaxDuration:this.hlMaxDuration&&this.hlMaxDuration.length>this.env.minLength&&this.llMaxDuration.length<this.env.minLength?this.hlMaxDuration:null,this.is.line&&(this.is.lineIndex=this.is.line.index,this.is.state="h"==this.is.line.type?"fall":"rise",this.is.start=this.is.line.candlePoint)),this.is.state){this.is.size=Math.max(this.is.size,Math.abs(this.is.start.y-this.is.line.candlePoint.y));var n,o=this.lines.id[this.is.lineIndex]||this.lines.id["h"==this.is.line.type?0:1],r=null,h=null,a=this.lines.list["h"==o.type?1:0].filter((function(t){return s.lines.id[t].forked&&s.lines.id[t].thisPoint.x-s.lines.id[t].forkedAt>12}));a.length>1?a[1]:a.length>0&&a[0];var l=a.filter((function(t){return s.lines.id[t].forkedAt>s.is.start.x}));if(o&&this.lines.list["h"==o.type?0:1].forEach((function(t,e){var i=s.lines.id[t];if(t>=o.index&&null!=i.rollback){n=s.lines.list["h"==o.type?0:1][e-1];var a=1==s.env.deltaModel&&e>1&&n&&s.lines.id[n]?e>1&&n&&s.lines.id[n].lastForkY:s.lines.id[t>0?t-1:0];h=a?s.lines.id[t>1?n:"h"==o.type?0:1].lastForkY-i.candlePoint.y:i.rollback?i.rollback.lastForkValue-i.candlePoint.y:0,i.rollback.lastForkValue>0&&i.thisPoint.x-i.rollback.lastForkTime>s.env.minRightLeg&&("fall"==s.is.state?s.llMaxDuration.length>1:s.hlMaxDuration.length>1)&&(("h"==o.type?h<0:h>0)||i.rollback.length>s.env.rollbackLength||2*s.is.size/3>Math.abs(s.is.start.y-s.is.line.candlePoint.y)&&s.is.size>s.is.line.candlePoint.y*s.env.minIsSizeOnRollback&&l.length>1||("h"==o.type?i.candlePoint.y>s.is.start.y&&1==s.lines.list[0].length:i.candlePoint.y<s.is.start.y&&1==s.lines.list[1].length))&&(i.candlePoint.x-i.rollback.lastForkTime>s.env.forkDurationMin&&i.candlePoint.x-i.rollback.lastForkTime<s.env.forkDurationMax||("h"==o.type?i.candlePoint.y>i.startPoint.y:i.candlePoint.y<i.startPoint.y)||("h"==o.type?i.candlePoint.y>s.is.start.y&&1==s.lines.list[0].length:i.candlePoint.y<s.is.start.y&&1==s.lines.list[1].length))&&(r=t+1)}})),r){this.in.size=(this.was.size||0)+this.is.size;var u=this.lines.id[0].candlePoint.y-this.is.start.y,p="rise"==this.is.state?u>=0:u<0;this.was.size&&(this.in.state=this.was.size>this.is.size?this.was.state:this.is.state),this.was=i({},this.is),this.was.success=p,this.is.line="fall"==this.is.state?this.llMaxDuration:this.hlMaxDuration,this.is.state="h"==this.is.line.type?"fall":"rise",this.is.lineIndex=this.is.line.index,this.is.start=this.lines.id[0].candlePoint,this.is.size=0}}},t}(),h=function(){function t(t){this.hLineDirectives=[],this.lLineDirectives=[],this.step=1,this.i=0,this.localCounter=0,this.prevPoint=null,this.env=Object.assign({step:1,minLength:5,minRightLeg:3,maxForks:500,minLog:0,maxLog:0,rollbackLength:3,deltaModel:1,minIsSizeOnRollback:.05},t),this.env.minLength=Math.round(this.env.minLength/this.env.step)||1,this.env.minRightLeg=Math.round(this.env.minRightLeg/this.env.step)||1,this.env.rollbackLength=Math.round(this.env.rollbackLength/this.env.step)||1,this.env.forkDurationMin=Math.round(this.env.forkDurationMin/this.env.step)||1,this.env.forkDurationMax=Math.round(this.env.forkDurationMax/this.env.step)||1,this.lines=new o(this.step),this.trend=new r(this.lines,this.env)}return t.prototype.log=function(t){for(var e=arguments,i=[],n=1;n<arguments.length;n++)i[n-1]=e[n];this.consoleWindow=this.env.minLog<this.localCounter&&this.localCounter<this.env.maxLog,this.consoleWindow&&console.log.apply(console,s([t],i))},t.prototype.nextValue=function(t,e,i,s){var n,o=this;this.localCounter++,this.lLineDirectives.length>0&&this.lLineDirectives.forEach((function(t,e){var i=o.lines.id[t.lineIndex];"gt"==t.condition&&s>t.value&&"fork"==t.action&&i&&(null!=t.lineIndex&&null!=i&&i.k<0?o.lines.add(null,s,o.i-1,o.prevPoint,t.lineIndex):(i.forked=!0,i.forkedAt=i.thisPoint.x,i.forkedValue=i.thisPoint.y,o.lines.add(null,s,o.i-1,o.prevPoint)))})),this.hLineDirectives.length>0&&this.hLineDirectives.forEach((function(t,e){var s=o.lines.id[t.lineIndex];"lt"==t.condition&&i<t.value&&"fork"==t.action&&s&&(s.k>0?o.lines.add(i,null,o.i-1,o.prevPoint,t.lineIndex):(s.forked=!0,s.forkedAt=s.thisPoint.x,s.forkedValue=s.thisPoint.y,o.lines.add(i,null,o.i-1,o.prevPoint)))})),this.hLineDirectives.length=0,this.lLineDirectives.length=0,this.lines.list[0].length<1?(this.lines.add(i,null,this.i),this.lines.add(null,s,this.i)):this.lines.list.forEach((function(t){return t.forEach((function(t){var e=o.lines.id[t];if(e&&e.type){n=null,e&&e.startPoint.x<o.i&&(n=o.lines.update(t,i,s,o.i));var r=e.type;n&&("h"==r?o.hLineDirectives.push(n):o.lLineDirectives.push(n))}}))}));var r=[];return this.lines.list.forEach((function(t){t&&(r=[],t.forEach((function(e,i){var s=o.lines.id[t[i]],n=o.lines.id[t[i-1]];(i>0&&s&&n&&"h"==s.type&&s.thisPoint&&n.thisPoint.y<=s.thisPoint.y||i>o.env.maxForks||i>0&&s&&n&&"l"==s.type&&s.thisPoint&&n.thisPoint.y>=s.thisPoint.y||i>o.env.maxForks)&&r.push(e)})),r.forEach((function(t){return o.lines.delete(t)})))})),this.prevPoint={x:this.i,h:i,l:s},this.trend.update(this.lines.list[0],this.lines.list[1]),this.i++,this.lines},t}(),a=Object.freeze({__proto__:null,Indicator:h}),l=function(){function t(t){this.length=t,this.filled=!1,this.pointer=0,this.buffer=new Array(t),this.maxIndex=t-1}return t.prototype.push=function(t){var e=this.buffer[this.pointer];return this.buffer[this.pointer]=t,this.iteratorNext(),e},t.prototype.pushback=function(t){this.iteratorPrev();var e=this.buffer[this.pointer];return this.buffer[this.pointer]=t,e},t.prototype.peek=function(){return this.buffer[this.pointer]},t.prototype.forEach=function(t){for(var e=this.pointer,i=0;i!==this.length;)t(this.buffer[e],i),e=(this.length+e+1)%this.length,i++},t.prototype.forEachRight=function(t){for(var e=(this.length+this.pointer-1)%this.length,i=this.length-1;i!==this.length;)t(this.buffer[e],i),e=(this.length+e-1)%this.length,i--},t.prototype.fill=function(t){this.buffer.fill(t),this.filled=!0},t.prototype.toArray=function(){return this.buffer},t.prototype.iteratorNext=function(){this.pointer++,this.pointer>this.maxIndex&&(this.pointer=0,this.filled=!0)},t.prototype.iteratorPrev=function(){this.pointer--,this.pointer<0&&(this.pointer=this.maxIndex)},t}(),u=function(t){function i(e,i){void 0===e&&(e=100);var s=t.call(this,e)||this;return s.period=e,s.mode=i,s.comparator="max"===i?s.maxComporator:s.mminComporator,s}return function(t,i){function s(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}(i,t),i.prototype.nextValue=function(t){return this.push(t),this.getExtremum()},i.prototype.momentValue=function(t){var e=this.push(t),i=this.getExtremum();return this.pushback(e),i},i.prototype.maxComporator=function(t,e){return t>e},i.prototype.mminComporator=function(t,e){return t<e},i.prototype.getExtremum=function(t){var e=(this.length+this.pointer-2)%this.length,i="max"===this.mode?-1/0:1/0;if(!this.filled)return 0;for(;e!==this.pointer;){var s=this.buffer[(this.length+e-1)%this.length],n=this.buffer[(this.length+e+1)%this.length],o=this.buffer[e];if(this.comparator(o,i)&&this.comparator(o,s)&&this.comparator(o,n)){if(i=o,this.prevIx===e)return null;if(this.prevIx=e,t)return i}e=(this.length+e-1)%this.length}return isFinite(i)?i:(this.prevIx=null,null)},i}(l),p=function(){function t(t){this.period=t,this.sum=0,this.circular=new l(t)}return t.prototype.nextValue=function(t){var e=this;if(this.circular.push(t),this.sum+=t,this.circular.filled)return this.nextValue=function(t){return e.sum=e.sum-e.circular.push(t)+t,e.sum/e.period},this.momentValue=function(t){return(e.sum-e.circular.peek()+t)/e.period},this.sum/this.period},t.prototype.momentValue=function(t){},t}(),c=function(){function t(t){this.period=t,this.smooth=1/this.period,this.sma=new p(this.period)}return t.prototype.nextValue=function(t){return this.wema?this.wema=(t-this.wema)*this.smooth+this.wema:this.wema=this.sma.nextValue(t)},t.prototype.momentValue=function(t){return this.wema?(t-this.wema)*this.smooth+this.wema:this.sma.momentValue(t)},t}(),d=function(){function t(t){this.period=t,this.smooth=2/(this.period+1),this.sma=new p(this.period)}return t.prototype.nextValue=function(t){var e=this,i=this.sma.nextValue(t);return i&&(this.ema=i,this.nextValue=function(t){return e.ema=(t-e.ema)*e.smooth+e.ema},this.momentValue=function(t){return(t-e.ema)*e.smooth+e.ema}),i},t.prototype.momentValue=function(t){},t}(),f=function(){function t(t,e){this.indicator=t,this.samples=e,this._indicators=[]}return t.prototype.create=function(){for(var t,e=arguments,i=[],n=0;n<arguments.length;n++)i[n]=e[n];for(var o=0;o<this.samples;o++)this._indicators.push(new((t=this.indicator).bind.apply(t,s([void 0],i))))},t.prototype.nextValue=function(t){for(var e=0;e<this.samples;e++)if(void 0===(t=this._indicators[e].nextValue(t)))return t;return t},t.prototype.momentValue=function(t){for(var e=0;e<this.samples;e++)if(null==(t=this._indicators[e].momentValue(t)))return t;return t},t}(),m=function(){function t(t,e,i,s,n){void 0===t&&(t=.85),void 0===s&&(s=1),void 0===n&&(n=1),this.redunant=t,this.multiplier=s,this.offset=n,this.prevValue=0,this.lastUpperValue=0,this.lastLowerValue=0,this.samplerUp=new f(e,i),this.samplerLow=new f(e,i)}return t.prototype.create=function(){for(var t,e,i=arguments,s=[],n=0;n<arguments.length;n++)s[n]=i[n];(t=this.samplerUp).create.apply(t,s),(e=this.samplerLow).create.apply(e,s)},t.prototype.nextValue=function(t){this.lastUpperValue=t>0?Math.max(t,this.prevValue):Math.max(0,this.lastUpperValue)*this.redunant,this.lastLowerValue=t<=0?Math.min(t,this.prevValue):Math.min(0,this.lastLowerValue)*this.redunant;var e=(t<=0?t:this.lastLowerValue)*this.multiplier,i=(t>=0?t:this.lastUpperValue)*this.multiplier;return[this.samplerUp.nextValue(i)+this.offset,this.samplerLow.nextValue(e)-this.offset]},t}(),v=function(){function t(t,e,i,s){void 0===i&&(i=.85),void 0===s&&(s="WEMA"),this.period=t,this.samples=e,this.redunant=i,this.type=s,this.upper=0,this.lower=0,this.lastUpperValue=0,this.lastLowerValue=0,this.sample1Up=this.createSample(),this.sample2Up=this.createSample(),this.sample3Up=this.createSample(),this.sample1Low=this.createSample(),this.sample2Low=this.createSample(),this.sample3Low=this.createSample()}return t.prototype.nextValue=function(t){return t>0?(this.upper=this.getUp(t),this.lastLowerValue*=this.redunant,this.lower=this.getDown(this.lastLowerValue),this.lastUpperValue=t):t<0&&(this.lower=this.getDown(t),this.lastUpperValue*=this.redunant,this.upper=this.getUp(this.lastUpperValue),this.lastLowerValue=t),{upper:this.upper,lower:this.lower}},t.prototype.getUp=function(t){var e=this.sample1Up.nextValue(t),i=null;return 1===this.samples?e:(e&&(i=this.sample2Up.nextValue(e)),2===this.samples?i:i?this.sample3Up.nextValue(i):null)},t.prototype.getDown=function(t){var e=this.sample1Low.nextValue(t),i=null;return 1===this.samples?e:(e&&(i=this.sample2Low.nextValue(e)),2===this.samples?i:i?this.sample3Low.nextValue(i):null)},t.prototype.createSample=function(){switch(this.type){case"EMA":return new d(this.period);case"WEMA":return new c(this.period);case"SMA":return new p(this.period)}},t}(),V=function(){function t(t){this.period=t,this.SMAx=new p(this.period),this.SMAy=new p(this.period),this.pricesX=new l(this.period),this.pricesY=new l(this.period)}return t.prototype.nextValue=function(t,e){this.pricesX.push(t),this.pricesY.push(e),this.SMAxValue=this.SMAx.nextValue(t),this.SMAyValue=this.SMAy.nextValue(e);for(var i=0,s=0,n=0,o=0;o<this.period;o++){var r=this.pricesX.toArray()[o],h=this.pricesY.toArray()[o];i+=(r-this.SMAxValue)*(h-this.SMAyValue),s+=Math.pow(r-this.SMAxValue,2),n+=Math.pow(h-this.SMAyValue,2)}return i/Math.sqrt(s*n)},t}(),w=function(){function t(t){this.period=t,this.denominator=t*(t+1)/2,this.buffer=new l(t),this.values=[]}return t.prototype.nextValue=function(t){var e=this;if(this.buffer.push(t),this.buffer.filled){var i=0;return this.buffer.forEach((function(t,s){i+=t*(s+1)/e.denominator})),i}},t.prototype.momentValue=function(t){var e=this,i=this.buffer.push(t);if(this.buffer.filled){var s=0;return this.buffer.forEach((function(t,i){s+=t*(i+1)/e.denominator})),this.buffer.pushback(i),s}this.buffer.pushback(i)},t}(),x=function(){function t(t){void 0===t&&(t=.2),this.alpha=t,this.filled=!1}return t.prototype.nextValue=function(t){var e=this.alpha*t+(1-this.alpha)*(this.prevValue||1);if(this.filled=this.filled||void 0!==this.prevValue,this.prevValue=e,this.filled)return e},t.prototype.momentValue=function(t){if(this.filled)return this.alpha*t+(1-this.alpha)*(this.prevValue||1)},t}(),y=function(){function t(t){this.period=t,this.sum=0,this.avg=0,this.filled=!1,this.fill=0}return t.prototype.nextValue=function(t){var e=this;return this.filled?(this.nextValue=function(t){return e.avg=(e.avg*(e.period-1)+t)/e.period},this.nextValue(t)):(this.sum+=t,this.fill++,this.fill===this.period?(this.filled=!0,this.avg=this.sum/this.period,this.avg):void 0)},t.prototype.momentValue=function(t){if(this.filled)return(this.avg*(this.period-1)+t)/this.period},t}(),g=function(){function t(t){void 0===t&&(t=14),this.period=t,this.alpha=1/t,this.sma=new p(this.period)}return t.prototype.nextValue=function(t){var e=this;return this.prevValue?(this.prevValue=this.alpha*t+(1-this.alpha)*this.prevValue,this.nextValue=function(t){return e.prevValue=e.alpha*t+(1-e.alpha)*e.prevValue,e.prevValue}):this.prevValue=this.sma.nextValue(t),this.prevValue},t.prototype.momentValue=function(t){if(this.prevValue)return this.alpha*t+(1-this.alpha)*this.prevValue},t}(),P=function(){function t(t,e){void 0===t&&(t=5),void 0===e&&(e=34),this.smaSlow=new p(e),this.smaFast=new p(t)}return t.prototype.nextValue=function(t,e){var i=this;if(this.smaSlowValue=this.smaSlow.nextValue((t+e)/2),this.smaFastValue=this.smaFast.nextValue((t+e)/2),void 0!==this.smaSlowValue&&void 0!==this.smaFastValue)return this.nextValue=function(t,e){return i.smaSlowValue=i.smaSlow.nextValue((t+e)/2),i.smaFastValue=i.smaFast.nextValue((t+e)/2),i.smaFastValue-i.smaSlowValue},this.momentValue=function(t,e){return i.smaFast.momentValue((t+e)/2)-i.smaSlow.momentValue((t+e)/2)},this.smaFastValue-this.smaSlowValue},t.prototype.momentValue=function(t,e){},t}(),k=function(){function t(){this.sma=new p(5),this.ao=new P}return t.prototype.nextValue=function(t,e){var i=this;if(this.aoValue=this.ao.nextValue(t,e),void 0!==this.aoValue&&(this.smaValue=this.sma.nextValue(this.aoValue),void 0!==this.smaValue))return this.nextValue=function(t,e){return i.aoValue=i.ao.nextValue(t,e),i.smaValue=i.sma.nextValue(i.aoValue),i.aoValue-i.smaValue},this.momentValue=function(t,e){return i.ao.momentValue(t,e)-i.sma.momentValue(i.aoValue)},this.aoValue-this.smaValue},t.prototype.momentValue=function(t,e){},t}(),b=function(t,e){return(t-e)/e*100},M=function(){function t(t){this.period=t,this.value=0,this.changes=new l(t)}return t.prototype.nextValue=function(t){if(this.prevPrice){var e=b(t,this.prevPrice);return this.calculate(e),this.prevPrice=t,this.value}this.prevPrice=t},t.prototype.calculate=function(t){return this.value+=t,this.value-=this.changes.push(t),this.value},t}();function A(t){return t.consolidate=0,t.power=0,t.streak=0,t.diff=0,t.startPrice=0,t.prevPeak=0,t}var L=function(){function t(){this.up={consolidate:0,power:0,streak:0,startPrice:0,diff:0,prevPeak:0},this.down={consolidate:0,power:0,streak:0,startPrice:0,diff:0,prevPeak:0}}return t.prototype.nextValue=function(t,e,s,n){if(t<e||this.up.streak&&this.up.prevPeak<n){this.up.startPrice||(this.up.startPrice=t),this.down.streak&&A(this.down);var o=e-t;this.up.streak++,this.up.prevPeak=n,this.up.diff>o?this.up.consolidate++:this.up.consolidate=0,this.up.diff=o,this.up.power=b(e,this.up.startPrice)}return(t>e||this.down.streak&&this.down.prevPeak>s)&&(this.down.startPrice||(this.down.startPrice=t),this.up.streak&&A(this.up),o=t-e,this.down.streak++,this.down.prevPeak=s,this.down.diff>o?this.down.consolidate++:this.down.consolidate=0,this.down.diff=o,this.down.power=b(e,this.down.startPrice)),t===e&&(this.up.streak++,this.down.streak++,this.up.diff=this.down.diff=0),this.up.streak>this.down.streak?i({},this.up):i({},this.down)},t}(),S=function(){function t(t){this.max=-1/0,this.highest=new l(t)}return t.prototype.filled=function(){return this.highest.filled},t.prototype.nextValue=function(t){return this.max<t&&(this.max=t),this.highest.push(t)===this.max&&t!==this.max&&(this.max=function(t){for(var e=-1/0,i=t.length-1;i>=0;i--){var s=t[i];e<s&&(e=s)}return e}(this.highest.toArray())),this.max},t.prototype.momentValue=function(t){return this.max>t?this.max:t},t}(),C=function(){function t(t){this.min=1/0,this.lowest=new l(t)}return t.prototype.filled=function(){return this.lowest.filled},t.prototype.nextValue=function(t){return this.min>t&&(this.min=t),this.lowest.push(t)===this.min&&t!==this.min&&(this.min=function(t){for(var e=1/0,i=t.length-1;i>=0;i--){var s=t[i];e>s&&(e=s)}return e}(this.lowest.toArray())),this.min},t.prototype.momentValue=function(t){return this.min<t?this.min:t},t}(),D=function(){function t(t,e){void 0===t&&(t=14),void 0===e&&(e=3),this.period=t,this.smaPeriod=e,this.sma=new p(this.smaPeriod),this.max=new S(t),this.min=new C(t)}return t.prototype.nextValue=function(t,e,i){var s=this.max.nextValue(t),n=this.min.nextValue(e);if(this.max.filled()){var o=(i-n)/(s-n)*100;return{k:o,d:this.sma.nextValue(o)}}},t.prototype.momentValue=function(t,e,i){if(this.max.filled()){var s=this.max.momentValue(t),n=this.min.momentValue(e),o=(i-n)/(s-n)*100;return{k:o,d:this.sma.momentValue(o)}}},t}(),F=function(){function t(t){this.avgGain=new y(t),this.avgLoss=new y(t)}return t.prototype.nextValue=function(t){var e=t-this.prev;if(this.prev){var i=e>0?e:0,s=e<0?e:0,n=this.avgGain.nextValue(i),o=this.avgLoss.nextValue(s);return this.prev=t,{upAvg:n,downAvg:o}}this.prev=t},t.prototype.momentValue=function(t){var e=t-this.prev,i=e>0?e:0,s=e<0?e:0;return{upAvg:this.avgGain.momentValue(i),downAvg:this.avgLoss.momentValue(s)}},t}(),I=function(){function t(t){void 0===t&&(t=14),this.period=t,this.change=new F(this.period)}return t.prototype.nextValue=function(t){var e=this.change.nextValue(t)||{},i=e.downAvg,s=e.upAvg;if(void 0!==s&&void 0!==i)return 100-100/(1+s/-i)},t.prototype.momentValue=function(t){var e=this.change.momentValue(t)||{},i=e.downAvg,s=e.upAvg;if(void 0!==s&&void 0!==i)return 100-100/(1+s/-i)},t}(),_=function(){function t(t,e,i,s){void 0===t&&(t=14),void 0===e&&(e=3),void 0===i&&(i=3),void 0===s&&(s=14),this.rsi=new I(t),this.sma1=new p(e),this.sma2=new p(i),this.max=new S(s),this.min=new C(s)}return t.prototype.nextValue=function(t){var e=this.rsi.nextValue(t);if(void 0!==e){var i=this.max.nextValue(e),s=this.min.nextValue(e);if(this.max.filled()){var n=(e-s)/(i-s)*100,o=this.sma1.nextValue(n);if(void 0!==o)return{k:o,d:this.sma2.nextValue(o),stochRsi:n}}}},t.prototype.momentValue=function(t){if(this.max.filled()){var e=this.rsi.momentValue(t),i=this.max.momentValue(e),s=this.min.momentValue(e),n=(e-s)/(i-s)*100,o=this.sma1.momentValue(n);return{k:o,d:this.sma2.momentValue(o),stochRsi:n}}},t}(),E=function(){function t(t){this.period=t,this.values=new l(t)}return t.prototype.nextValue=function(t,e){if(e)return this.nextValue=this.pureNextValue,this.momentValue=this.pureMomentValue,this.pureNextValue(t,e);this.values.push(t)},t.prototype.momentValue=function(t,e){},t.prototype.pureNextValue=function(t,e){var i=this;return this.values.push(t),this.values.toArray().reduce((function(t,s){return t+i.positiveDelta(e,s)}),0)/this.period},t.prototype.pureMomentValue=function(t,e){var i=this,s=this.values.push(t),n=this.values.toArray().reduce((function(t,s){return t+i.positiveDelta(e,s)}),0);return this.values.pushback(s),n/this.period},t.prototype.positiveDelta=function(t,e){return t>e?t-e:e-t},t}(),O=function(){function t(t){void 0===t&&(t=20),this.md=new E(t),this.sma=new p(t)}return t.prototype.nextValue=function(t,e,i){var s=(t+e+i)/3,n=this.sma.nextValue(s),o=this.md.nextValue(s,n);return o&&(s-n)/(.015*o)},t.prototype.momentValue=function(t,e,i){var s=(t+e+i)/3,n=this.sma.momentValue(s),o=this.md.momentValue(s,n);return o&&(s-n)/(.015*o)},t}(),U=function(){function t(t){this.period=t,this.arr=[],this.filled=!1,this.devider=0,this.lastSum=0,this.devider=function(t){for(var e=0,i=t.length;i>0;)e+=t[--i];return e}(Array.from(Array(this.period).keys()).map((function(t){return t+1})))}return t.prototype.nextValue=function(t){if(this.filled=this.filled||this.arr.length===this.period,this.arr.push(t),this.filled)return this.arr.shift(),this.arr.reduce((function(t,e,i){return t+e*(i+1)}),0)/this.devider},t.prototype.momentValue=function(t){if(this.filled){var e=this.arr.slice(1);return e.push(t),e.reduce((function(t,e,i){return t+e*(i+1)}),0)/this.devider}},t}();function R(t,e,i){if(i){var s=t-e,n=t>i?t-i:i-t,o=e>i?e-i:i-e;return s>=n&&s>=o?s:n>=s&&n>=o?n:o}}var T=function(){function t(t,e){switch(void 0===t&&(t=14),void 0===e&&(e="WEMA"),e){case"SMA":this.avg=new p(t);break;case"EMA":this.avg=new d(t);break;case"SMMA":this.avg=new y(t);break;case"WEMA":this.avg=new c(t);break;case"LWMA":this.avg=new U(t);break;case"EWMA":this.avg=new x(.2);break;case"RMA":this.avg=new g(t)}this.prevClose=0}return t.prototype.nextValue=function(t,e,i){var s=R(t,e,this.prevClose);if(this.prevClose=i,void 0!==s)return this.avg.nextValue(s)},t.prototype.momentValue=function(t,e){var i=R(t,e,this.prevClose);if(void 0!==i)return this.avg.momentValue(i)},t}(),N=function(){function t(t){void 0===t&&(t=5),this.values=new l(t)}return t.prototype.nextValue=function(t){var e=this.values.push(t);if(e)return(t-e)/e*100},t.prototype.momentValue=function(t){var e=this.values.peek();if(e)return(t-e)/e*100},t}(),j=function(){function t(t){void 0===t&&(t=20),this.maxProvider=new S(t),this.minProvider=new C(t)}return t.prototype.nextValue=function(t,e){var i=this.maxProvider.nextValue(t),s=this.minProvider.nextValue(e);return{upper:i,middle:(i+s)/2,lower:s}},t.prototype.momentValue=function(t,e){var i=this.maxProvider.momentValue(t),s=this.minProvider.momentValue(e);return{upper:i,middle:(i+s)/2,lower:s}},t}(),z=function(){function t(t){this.period=t,this.fill=0,this.values=new l(t)}return t.prototype.nextValue=function(t){var e=this;if(this.values.push(t),this.fill++,this.fill===this.period)return this.nextValue=function(t){var i=e.calc(t);return e.values.push(t),i},this.momentValue=this.calc,this.calc(t)},t.prototype.momentValue=function(t){},t.prototype.calc=function(t){var e=0;return this.values.toArray().forEach((function(i){i<=t&&e++})),e/this.period*100},t}(),W=function(){function t(t,e,i){void 0===t&&(t=3),void 0===e&&(e=2),void 0===i&&(i=100),this.period=t,this.rsi=new I(this.period),this.updownRsi=new I(e),this.roc=new N(1),this.percentRank=new z(i),this.updownPeriod=0,this.prevClose=0}return t.prototype.nextValue=function(t){var e=this.rsi.nextValue(t),i=this.percentRank.nextValue(this.roc.nextValue(t));if(this.updownPeriod=this.getUpdownPeriod(t),this.prevClose=t,this.updownValue=this.updownRsi.nextValue(this.updownPeriod),this.updownValue)return(e+this.updownValue+i)/3},t.prototype.momentValue=function(t){var e=this.rsi.momentValue(t),i=this.percentRank.momentValue(this.roc.momentValue(t)),s=this.getUpdownPeriod(t),n=this.updownRsi.momentValue(s);if(void 0!==n)return(e+n+i)/3},t.prototype.getUpdownPeriod=function(t){var e=this.updownPeriod;return t>this.prevClose?(this.updownPeriod<0&&(e=0),e++):t<this.prevClose?(this.updownPeriod>0&&(e=0),e--):e=0,e},t}(),$=function(){function t(t){this.period=t,this.values=new l(t)}return t.prototype.nextValue=function(t,e){return this.values.push(t),Math.sqrt(this.values.toArray().reduce((function(t,i){return t+Math.pow(i-e,2)}),0)/this.period)},t.prototype.momentValue=function(t,e){var i=this.values.push(t),s=Math.sqrt(this.values.toArray().reduce((function(t,i){return t+Math.pow(i-e,2)}),0)/this.period);return this.values.pushback(i),s},t}(),B=function(){function t(t,e){void 0===t&&(t=20),void 0===e&&(e=2),this.period=t,this.stdDev=e,this.fill=0,this.sma=new p(t),this.sd=new $(t)}return t.prototype.nextValue=function(t){var e=this,i=this.sma.nextValue(t),s=this.sd.nextValue(t,i);if(this.fill++,this.fill===this.period){var n=i-this.stdDev*s,o=i+this.stdDev*s;return this.nextValue=function(t){var i=e.sma.nextValue(t),s=e.sd.nextValue(t,i);return{lower:i-e.stdDev*s,middle:i,upper:i+e.stdDev*s}},{lower:n,middle:i,upper:o}}},t.prototype.momentValue=function(t){var e=this.sma.momentValue(t),i=this.sd.momentValue(t,e);return{lower:e-this.stdDev*i,middle:e,upper:e+this.stdDev*i}},t}(),H=function(){function t(t,e,i){void 0===t&&(t=12),void 0===e&&(e=26),void 0===i&&(i=9),this.periodEmaFast=t,this.periodEmaSlow=e,this.periodSignal=i,this.emaFastIndicator=new d(t),this.emaSlowIndicator=new d(e),this.emaSignalIndicator=new d(i)}return t.prototype.nextValue=function(t){var e=this.emaFastIndicator.nextValue(t),i=this.emaSlowIndicator.nextValue(t),s=e-i,n=s&&this.emaSignalIndicator.nextValue(s)||void 0,o=s-n||void 0;if(!isNaN(s))return{macd:s,emaFast:e,emaSlow:i,signal:n,histogram:o}},t.prototype.momentValue=function(t){var e=this.emaFastIndicator.momentValue(t),i=this.emaSlowIndicator.momentValue(t),s=e-i,n=s&&this.emaSignalIndicator.momentValue(s);return{macd:s,emaFast:e,emaSlow:i,signal:n,histogram:s-n}},t}(),Y=function(){function t(){this.prevOpen=0,this.prevClose=0}return t.prototype.nextValue=function(t,e,i,s){var n=this.calculate(t,e,i,s);return this.prevClose=n.c,this.prevOpen=n.o,n},t.prototype.momentValue=function(t,e,i,s){return this.calculate(t,e,i,s)},t.prototype.calculate=function(t,e,i,s){return s=(t+e+i+s)/4,this.prevOpen&&(t=(this.prevOpen+this.prevClose)/2),{o:t,h:e=Math.max(e,t,s),l:i=Math.min(i,t,s),c:s}},t}(),X=function(){function t(t){switch(void 0===t&&(t="classic"),this.mode=t,this.mode){case"classic":this.calculator=this.classic;break;case"camarilla":this.calculator=this.camarilla;break;case"woodie":this.calculator=this.woodie;break;case"fibonacci":this.calculator=this.fibonacci}}return t.prototype.nextValue=function(t,e,i){return this.calculator(t,e,i)},t.prototype.classic=function(t,e,i){var s=(t+e+i)/3;return{r3:t+2*(s-e),r2:s+(t-e),r1:2*s-e,pp:s,s1:2*s-t,s2:s-(t-e),s3:e-2*(t-s)}},t.prototype.woodie=function(t,e,i){var s=(t+e+2*i)/4;return{r2:s+t-e,r1:2*s-e,pp:s,s1:2*s-t,s2:s-t+e}},t.prototype.camarilla=function(t,e,i){var s=1.1*(t-e),n=t/e*i,o=i+s/2,r=n+1.168*(n-o);return{r6:r,r5:n,r4:o,r3:i+s/4,r2:i+s/6,r1:i+s/12,pp:(t+e+i)/3,s1:i-s/12,s2:i-s/6,s3:i-s/4,s4:i-s/2,s5:i-(n-i),s6:i-(r-i)}},t.prototype.fibonacci=function(t,e,i){var s=t-e,n=(t+e+i)/3;return{r3:n+s,r2:n+.618*s,r1:n+.382*s,pp:n,s1:n-.382*s,s2:n-.618*s,s3:n-s}},t}(),q=function(){function t(t,e,i){void 0===t&&(t=.02),void 0===e&&(e=.02),void 0===i&&(i=.2),this.start=t,this.acceleration=e,this.max=i,this.result=0,this.isBullTrend=!0}return t.prototype.nextValue=function(t,e,i){if(!this.result)return this.result=i,this.low1=e,this.high1=t,this.low2=e,this.high2=t,this.highest=t,this.lowest=e,this.accelerationFactor=this.start,e;if(this.isBullTrend?this.psar=this.result+this.accelerationFactor*(this.highest-this.result):this.psar=this.result+this.accelerationFactor*(this.lowest-this.result),this.isBullTrend)if(e<this.psar)this.isBullTrend=!1,this.psar=this.highest,this.lowest=e,this.accelerationFactor=this.start;else{if(t>this.highest){this.highest=t;var s=this.accelerationFactor+this.acceleration;this.accelerationFactor=s>this.max?this.max:s}this.low1<this.psar&&(this.psar=this.low1),this.low2<this.psar&&(this.psar=this.low2)}else t>this.psar?(this.isBullTrend=!0,this.psar=this.lowest,this.highest=t,this.accelerationFactor=this.start):(e<this.lowest&&(this.lowest=e,s=this.accelerationFactor+this.acceleration,this.accelerationFactor=s>this.max?this.max:s),this.high1>this.psar&&(this.psar=this.high1),this.high2>this.psar&&(this.psar=this.high2));return this.low2=this.low1,this.low1=e,this.high2=this.high1,this.high1=t,this.result=this.psar,this.result},t.prototype.momentValue=function(t,e){if(!this.result)return e;var i,s=this.isBullTrend,n=this.result,o=this.low1,r=this.high1,h=this.low2,a=this.high2,l=this.highest,u=this.lowest,p=this.accelerationFactor;return i=s?n+p*(l-n):n+p*(u-n),s?e<i?i=l:(o<i&&(i=o),h<i&&(i=h)):t>i?i=u:(r>i&&(i=r),a>i&&(i=a)),i},t}(),G=function(){function t(t){this.period=t,this.prevValue=0,this.sumCount=1}return t.prototype.nextValue=function(t){var e=this;return this.sumCount<this.period?(this.prevValue+=t,void this.sumCount++):this.sumCount===this.period?(this.prevValue+=t,this.sumCount++,this.nextValue=function(t){return e.prevValue=e.prevValue-e.prevValue/e.period+t},this.prevValue):void 0},t.prototype.momentValue=function(t){if(!(this.sumCount<this.period))return this.prevValue-this.prevValue/this.period+t},t}(),K=function(){function t(t){void 0===t&&(t=14),this.period=t,this.wma1=new G(t),this.wma2=new G(t),this.wma3=new G(t),this.wema=new c(t)}return t.prototype.nextValue=function(t,e,i){if(!this.prevClose)return this.prevHigh=t,this.prevLow=e,void(this.prevClose=i);var s=0,n=0,o=t-this.prevHigh,r=this.prevLow-e;o>r&&o>0&&(s=o),r>o&&r>0&&(n=r),(s>n||n<0)&&(n=0);var h=this.wma1.nextValue(R(t,e,this.prevClose)),a=this.wma2.nextValue(s),l=this.wma3.nextValue(n);if(this.prevHigh=t,this.prevLow=e,this.prevClose=i,void 0!==a&&void 0!==l){var u=100*a/h,p=100*l/h,c=u>p?u-p:p-u;return{adx:this.wema.nextValue(c/(u+p)*100),pdi:u,mdi:p}}},t.prototype.momentValue=function(t,e,i){if(this.prevClose){var s=0,n=0,o=t-this.prevHigh,r=this.prevLow-e;o>r&&o>0&&(s=o),r>o&&r>0&&(n=r),(s>n||n<0)&&(n=0);var h=this.wma1.momentValue(R(t,e,this.prevClose)),a=this.wma2.momentValue(s),l=this.wma3.momentValue(n);if(void 0!==a&&void 0!==l){var u=100*a/h,p=100*l/h,c=u>p?u-p:p-u;return{adx:this.wema.momentValue(c/(u+p)*100),pdi:u,mdi:p}}}},t}(),J=function(){function t(t,e,i){void 0===t&&(t=10),void 0===e&&(e=3),void 0===i&&(i="WEMA"),this.multiplier=e,this.atr=new T(t,i)}return t.prototype.nextValue=function(t,e,i){var s=this.atr.nextValue(t,e,i);if(s){var n=(t+e)/2,o=n+this.multiplier*s,r=n-this.multiplier*s;this.prevLower&&(r=r>this.prevLower||this.prevClose<this.prevLower?r:this.prevLower,o=o<this.prevUpper||this.prevClose>this.prevUpper?o:this.prevUpper);var h,a=(h=this.prevSuper===this.prevUpper?i>o?r:o:i<r?o:r)===o?1:-1;return this.prevUpper=o,this.prevLower=r,this.prevSuper=h,this.prevClose=i,{upper:o,lower:r,superTrend:h,direction:a}}},t.prototype.momentValue=function(t,e,i){var s=this.atr.momentValue(t,e),n=(t+e)/2,o=n+this.multiplier*s,r=n-this.multiplier*s;this.prevLower&&(r=r>this.prevLower||this.prevClose<this.prevLower?r:this.prevLower,o=o<this.prevSuper||this.prevClose>this.prevUpper?o:this.prevUpper);var h;return{upper:o,lower:r,superTrend:h=this.prevSuper===this.prevUpper?i>o?r:o:i<r?o:r,direction:h===o?1:-1}},t}(),Q=function(t){return(t.o+t.h+t.l+t.c)/4},Z=function(){function t(t,e){void 0===t&&(t=4),void 0===e&&(e=Q),this.sum=0,this.sessionPricesLookup=new Set,this.sessionVolumes={},this.prevCandle=null,this.source=e,this.precision=t,this.valueToRoundWith=Math.pow(10,this.precision)}return t.prototype.getSession=function(t,e){var i=this;void 0===e&&(e=15);var s=this.source(t),n=1/0,o=s;this.sessionPricesLookup.forEach((function(t){var r=i.diffPercent(t,s);r>e?(i.sessionPricesLookup.delete(t),delete i.sessionVolumes[t]):r<n&&(n=r,o=t)}));var r=Array.from(this.sessionPricesLookup).sort(),h=r.indexOf(o),a=new Map;if(-1===h)return a;for(var l=Math.round(r.length/4),u=0,p=0;p<4;p++){for(var c=p*l,d=c+l,f=0,m=0,v=c;v<d;v++){var V=r[c],w=this.sessionVolumes[V];f<w&&(f=w,m=V)}this.diffPercent(u,m)<1&&(f=a.get(u)+f,m=this.roundPrice((m+u)/2),a.delete(u)),a.set(m,f),u=m}return a},t.prototype.getSessionAvg=function(){return this.sum/this.sessionPricesLookup.size},t.prototype.getRawSession=function(){return this.sessionVolumes},t.prototype.nextValue=function(t){var e,i=this.roundPrice(this.source(t)),s=(null===(e=this.prevCandle)||void 0===e?void 0:e.time)===t.time?t.v-this.prevCandle.v:t.v;this.addToSession(i,s),this.sum+=s,this.lastPrice=i,this.prevCandle=t},t.prototype.roundPrice=function(t){return Math.round((t+Number.EPSILON)*this.valueToRoundWith)/this.valueToRoundWith},t.prototype.addToSession=function(t,e){this.sessionPricesLookup.has(t)?this.sessionVolumes[t]+=e:(this.sessionPricesLookup.add(t),this.sessionVolumes[t]=e)},t.prototype.diffPercent=function(t,e){return t<e?100*(e-t)/t:100*(t-e)/e},t}(),tt=function(){function t(t,e){void 0===t&&(t=3),void 0===e&&(e=10),this.accDistribution=0,this.emaFast=new d(t),this.emaSlow=new d(e)}return t.prototype.nextValue=function(t,e,i,s){return this.accDistribution+=i===t&&i===e||t===e?0:(2*i-e-t)/(t-e)*s,this.emaFast.nextValue(this.accDistribution)-this.emaSlow.nextValue(this.accDistribution)},t.prototype.momentValue=function(t,e,i,s){var n=this.accDistribution+(i===t&&i===e||t===e?0:(2*i-e-t)/(t-e)*s);return this.emaFast.momentValue(n)-this.emaSlow.momentValue(n)},t}();t.AC=k,t.ADX=K,t.AO=P,t.ATR=T,t.BollingerBands=B,t.CCI=O,t.ChaikinOscillator=tt,t.CircularBuffer=l,t.Correlation=V,t.DC=j,t.EMA=d,t.EWMA=x,t.Extremums=u,t.HeikenAshi=Y,t.LWMA=U,t.Level=v,t.MACD=H,t.Move=M,t.PSAR=q,t.Pivot=X,t.RMA=g,t.ROC=N,t.RSI=I,t.SMA=p,t.SMMA=y,t.Sampler=f,t.StandardDeviation=$,t.Stochastic=D,t.StochasticRSI=_,t.SuperTrend=J,t.TrendLines=a,t.UniLevel=m,t.VolumeProfile=Z,t.WEMA=c,t.WMA=w,t.WWS=G,t.Wave=L,t.cRSI=W,Object.defineProperty(t,"__esModule",{value:!0})}(e)}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var o=e[s]={exports:{}};return t[s].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};(()=>{"use strict";i.r(s),i.d(s,{default:()=>u});var t=i(978);const e=(e,i)=>{const s=[],n=new t.EMA(i);return e.forEach((t=>{s.push(n.nextValue(t))})),s},n=(e,i)=>{const s=[],n=new t.SMA(i);return e.forEach((t=>{s.push(n.nextValue(t))})),s},o=(t,e)=>{var i;return(0===(i=t.map(((t,i)=>t>e[i]?"up":t<e[i]?"down":"neutral")).reverse()).length?[]:i.reduce(((t,e,i,s)=>{if(0===i)t.push([e]);else{const n=s[i-1],o=t[t.length-1];e!==n?t.push([e]):o.push(e)}return t}),[])).map((t=>{const e=t.length;return t.map(((t,i)=>{let s=e-i;return"down"===t?-s:"up"===t?s:0}))})).flat().reverse()},r=(t,e)=>{let{upper:i,lower:s}=e;const n=i.map(((t,e)=>t-s[e]));return t.map(((t,e)=>(t-s[e])/n[e]*100))},h={getSMA:n,getEMA:e},a=(t,e=10)=>{const{open:i,high:s,low:n,close:o,volume:r}=t,h=Math.min(...n),a=(Math.max(...s)-h)/e,u={upVolume:0,downVolume:0,grossVolume:0},p=Array.from({length:e},((t,e)=>({price:h+a*e,upVolume:0,downVolume:0,grossVolume:0}))),c=1/a;for(let t=0;t<o.length;t++){const a=o[t],l=i[t],u=s[t],d=n[t],f=r[t],m=a>=l?f:0,v=a<l?f:0,V=Math.max(0,Math.floor((d-h)*c)),w=Math.min(e,Math.ceil((u-h)*c));for(let t=V;t<w;t++)p[t].upVolume+=m,p[t].downVolume+=v,p[t].grossVolume+=m+v}for(const{upVolume:t,downVolume:e,grossVolume:i}of p)u.upVolume+=t,u.downVolume+=e,u.grossVolume+=i;return{bins:p,nodes:l(p)}},l=t=>{if(!t||0===t.length)throw new Error("Bins array is empty or not provided");let e=t[0],i=t[0];return t.forEach((t=>{t.grossVolume>e.grossVolume&&(e=t),t.grossVolume<i.grossVolume&&(i=t)})),{highestVolumeNode:e,lowestVolumeNode:i}};class u{constructor(){this.VolumeProfile=a}init(t){return this.ohlcv=t.reduce(((t,{open:e,high:i,low:s,close:n,volume:o,...r})=>{t.open.push(e),t.high.push(i),t.low.push(s),t.close.push(n),t.volume.push(o);for(const e of Object.keys(r))t[e]||(t[e]=[]),t[e].push(r[e]);return t}),{open:[],high:[],low:[],close:[],volume:[]}),this}getHeaders(){return Object.keys(this.ohlcv)}getData(){const{ohlcv:t}=this,e=Object.keys(t),i=e.length;return t.open.map(((s,n)=>{const o={};for(let s=0;s<i;s++){const i=e[s];o[i]=t[i][n]}return o}))}getLastValues(){const t={};for(const[e,i]of Object.entries(this.ohlcv)){let s=i[i.length-1];t[e]=s}return t}addColumn(t,e){const i=this.ohlcv.open.length;if(e.length>i)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");e=[...new Array(i-e.length).fill(null),...e],this.ohlcv[t]=e}crossPairs(t){const e=this.ohlcv,i={},s=t=>{if(!e.hasOwnProperty(t)&&"string"==typeof t){const[e,...i]=t.split("_");this[e]&&i.length>0&&this[e](...i)}};for(const{fast:n,slow:r}of t)if(n&&r)if(s(n),s(r),"number"!=typeof r||i[r]||(i[r]=e.close.map((()=>r))),e[n]&&e[r]){const t=o(e[n],e[r]);this.addColumn(`${n}_x_${r}`,t)}else if(e[n]&&i[r]){const t=o(e[n],i[r]);this.addColumn(`${n}_x_${r}`,t)}else console.error(`Missing ohlcv properties for ${n} or ${r}`)}ema(t){return((t,i)=>{const{ohlcv:s}=t,n=s.close,o=e(n,i);t.addColumn(`ema_${i}`,o)})(this,t),this}sma(t){return((t,e)=>{const{ohlcv:i}=t,s=i.close,o=n(s,e);t.addColumn(`sma_${e}`,o)})(this,t),this}macd(t,i,s){return((t,i=12,s=26,n=9)=>{const{ohlcv:r}=t,h=((t,i=12,s=26,n=9)=>{const r=e(t,i),h=e(t,s),a=r.map(((t,e)=>isNaN(t)||isNaN(h[e])?null:t-h[e])),l=e(a,n),u=a.map(((t,e)=>t-l[e])),p=o(a,l);return{macd_diff:a,macd_dea:l,macd_histogram:u,macd_diff_x_macd_dea:p}})(r.close,i,s,n);for(let e in h)t.addColumn(e,h[e])})(this,t,i,s),this}bollingerBands(e,i,s){return((e,i,s)=>{const{ohlcv:n}=e,o=((e,i=20,s=2)=>{const n={lower:[],middle:[],upper:[]},o=new t.BollingerBands(i,s);e.forEach((t=>{const e=o.nextValue(t);if("object"==typeof e){const{lower:t,middle:i,upper:s}=e;n.lower.push(t),n.middle.push(i),n.upper.push(s)}else n.lower.push(null),n.middle.push(null),n.upper.push(null)}));const h=r(e,{upper:n.upper,lower:n.lower});return{...n,range:h}})(n.close,i,s);for(let t in o)e.addColumn(`bollinger_bands_${t}`,o[t])})(this,e,i),this}rsi(e,i,s){return((e,i,s,n)=>{const{ohlcv:r}=e;"number"==typeof i&&void 0===n&&(n=i);const a=((e,i=14,s="SMA",n=14)=>{if(e.length<i)return[];let r=[];i=parseInt(i),n=parseInt(n);const a=new t.RSI(i);e.forEach((t=>{r.push(a.nextValue(t))})),r=r.filter((t=>t));let l={[`rsi_${i}`]:r};if("string"==typeof s&&"number"==typeof n&&h.hasOwnProperty(`get${s}`)){const t=h[`get${s}`](r,n);l[`rsi_${s}_${n}`]=t,l[`rsi_${i}_x_rsi_${s}_${n}`]=o(r,t)}return l})(r.close,i,s,n);for(let t in a)e.addColumn(`${t}`.toLowerCase(),a[t])})(this,e,i,s),this}candles(){return(t=>{const{ohlcv:e}=t,i=(t=>{const{open:e,high:i,low:s,close:n}=t,o=e.length;if(![e,i,s,n].every((t=>Array.isArray(t)&&t.length>1&&t.length===o)))return{pattern:Array(o).fill("Neutral"),name:Array(o).fill("No Pattern"),score:Array(o).fill(0)};const r=(t,e,i=1e-4)=>Math.abs(t-e)<i,h={bullish:[{name:"Marubozu",condition:(t,e)=>r(e.open,e.low)&&r(e.close,e.high),score:3},{name:"Engulfing",condition:(t,e)=>e.open<t.close&&e.close>t.open&&e.low<t.low&&e.high>t.high,score:2},{name:"Kicker",condition:(t,e)=>e.open<t.open&&e.close>e.open&&t.close<t.open,score:2},{name:"Morning Star",condition:(t,e)=>e.close>t.close&&e.open<t.open&&t.close<t.open,score:2},{name:"Piercing Line",condition:(t,e)=>e.close>t.close&&e.open<t.open&&e.close>(t.open+t.close)/2,score:1},{name:"Belt Hold",condition:(t,e)=>e.open>t.open&&r(e.close,e.high)&&r(t.close,t.low),score:1},{name:"Harami",condition:(t,e)=>e.open>t.close&&e.close<t.open&&e.open<t.open&&e.close>t.close,score:1},{name:"Doji",condition:(t,e)=>r(e.close,e.open)&&e.high-e.low>Math.abs(e.close-e.open),score:0}],bearish:[{name:"Marubozu",condition:(t,e)=>r(e.open,e.high)&&r(e.close,e.low),score:-3},{name:"Engulfing",condition:(t,e)=>e.open>t.close&&e.close<t.open&&e.high>t.high&&e.low<t.low,score:-2},{name:"Kicker",condition:(t,e)=>e.open>t.open&&e.close<e.open&&t.close>t.open,score:-2},{name:"Evening Star",condition:(t,e)=>e.close<t.close&&e.open>t.open&&t.close<t.open,score:-2},{name:"Dark Cloud Cover",condition:(t,e)=>e.close<t.close&&e.open>t.open&&e.close<(t.open+t.close)/2,score:-1},{name:"Belt Hold",condition:(t,e)=>e.open<t.open&&r(e.close,e.low)&&r(t.close,t.high),score:-1},{name:"Harami",condition:(t,e)=>e.open<t.close&&e.close>t.open&&e.open>t.open&&e.close<t.close,score:-1},{name:"Doji",condition:(t,e)=>r(e.close,e.open)&&e.high-e.low>Math.abs(e.close-e.open),score:0}]},a=(t,e,i)=>{for(const{name:s,condition:n,score:o}of i)if(n(t,e))return{name:s,score:o};return null},l=["Neutral"],u=["No Pattern"],p=[0];for(let t=1;t<o;t++){const o={open:e[t-1],high:i[t-1],low:s[t-1],close:n[t-1]},r={open:e[t],high:i[t],low:s[t],close:n[t]},c=a(o,r,h.bullish)||a(o,r,h.bearish);c?(l.push(c.score>0?"Bullish":"Bearish"),u.push(c.name),p.push(c.score)):(l.push("Neutral"),u.push("No Pattern"),p.push(0))}return{pattern:l,name:u,score:p}})(e);for(let e in i)t.addColumn(`candle_${e}`.toLowerCase(),i[e])})(this),this}}})(),OHLCV_INDICATORS=s})();
2
+ var OHLCV_INDICATORS;(()=>{var t={978:function(t,i){!function(t){"use strict";var i=function(t,e){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&(t[e]=i[e])})(t,e)},e=function(){return(e=Object.assign||function(t){for(var i,e=arguments,s=1,n=arguments.length;s<n;s++)for(var o in i=e[s])Object.prototype.hasOwnProperty.call(i,o)&&(t[o]=i[o]);return t}).apply(this,arguments)};function s(){for(var t=arguments,i=0,e=0,s=arguments.length;e<s;e++)i+=t[e].length;var n=Array(i),o=0;for(e=0;e<s;e++)for(var r=arguments[e],h=0,l=r.length;h<l;h++,o++)n[o]=r[h];return n}var n=function(){function t(t,i,e,s,n,o){void 0===o&&(o=null),this.forked=!1,this.forkedAt=0,this.lastForkY=null,this.step=s,this.index=n,this.length=0,this.startPoint=o?{y:t?o.h:o.l,x:o.x}:{y:t||i,x:e},this.init(t,i,e),this.thisPoint=this.startPoint}return t.prototype.init=function(t,i,e){this.type||(this.type=t?"h":"l"),this.candlePoint={y:"h"==this.type?t:i,x:e},this.thisPoint&&(this.prevPoint=this.thisPoint,this.nextPoint&&(this.thisPoint=this.nextPoint),this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step})},t.prototype.update=function(t,i,e){var s=null;if(this.length++,this.init(t,i,e),this.k&&!isNaN(this.k)||(this.k=(this.candlePoint.y-this.startPoint.y)/(this.candlePoint.x-this.startPoint.x),this.b=this.candlePoint.y-this.k*this.candlePoint.x,this.prevPoint=this.startPoint,this.thisPoint=this.candlePoint,this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step},s={condition:"h"==this.type?"lt":"gt",value:this.nextPoint.y,action:"fork",lineIndex:this.index}),"h"==this.type&&this.thisPoint.y<=this.candlePoint.y||"l"==this.type&&this.thisPoint.y>=this.candlePoint.y){this.k=(this.candlePoint.y-this.startPoint.y)/(this.candlePoint.x-this.startPoint.x),this.b=this.candlePoint.y-this.k*this.candlePoint.x,this.thisPoint=this.candlePoint,this.length=0,this.nextPoint={y:this.k*(this.candlePoint.x+this.step)+this.b,x:this.candlePoint.x+this.step};var n=this.rollback?this.rollback.length:0,o=this.candlePoint.y-this.prevPoint.y;("h"==this.type?o>0:o<0)?(this.rollback={k:o,b:this.candlePoint.y-o*this.candlePoint.x,length:n+1,lastForkTime:this.forkedAt||(this.rollback?this.rollback.lastForkTime:0),lastForkValue:this.forkedValue||(this.rollback?this.rollback.lastForkValue:0)},this.forked=!1,this.forkedAt=null,this.forkedValue=null):(this.forkedAt=this.candlePoint.x,this.forkedValue=this.candlePoint.y,this.forked=!0,this.rollback=null),s={condition:"h"==this.type?"lt":"gt",value:this.nextPoint.y,action:"fork",lineIndex:this.index}}else this.rollback=null;return s},t.prototype.updateStep=function(t){this.step=t},t}(),o=function(){function t(t){this.lineIndex=0,this.forkDiffH=null,this.forkDiffL=null,this.step=t,this.list=[[],[]],this.id={}}return t.prototype.add=function(t,i,e,s,o){void 0===s&&(s=null),void 0===o&&(o=null);var r,h,l,a=null;if(null==o?(r=this.lineIndex,this.lineIndex++,null!=t?this.list[0].push(r):this.list[1].push(r)):(r=o,a=this.id[r].lastForkY||(null!=t?s.h:s.l)),this.id[r]=new n(t,i,e,this.step,r,s),a&&(this.id[r].lastForkY=a),r>1||null!=o&&null!=this.id[o]){h=null!=o?o:this.list["h"==this.id[r].type?0:1][this.list["h"==this.id[r].type?0:1].indexOf(r)-1],l=null!=o?o:this.list["h"==this.id[r].type?0:1][this.list["h"==this.id[r].type?0:1].indexOf(r)-2];var u=this.id[h].lastForkY;l&&!u&&(u=this.id[l].lastForkY);var c=null!=t?s.h:s.l;u&&(t?this.forkDiffH=u>=c?-h-1:h+1:this.forkDiffL=u>=c?-h-1:h+1),this.id[h].lastForkY=c}return r},t.prototype.update=function(t,i,e,s){return this.id[t].update(i,e,s)},t.prototype.delete=function(t){this.id[t]&&("h"==this.id[t].type?this.list[0].splice(this.list[0].indexOf(t),1):this.list[1].splice(this.list[1].indexOf(t),1),delete this.id[t])},t}(),r=function(){function t(t,i){this.kdiff=[],this.env=i,this.lines=t,this.in={state:null,lineIndex:null,line:null},this.is={state:null,lineIndex:null,line:null,start:null,size:0},this.was={state:null,lineIndex:null,line:null,size:null},this.width=0,this.speed=0,this.at=0}return t.prototype.update=function(t,i){var s=this;if(t.length>1?this.hlMaxDuration=t.map((function(t){return s.lines.id[t]})).filter((function(t){return!s.is.line||(t.forkedAt?t.forkedAt>s.is.line.startPoint.x:!!t.rollback&&t.rollback.lastForkTime>s.is.line.startPoint.x)})).reduce((function(t,i){return t.length>i.length?t:i}),this.lines.id[t[0]]):this.hlMaxDuration=this.lines.id[t[0]],i.length>1?this.llMaxDuration=i.map((function(t){return s.lines.id[t]})).filter((function(t){return!s.is.line||(t.forkedAt?t.forkedAt>s.is.line.startPoint.x:!!t.rollback&&t.rollback.lastForkTime>s.is.line.startPoint.x)})).reduce((function(t,i){return t.length>i.length?t:i}),this.lines.id[i[0]]):this.llMaxDuration=this.lines.id[i[0]],null==this.is.state&&null==this.was.state&&(this.is.line=this.llMaxDuration&&this.llMaxDuration.length>this.env.minLength&&this.hlMaxDuration.length<this.env.minLength?this.llMaxDuration:this.hlMaxDuration&&this.hlMaxDuration.length>this.env.minLength&&this.llMaxDuration.length<this.env.minLength?this.hlMaxDuration:null,this.is.line&&(this.is.lineIndex=this.is.line.index,this.is.state="h"==this.is.line.type?"fall":"rise",this.is.start=this.is.line.candlePoint)),this.is.state){this.is.size=Math.max(this.is.size,Math.abs(this.is.start.y-this.is.line.candlePoint.y));var n,o=this.lines.id[this.is.lineIndex]||this.lines.id["h"==this.is.line.type?0:1],r=null,h=null,l=this.lines.list["h"==o.type?1:0].filter((function(t){return s.lines.id[t].forked&&s.lines.id[t].thisPoint.x-s.lines.id[t].forkedAt>12}));l.length>1?l[1]:l.length>0&&l[0];var a=l.filter((function(t){return s.lines.id[t].forkedAt>s.is.start.x}));if(o&&this.lines.list["h"==o.type?0:1].forEach((function(t,i){var e=s.lines.id[t];if(t>=o.index&&null!=e.rollback){n=s.lines.list["h"==o.type?0:1][i-1];var l=1==s.env.deltaModel&&i>1&&n&&s.lines.id[n]?i>1&&n&&s.lines.id[n].lastForkY:s.lines.id[t>0?t-1:0];h=l?s.lines.id[t>1?n:"h"==o.type?0:1].lastForkY-e.candlePoint.y:e.rollback?e.rollback.lastForkValue-e.candlePoint.y:0,e.rollback.lastForkValue>0&&e.thisPoint.x-e.rollback.lastForkTime>s.env.minRightLeg&&("fall"==s.is.state?s.llMaxDuration.length>1:s.hlMaxDuration.length>1)&&(("h"==o.type?h<0:h>0)||e.rollback.length>s.env.rollbackLength||2*s.is.size/3>Math.abs(s.is.start.y-s.is.line.candlePoint.y)&&s.is.size>s.is.line.candlePoint.y*s.env.minIsSizeOnRollback&&a.length>1||("h"==o.type?e.candlePoint.y>s.is.start.y&&1==s.lines.list[0].length:e.candlePoint.y<s.is.start.y&&1==s.lines.list[1].length))&&(e.candlePoint.x-e.rollback.lastForkTime>s.env.forkDurationMin&&e.candlePoint.x-e.rollback.lastForkTime<s.env.forkDurationMax||("h"==o.type?e.candlePoint.y>e.startPoint.y:e.candlePoint.y<e.startPoint.y)||("h"==o.type?e.candlePoint.y>s.is.start.y&&1==s.lines.list[0].length:e.candlePoint.y<s.is.start.y&&1==s.lines.list[1].length))&&(r=t+1)}})),r){this.in.size=(this.was.size||0)+this.is.size;var u=this.lines.id[0].candlePoint.y-this.is.start.y,c="rise"==this.is.state?u>=0:u<0;this.was.size&&(this.in.state=this.was.size>this.is.size?this.was.state:this.is.state),this.was=e({},this.is),this.was.success=c,this.is.line="fall"==this.is.state?this.llMaxDuration:this.hlMaxDuration,this.is.state="h"==this.is.line.type?"fall":"rise",this.is.lineIndex=this.is.line.index,this.is.start=this.lines.id[0].candlePoint,this.is.size=0}}},t}(),h=function(){function t(t){this.hLineDirectives=[],this.lLineDirectives=[],this.step=1,this.i=0,this.localCounter=0,this.prevPoint=null,this.env=Object.assign({step:1,minLength:5,minRightLeg:3,maxForks:500,minLog:0,maxLog:0,rollbackLength:3,deltaModel:1,minIsSizeOnRollback:.05},t),this.env.minLength=Math.round(this.env.minLength/this.env.step)||1,this.env.minRightLeg=Math.round(this.env.minRightLeg/this.env.step)||1,this.env.rollbackLength=Math.round(this.env.rollbackLength/this.env.step)||1,this.env.forkDurationMin=Math.round(this.env.forkDurationMin/this.env.step)||1,this.env.forkDurationMax=Math.round(this.env.forkDurationMax/this.env.step)||1,this.lines=new o(this.step),this.trend=new r(this.lines,this.env)}return t.prototype.log=function(t){for(var i=arguments,e=[],n=1;n<arguments.length;n++)e[n-1]=i[n];this.consoleWindow=this.env.minLog<this.localCounter&&this.localCounter<this.env.maxLog,this.consoleWindow&&console.log.apply(console,s([t],e))},t.prototype.nextValue=function(t,i,e,s){var n,o=this;this.localCounter++,this.lLineDirectives.length>0&&this.lLineDirectives.forEach((function(t,i){var e=o.lines.id[t.lineIndex];"gt"==t.condition&&s>t.value&&"fork"==t.action&&e&&(null!=t.lineIndex&&null!=e&&e.k<0?o.lines.add(null,s,o.i-1,o.prevPoint,t.lineIndex):(e.forked=!0,e.forkedAt=e.thisPoint.x,e.forkedValue=e.thisPoint.y,o.lines.add(null,s,o.i-1,o.prevPoint)))})),this.hLineDirectives.length>0&&this.hLineDirectives.forEach((function(t,i){var s=o.lines.id[t.lineIndex];"lt"==t.condition&&e<t.value&&"fork"==t.action&&s&&(s.k>0?o.lines.add(e,null,o.i-1,o.prevPoint,t.lineIndex):(s.forked=!0,s.forkedAt=s.thisPoint.x,s.forkedValue=s.thisPoint.y,o.lines.add(e,null,o.i-1,o.prevPoint)))})),this.hLineDirectives.length=0,this.lLineDirectives.length=0,this.lines.list[0].length<1?(this.lines.add(e,null,this.i),this.lines.add(null,s,this.i)):this.lines.list.forEach((function(t){return t.forEach((function(t){var i=o.lines.id[t];if(i&&i.type){n=null,i&&i.startPoint.x<o.i&&(n=o.lines.update(t,e,s,o.i));var r=i.type;n&&("h"==r?o.hLineDirectives.push(n):o.lLineDirectives.push(n))}}))}));var r=[];return this.lines.list.forEach((function(t){t&&(r=[],t.forEach((function(i,e){var s=o.lines.id[t[e]],n=o.lines.id[t[e-1]];(e>0&&s&&n&&"h"==s.type&&s.thisPoint&&n.thisPoint.y<=s.thisPoint.y||e>o.env.maxForks||e>0&&s&&n&&"l"==s.type&&s.thisPoint&&n.thisPoint.y>=s.thisPoint.y||e>o.env.maxForks)&&r.push(i)})),r.forEach((function(t){return o.lines.delete(t)})))})),this.prevPoint={x:this.i,h:e,l:s},this.trend.update(this.lines.list[0],this.lines.list[1]),this.i++,this.lines},t}(),l=Object.freeze({__proto__:null,Indicator:h}),a=function(){function t(t){this.length=t,this.filled=!1,this.pointer=0,this.buffer=new Array(t),this.maxIndex=t-1}return t.prototype.push=function(t){var i=this.buffer[this.pointer];return this.buffer[this.pointer]=t,this.iteratorNext(),i},t.prototype.pushback=function(t){this.iteratorPrev();var i=this.buffer[this.pointer];return this.buffer[this.pointer]=t,i},t.prototype.peek=function(){return this.buffer[this.pointer]},t.prototype.forEach=function(t){for(var i=this.pointer,e=0;e!==this.length;)t(this.buffer[i],e),i=(this.length+i+1)%this.length,e++},t.prototype.forEachRight=function(t){for(var i=(this.length+this.pointer-1)%this.length,e=this.length-1;e!==this.length;)t(this.buffer[i],e),i=(this.length+i-1)%this.length,e--},t.prototype.fill=function(t){this.buffer.fill(t),this.filled=!0},t.prototype.toArray=function(){return this.buffer},t.prototype.iteratorNext=function(){this.pointer++,this.pointer>this.maxIndex&&(this.pointer=0,this.filled=!0)},t.prototype.iteratorPrev=function(){this.pointer--,this.pointer<0&&(this.pointer=this.maxIndex)},t}(),u=function(t){function e(i,e){void 0===i&&(i=100);var s=t.call(this,i)||this;return s.period=i,s.mode=e,s.comparator="max"===e?s.maxComporator:s.mminComporator,s}return function(t,e){function s(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}(e,t),e.prototype.nextValue=function(t){return this.push(t),this.getExtremum()},e.prototype.momentValue=function(t){var i=this.push(t),e=this.getExtremum();return this.pushback(i),e},e.prototype.maxComporator=function(t,i){return t>i},e.prototype.mminComporator=function(t,i){return t<i},e.prototype.getExtremum=function(t){var i=(this.length+this.pointer-2)%this.length,e="max"===this.mode?-1/0:1/0;if(!this.filled)return 0;for(;i!==this.pointer;){var s=this.buffer[(this.length+i-1)%this.length],n=this.buffer[(this.length+i+1)%this.length],o=this.buffer[i];if(this.comparator(o,e)&&this.comparator(o,s)&&this.comparator(o,n)){if(e=o,this.prevIx===i)return null;if(this.prevIx=i,t)return e}i=(this.length+i-1)%this.length}return isFinite(e)?e:(this.prevIx=null,null)},e}(a),c=function(){function t(t){this.period=t,this.sum=0,this.circular=new a(t)}return t.prototype.nextValue=function(t){var i=this;if(this.circular.push(t),this.sum+=t,this.circular.filled)return this.nextValue=function(t){return i.sum=i.sum-i.circular.push(t)+t,i.sum/i.period},this.momentValue=function(t){return(i.sum-i.circular.peek()+t)/i.period},this.sum/this.period},t.prototype.momentValue=function(t){},t}(),p=function(){function t(t){this.period=t,this.smooth=1/this.period,this.sma=new c(this.period)}return t.prototype.nextValue=function(t){return this.wema?this.wema=(t-this.wema)*this.smooth+this.wema:this.wema=this.sma.nextValue(t)},t.prototype.momentValue=function(t){return this.wema?(t-this.wema)*this.smooth+this.wema:this.sma.momentValue(t)},t}(),d=function(){function t(t){this.period=t,this.smooth=2/(this.period+1),this.sma=new c(this.period)}return t.prototype.nextValue=function(t){var i=this,e=this.sma.nextValue(t);return e&&(this.ema=e,this.nextValue=function(t){return i.ema=(t-i.ema)*i.smooth+i.ema},this.momentValue=function(t){return(t-i.ema)*i.smooth+i.ema}),e},t.prototype.momentValue=function(t){},t}(),m=function(){function t(t,i){this.indicator=t,this.samples=i,this._indicators=[]}return t.prototype.create=function(){for(var t,i=arguments,e=[],n=0;n<arguments.length;n++)e[n]=i[n];for(var o=0;o<this.samples;o++)this._indicators.push(new((t=this.indicator).bind.apply(t,s([void 0],e))))},t.prototype.nextValue=function(t){for(var i=0;i<this.samples;i++)if(void 0===(t=this._indicators[i].nextValue(t)))return t;return t},t.prototype.momentValue=function(t){for(var i=0;i<this.samples;i++)if(null==(t=this._indicators[i].momentValue(t)))return t;return t},t}(),f=function(){function t(t,i,e,s,n){void 0===t&&(t=.85),void 0===s&&(s=1),void 0===n&&(n=1),this.redunant=t,this.multiplier=s,this.offset=n,this.prevValue=0,this.lastUpperValue=0,this.lastLowerValue=0,this.samplerUp=new m(i,e),this.samplerLow=new m(i,e)}return t.prototype.create=function(){for(var t,i,e=arguments,s=[],n=0;n<arguments.length;n++)s[n]=e[n];(t=this.samplerUp).create.apply(t,s),(i=this.samplerLow).create.apply(i,s)},t.prototype.nextValue=function(t){this.lastUpperValue=t>0?Math.max(t,this.prevValue):Math.max(0,this.lastUpperValue)*this.redunant,this.lastLowerValue=t<=0?Math.min(t,this.prevValue):Math.min(0,this.lastLowerValue)*this.redunant;var i=(t<=0?t:this.lastLowerValue)*this.multiplier,e=(t>=0?t:this.lastUpperValue)*this.multiplier;return[this.samplerUp.nextValue(e)+this.offset,this.samplerLow.nextValue(i)-this.offset]},t}(),v=function(){function t(t,i,e,s){void 0===e&&(e=.85),void 0===s&&(s="WEMA"),this.period=t,this.samples=i,this.redunant=e,this.type=s,this.upper=0,this.lower=0,this.lastUpperValue=0,this.lastLowerValue=0,this.sample1Up=this.createSample(),this.sample2Up=this.createSample(),this.sample3Up=this.createSample(),this.sample1Low=this.createSample(),this.sample2Low=this.createSample(),this.sample3Low=this.createSample()}return t.prototype.nextValue=function(t){return t>0?(this.upper=this.getUp(t),this.lastLowerValue*=this.redunant,this.lower=this.getDown(this.lastLowerValue),this.lastUpperValue=t):t<0&&(this.lower=this.getDown(t),this.lastUpperValue*=this.redunant,this.upper=this.getUp(this.lastUpperValue),this.lastLowerValue=t),{upper:this.upper,lower:this.lower}},t.prototype.getUp=function(t){var i=this.sample1Up.nextValue(t),e=null;return 1===this.samples?i:(i&&(e=this.sample2Up.nextValue(i)),2===this.samples?e:e?this.sample3Up.nextValue(e):null)},t.prototype.getDown=function(t){var i=this.sample1Low.nextValue(t),e=null;return 1===this.samples?i:(i&&(e=this.sample2Low.nextValue(i)),2===this.samples?e:e?this.sample3Low.nextValue(e):null)},t.prototype.createSample=function(){switch(this.type){case"EMA":return new d(this.period);case"WEMA":return new p(this.period);case"SMA":return new c(this.period)}},t}(),g=function(){function t(t){this.period=t,this.SMAx=new c(this.period),this.SMAy=new c(this.period),this.pricesX=new a(this.period),this.pricesY=new a(this.period)}return t.prototype.nextValue=function(t,i){this.pricesX.push(t),this.pricesY.push(i),this.SMAxValue=this.SMAx.nextValue(t),this.SMAyValue=this.SMAy.nextValue(i);for(var e=0,s=0,n=0,o=0;o<this.period;o++){var r=this.pricesX.toArray()[o],h=this.pricesY.toArray()[o];e+=(r-this.SMAxValue)*(h-this.SMAyValue),s+=Math.pow(r-this.SMAxValue,2),n+=Math.pow(h-this.SMAyValue,2)}return e/Math.sqrt(s*n)},t}(),w=function(){function t(t){this.period=t,this.denominator=t*(t+1)/2,this.buffer=new a(t),this.values=[]}return t.prototype.nextValue=function(t){var i=this;if(this.buffer.push(t),this.buffer.filled){var e=0;return this.buffer.forEach((function(t,s){e+=t*(s+1)/i.denominator})),e}},t.prototype.momentValue=function(t){var i=this,e=this.buffer.push(t);if(this.buffer.filled){var s=0;return this.buffer.forEach((function(t,e){s+=t*(e+1)/i.denominator})),this.buffer.pushback(e),s}this.buffer.pushback(e)},t}(),x=function(){function t(t){void 0===t&&(t=.2),this.alpha=t,this.filled=!1}return t.prototype.nextValue=function(t){var i=this.alpha*t+(1-this.alpha)*(this.prevValue||1);if(this.filled=this.filled||void 0!==this.prevValue,this.prevValue=i,this.filled)return i},t.prototype.momentValue=function(t){if(this.filled)return this.alpha*t+(1-this.alpha)*(this.prevValue||1)},t}(),V=function(){function t(t){this.period=t,this.sum=0,this.avg=0,this.filled=!1,this.fill=0}return t.prototype.nextValue=function(t){var i=this;return this.filled?(this.nextValue=function(t){return i.avg=(i.avg*(i.period-1)+t)/i.period},this.nextValue(t)):(this.sum+=t,this.fill++,this.fill===this.period?(this.filled=!0,this.avg=this.sum/this.period,this.avg):void 0)},t.prototype.momentValue=function(t){if(this.filled)return(this.avg*(this.period-1)+t)/this.period},t}(),y=function(){function t(t){void 0===t&&(t=14),this.period=t,this.alpha=1/t,this.sma=new c(this.period)}return t.prototype.nextValue=function(t){var i=this;return this.prevValue?(this.prevValue=this.alpha*t+(1-this.alpha)*this.prevValue,this.nextValue=function(t){return i.prevValue=i.alpha*t+(1-i.alpha)*i.prevValue,i.prevValue}):this.prevValue=this.sma.nextValue(t),this.prevValue},t.prototype.momentValue=function(t){if(this.prevValue)return this.alpha*t+(1-this.alpha)*this.prevValue},t}(),M=function(){function t(t,i){void 0===t&&(t=5),void 0===i&&(i=34),this.smaSlow=new c(i),this.smaFast=new c(t)}return t.prototype.nextValue=function(t,i){var e=this;if(this.smaSlowValue=this.smaSlow.nextValue((t+i)/2),this.smaFastValue=this.smaFast.nextValue((t+i)/2),void 0!==this.smaSlowValue&&void 0!==this.smaFastValue)return this.nextValue=function(t,i){return e.smaSlowValue=e.smaSlow.nextValue((t+i)/2),e.smaFastValue=e.smaFast.nextValue((t+i)/2),e.smaFastValue-e.smaSlowValue},this.momentValue=function(t,i){return e.smaFast.momentValue((t+i)/2)-e.smaSlow.momentValue((t+i)/2)},this.smaFastValue-this.smaSlowValue},t.prototype.momentValue=function(t,i){},t}(),P=function(){function t(){this.sma=new c(5),this.ao=new M}return t.prototype.nextValue=function(t,i){var e=this;if(this.aoValue=this.ao.nextValue(t,i),void 0!==this.aoValue&&(this.smaValue=this.sma.nextValue(this.aoValue),void 0!==this.smaValue))return this.nextValue=function(t,i){return e.aoValue=e.ao.nextValue(t,i),e.smaValue=e.sma.nextValue(e.aoValue),e.aoValue-e.smaValue},this.momentValue=function(t,i){return e.ao.momentValue(t,i)-e.sma.momentValue(e.aoValue)},this.aoValue-this.smaValue},t.prototype.momentValue=function(t,i){},t}(),k=function(t,i){return(t-i)/i*100},b=function(){function t(t){this.period=t,this.value=0,this.changes=new a(t)}return t.prototype.nextValue=function(t){if(this.prevPrice){var i=k(t,this.prevPrice);return this.calculate(i),this.prevPrice=t,this.value}this.prevPrice=t},t.prototype.calculate=function(t){return this.value+=t,this.value-=this.changes.push(t),this.value},t}();function A(t){return t.consolidate=0,t.power=0,t.streak=0,t.diff=0,t.startPrice=0,t.prevPeak=0,t}var S=function(){function t(){this.up={consolidate:0,power:0,streak:0,startPrice:0,diff:0,prevPeak:0},this.down={consolidate:0,power:0,streak:0,startPrice:0,diff:0,prevPeak:0}}return t.prototype.nextValue=function(t,i,s,n){if(t<i||this.up.streak&&this.up.prevPeak<n){this.up.startPrice||(this.up.startPrice=t),this.down.streak&&A(this.down);var o=i-t;this.up.streak++,this.up.prevPeak=n,this.up.diff>o?this.up.consolidate++:this.up.consolidate=0,this.up.diff=o,this.up.power=k(i,this.up.startPrice)}return(t>i||this.down.streak&&this.down.prevPeak>s)&&(this.down.startPrice||(this.down.startPrice=t),this.up.streak&&A(this.up),o=t-i,this.down.streak++,this.down.prevPeak=s,this.down.diff>o?this.down.consolidate++:this.down.consolidate=0,this.down.diff=o,this.down.power=k(i,this.down.startPrice)),t===i&&(this.up.streak++,this.down.streak++,this.up.diff=this.down.diff=0),this.up.streak>this.down.streak?e({},this.up):e({},this.down)},t}(),L=function(){function t(t){this.max=-1/0,this.highest=new a(t)}return t.prototype.filled=function(){return this.highest.filled},t.prototype.nextValue=function(t){return this.max<t&&(this.max=t),this.highest.push(t)===this.max&&t!==this.max&&(this.max=function(t){for(var i=-1/0,e=t.length-1;e>=0;e--){var s=t[e];i<s&&(i=s)}return i}(this.highest.toArray())),this.max},t.prototype.momentValue=function(t){return this.max>t?this.max:t},t}(),D=function(){function t(t){this.min=1/0,this.lowest=new a(t)}return t.prototype.filled=function(){return this.lowest.filled},t.prototype.nextValue=function(t){return this.min>t&&(this.min=t),this.lowest.push(t)===this.min&&t!==this.min&&(this.min=function(t){for(var i=1/0,e=t.length-1;e>=0;e--){var s=t[e];i>s&&(i=s)}return i}(this.lowest.toArray())),this.min},t.prototype.momentValue=function(t){return this.min<t?this.min:t},t}(),C=function(){function t(t,i){void 0===t&&(t=14),void 0===i&&(i=3),this.period=t,this.smaPeriod=i,this.sma=new c(this.smaPeriod),this.max=new L(t),this.min=new D(t)}return t.prototype.nextValue=function(t,i,e){var s=this.max.nextValue(t),n=this.min.nextValue(i);if(this.max.filled()){var o=(e-n)/(s-n)*100;return{k:o,d:this.sma.nextValue(o)}}},t.prototype.momentValue=function(t,i,e){if(this.max.filled()){var s=this.max.momentValue(t),n=this.min.momentValue(i),o=(e-n)/(s-n)*100;return{k:o,d:this.sma.momentValue(o)}}},t}(),F=function(){function t(t){this.avgGain=new V(t),this.avgLoss=new V(t)}return t.prototype.nextValue=function(t){var i=t-this.prev;if(this.prev){var e=i>0?i:0,s=i<0?i:0,n=this.avgGain.nextValue(e),o=this.avgLoss.nextValue(s);return this.prev=t,{upAvg:n,downAvg:o}}this.prev=t},t.prototype.momentValue=function(t){var i=t-this.prev,e=i>0?i:0,s=i<0?i:0;return{upAvg:this.avgGain.momentValue(e),downAvg:this.avgLoss.momentValue(s)}},t}(),I=function(){function t(t){void 0===t&&(t=14),this.period=t,this.change=new F(this.period)}return t.prototype.nextValue=function(t){var i=this.change.nextValue(t)||{},e=i.downAvg,s=i.upAvg;if(void 0!==s&&void 0!==e)return 100-100/(1+s/-e)},t.prototype.momentValue=function(t){var i=this.change.momentValue(t)||{},e=i.downAvg,s=i.upAvg;if(void 0!==s&&void 0!==e)return 100-100/(1+s/-e)},t}(),B=function(){function t(t,i,e,s){void 0===t&&(t=14),void 0===i&&(i=3),void 0===e&&(e=3),void 0===s&&(s=14),this.rsi=new I(t),this.sma1=new c(i),this.sma2=new c(e),this.max=new L(s),this.min=new D(s)}return t.prototype.nextValue=function(t){var i=this.rsi.nextValue(t);if(void 0!==i){var e=this.max.nextValue(i),s=this.min.nextValue(i);if(this.max.filled()){var n=(i-s)/(e-s)*100,o=this.sma1.nextValue(n);if(void 0!==o)return{k:o,d:this.sma2.nextValue(o),stochRsi:n}}}},t.prototype.momentValue=function(t){if(this.max.filled()){var i=this.rsi.momentValue(t),e=this.max.momentValue(i),s=this.min.momentValue(i),n=(i-s)/(e-s)*100,o=this.sma1.momentValue(n);return{k:o,d:this.sma2.momentValue(o),stochRsi:n}}},t}(),_=function(){function t(t){this.period=t,this.values=new a(t)}return t.prototype.nextValue=function(t,i){if(i)return this.nextValue=this.pureNextValue,this.momentValue=this.pureMomentValue,this.pureNextValue(t,i);this.values.push(t)},t.prototype.momentValue=function(t,i){},t.prototype.pureNextValue=function(t,i){var e=this;return this.values.push(t),this.values.toArray().reduce((function(t,s){return t+e.positiveDelta(i,s)}),0)/this.period},t.prototype.pureMomentValue=function(t,i){var e=this,s=this.values.push(t),n=this.values.toArray().reduce((function(t,s){return t+e.positiveDelta(i,s)}),0);return this.values.pushback(s),n/this.period},t.prototype.positiveDelta=function(t,i){return t>i?t-i:i-t},t}(),T=function(){function t(t){void 0===t&&(t=20),this.md=new _(t),this.sma=new c(t)}return t.prototype.nextValue=function(t,i,e){var s=(t+i+e)/3,n=this.sma.nextValue(s),o=this.md.nextValue(s,n);return o&&(s-n)/(.015*o)},t.prototype.momentValue=function(t,i,e){var s=(t+i+e)/3,n=this.sma.momentValue(s),o=this.md.momentValue(s,n);return o&&(s-n)/(.015*o)},t}(),E=function(){function t(t){this.period=t,this.arr=[],this.filled=!1,this.devider=0,this.lastSum=0,this.devider=function(t){for(var i=0,e=t.length;e>0;)i+=t[--e];return i}(Array.from(Array(this.period).keys()).map((function(t){return t+1})))}return t.prototype.nextValue=function(t){if(this.filled=this.filled||this.arr.length===this.period,this.arr.push(t),this.filled)return this.arr.shift(),this.arr.reduce((function(t,i,e){return t+i*(e+1)}),0)/this.devider},t.prototype.momentValue=function(t){if(this.filled){var i=this.arr.slice(1);return i.push(t),i.reduce((function(t,i,e){return t+i*(e+1)}),0)/this.devider}},t}();function O(t,i,e){if(e){var s=t-i,n=t>e?t-e:e-t,o=i>e?i-e:e-i;return s>=n&&s>=o?s:n>=s&&n>=o?n:o}}var R=function(){function t(t,i){switch(void 0===t&&(t=14),void 0===i&&(i="WEMA"),i){case"SMA":this.avg=new c(t);break;case"EMA":this.avg=new d(t);break;case"SMMA":this.avg=new V(t);break;case"WEMA":this.avg=new p(t);break;case"LWMA":this.avg=new E(t);break;case"EWMA":this.avg=new x(.2);break;case"RMA":this.avg=new y(t)}this.prevClose=0}return t.prototype.nextValue=function(t,i,e){var s=O(t,i,this.prevClose);if(this.prevClose=e,void 0!==s)return this.avg.nextValue(s)},t.prototype.momentValue=function(t,i){var e=O(t,i,this.prevClose);if(void 0!==e)return this.avg.momentValue(e)},t}(),U=function(){function t(t){void 0===t&&(t=5),this.values=new a(t)}return t.prototype.nextValue=function(t){var i=this.values.push(t);if(i)return(t-i)/i*100},t.prototype.momentValue=function(t){var i=this.values.peek();if(i)return(t-i)/i*100},t}(),N=function(){function t(t){void 0===t&&(t=20),this.maxProvider=new L(t),this.minProvider=new D(t)}return t.prototype.nextValue=function(t,i){var e=this.maxProvider.nextValue(t),s=this.minProvider.nextValue(i);return{upper:e,middle:(e+s)/2,lower:s}},t.prototype.momentValue=function(t,i){var e=this.maxProvider.momentValue(t),s=this.minProvider.momentValue(i);return{upper:e,middle:(e+s)/2,lower:s}},t}(),W=function(){function t(t){this.period=t,this.fill=0,this.values=new a(t)}return t.prototype.nextValue=function(t){var i=this;if(this.values.push(t),this.fill++,this.fill===this.period)return this.nextValue=function(t){var e=i.calc(t);return i.values.push(t),e},this.momentValue=this.calc,this.calc(t)},t.prototype.momentValue=function(t){},t.prototype.calc=function(t){var i=0;return this.values.toArray().forEach((function(e){e<=t&&i++})),i/this.period*100},t}(),H=function(){function t(t,i,e){void 0===t&&(t=3),void 0===i&&(i=2),void 0===e&&(e=100),this.period=t,this.rsi=new I(this.period),this.updownRsi=new I(i),this.roc=new U(1),this.percentRank=new W(e),this.updownPeriod=0,this.prevClose=0}return t.prototype.nextValue=function(t){var i=this.rsi.nextValue(t),e=this.percentRank.nextValue(this.roc.nextValue(t));if(this.updownPeriod=this.getUpdownPeriod(t),this.prevClose=t,this.updownValue=this.updownRsi.nextValue(this.updownPeriod),this.updownValue)return(i+this.updownValue+e)/3},t.prototype.momentValue=function(t){var i=this.rsi.momentValue(t),e=this.percentRank.momentValue(this.roc.momentValue(t)),s=this.getUpdownPeriod(t),n=this.updownRsi.momentValue(s);if(void 0!==n)return(i+n+e)/3},t.prototype.getUpdownPeriod=function(t){var i=this.updownPeriod;return t>this.prevClose?(this.updownPeriod<0&&(i=0),i++):t<this.prevClose?(this.updownPeriod>0&&(i=0),i--):i=0,i},t}(),z=function(){function t(t){this.period=t,this.values=new a(t)}return t.prototype.nextValue=function(t,i){return this.values.push(t),Math.sqrt(this.values.toArray().reduce((function(t,e){return t+Math.pow(e-i,2)}),0)/this.period)},t.prototype.momentValue=function(t,i){var e=this.values.push(t),s=Math.sqrt(this.values.toArray().reduce((function(t,e){return t+Math.pow(e-i,2)}),0)/this.period);return this.values.pushback(e),s},t}(),j=function(){function t(t,i){void 0===t&&(t=20),void 0===i&&(i=2),this.period=t,this.stdDev=i,this.fill=0,this.sma=new c(t),this.sd=new z(t)}return t.prototype.nextValue=function(t){var i=this,e=this.sma.nextValue(t),s=this.sd.nextValue(t,e);if(this.fill++,this.fill===this.period){var n=e-this.stdDev*s,o=e+this.stdDev*s;return this.nextValue=function(t){var e=i.sma.nextValue(t),s=i.sd.nextValue(t,e);return{lower:e-i.stdDev*s,middle:e,upper:e+i.stdDev*s}},{lower:n,middle:e,upper:o}}},t.prototype.momentValue=function(t){var i=this.sma.momentValue(t),e=this.sd.momentValue(t,i);return{lower:i-this.stdDev*e,middle:i,upper:i+this.stdDev*e}},t}(),$=function(){function t(t,i,e){void 0===t&&(t=12),void 0===i&&(i=26),void 0===e&&(e=9),this.periodEmaFast=t,this.periodEmaSlow=i,this.periodSignal=e,this.emaFastIndicator=new d(t),this.emaSlowIndicator=new d(i),this.emaSignalIndicator=new d(e)}return t.prototype.nextValue=function(t){var i=this.emaFastIndicator.nextValue(t),e=this.emaSlowIndicator.nextValue(t),s=i-e,n=s&&this.emaSignalIndicator.nextValue(s)||void 0,o=s-n||void 0;if(!isNaN(s))return{macd:s,emaFast:i,emaSlow:e,signal:n,histogram:o}},t.prototype.momentValue=function(t){var i=this.emaFastIndicator.momentValue(t),e=this.emaSlowIndicator.momentValue(t),s=i-e,n=s&&this.emaSignalIndicator.momentValue(s);return{macd:s,emaFast:i,emaSlow:e,signal:n,histogram:s-n}},t}(),Y=function(){function t(){this.prevOpen=0,this.prevClose=0}return t.prototype.nextValue=function(t,i,e,s){var n=this.calculate(t,i,e,s);return this.prevClose=n.c,this.prevOpen=n.o,n},t.prototype.momentValue=function(t,i,e,s){return this.calculate(t,i,e,s)},t.prototype.calculate=function(t,i,e,s){return s=(t+i+e+s)/4,this.prevOpen&&(t=(this.prevOpen+this.prevClose)/2),{o:t,h:i=Math.max(i,t,s),l:e=Math.min(e,t,s),c:s}},t}(),q=function(){function t(t){switch(void 0===t&&(t="classic"),this.mode=t,this.mode){case"classic":this.calculator=this.classic;break;case"camarilla":this.calculator=this.camarilla;break;case"woodie":this.calculator=this.woodie;break;case"fibonacci":this.calculator=this.fibonacci}}return t.prototype.nextValue=function(t,i,e){return this.calculator(t,i,e)},t.prototype.classic=function(t,i,e){var s=(t+i+e)/3;return{r3:t+2*(s-i),r2:s+(t-i),r1:2*s-i,pp:s,s1:2*s-t,s2:s-(t-i),s3:i-2*(t-s)}},t.prototype.woodie=function(t,i,e){var s=(t+i+2*e)/4;return{r2:s+t-i,r1:2*s-i,pp:s,s1:2*s-t,s2:s-t+i}},t.prototype.camarilla=function(t,i,e){var s=1.1*(t-i),n=t/i*e,o=e+s/2,r=n+1.168*(n-o);return{r6:r,r5:n,r4:o,r3:e+s/4,r2:e+s/6,r1:e+s/12,pp:(t+i+e)/3,s1:e-s/12,s2:e-s/6,s3:e-s/4,s4:e-s/2,s5:e-(n-e),s6:e-(r-e)}},t.prototype.fibonacci=function(t,i,e){var s=t-i,n=(t+i+e)/3;return{r3:n+s,r2:n+.618*s,r1:n+.382*s,pp:n,s1:n-.382*s,s2:n-.618*s,s3:n-s}},t}(),X=function(){function t(t,i,e){void 0===t&&(t=.02),void 0===i&&(i=.02),void 0===e&&(e=.2),this.start=t,this.acceleration=i,this.max=e,this.result=0,this.isBullTrend=!0}return t.prototype.nextValue=function(t,i,e){if(!this.result)return this.result=e,this.low1=i,this.high1=t,this.low2=i,this.high2=t,this.highest=t,this.lowest=i,this.accelerationFactor=this.start,i;if(this.isBullTrend?this.psar=this.result+this.accelerationFactor*(this.highest-this.result):this.psar=this.result+this.accelerationFactor*(this.lowest-this.result),this.isBullTrend)if(i<this.psar)this.isBullTrend=!1,this.psar=this.highest,this.lowest=i,this.accelerationFactor=this.start;else{if(t>this.highest){this.highest=t;var s=this.accelerationFactor+this.acceleration;this.accelerationFactor=s>this.max?this.max:s}this.low1<this.psar&&(this.psar=this.low1),this.low2<this.psar&&(this.psar=this.low2)}else t>this.psar?(this.isBullTrend=!0,this.psar=this.lowest,this.highest=t,this.accelerationFactor=this.start):(i<this.lowest&&(this.lowest=i,s=this.accelerationFactor+this.acceleration,this.accelerationFactor=s>this.max?this.max:s),this.high1>this.psar&&(this.psar=this.high1),this.high2>this.psar&&(this.psar=this.high2));return this.low2=this.low1,this.low1=i,this.high2=this.high1,this.high1=t,this.result=this.psar,this.result},t.prototype.momentValue=function(t,i){if(!this.result)return i;var e,s=this.isBullTrend,n=this.result,o=this.low1,r=this.high1,h=this.low2,l=this.high2,a=this.highest,u=this.lowest,c=this.accelerationFactor;return e=s?n+c*(a-n):n+c*(u-n),s?i<e?e=a:(o<e&&(e=o),h<e&&(e=h)):t>e?e=u:(r>e&&(e=r),l>e&&(e=l)),e},t}(),G=function(){function t(t){this.period=t,this.prevValue=0,this.sumCount=1}return t.prototype.nextValue=function(t){var i=this;return this.sumCount<this.period?(this.prevValue+=t,void this.sumCount++):this.sumCount===this.period?(this.prevValue+=t,this.sumCount++,this.nextValue=function(t){return i.prevValue=i.prevValue-i.prevValue/i.period+t},this.prevValue):void 0},t.prototype.momentValue=function(t){if(!(this.sumCount<this.period))return this.prevValue-this.prevValue/this.period+t},t}(),K=function(){function t(t){void 0===t&&(t=14),this.period=t,this.wma1=new G(t),this.wma2=new G(t),this.wma3=new G(t),this.wema=new p(t)}return t.prototype.nextValue=function(t,i,e){if(!this.prevClose)return this.prevHigh=t,this.prevLow=i,void(this.prevClose=e);var s=0,n=0,o=t-this.prevHigh,r=this.prevLow-i;o>r&&o>0&&(s=o),r>o&&r>0&&(n=r),(s>n||n<0)&&(n=0);var h=this.wma1.nextValue(O(t,i,this.prevClose)),l=this.wma2.nextValue(s),a=this.wma3.nextValue(n);if(this.prevHigh=t,this.prevLow=i,this.prevClose=e,void 0!==l&&void 0!==a){var u=100*l/h,c=100*a/h,p=u>c?u-c:c-u;return{adx:this.wema.nextValue(p/(u+c)*100),pdi:u,mdi:c}}},t.prototype.momentValue=function(t,i,e){if(this.prevClose){var s=0,n=0,o=t-this.prevHigh,r=this.prevLow-i;o>r&&o>0&&(s=o),r>o&&r>0&&(n=r),(s>n||n<0)&&(n=0);var h=this.wma1.momentValue(O(t,i,this.prevClose)),l=this.wma2.momentValue(s),a=this.wma3.momentValue(n);if(void 0!==l&&void 0!==a){var u=100*l/h,c=100*a/h,p=u>c?u-c:c-u;return{adx:this.wema.momentValue(p/(u+c)*100),pdi:u,mdi:c}}}},t}(),J=function(){function t(t,i,e){void 0===t&&(t=10),void 0===i&&(i=3),void 0===e&&(e="WEMA"),this.multiplier=i,this.atr=new R(t,e)}return t.prototype.nextValue=function(t,i,e){var s=this.atr.nextValue(t,i,e);if(s){var n=(t+i)/2,o=n+this.multiplier*s,r=n-this.multiplier*s;this.prevLower&&(r=r>this.prevLower||this.prevClose<this.prevLower?r:this.prevLower,o=o<this.prevUpper||this.prevClose>this.prevUpper?o:this.prevUpper);var h,l=(h=this.prevSuper===this.prevUpper?e>o?r:o:e<r?o:r)===o?1:-1;return this.prevUpper=o,this.prevLower=r,this.prevSuper=h,this.prevClose=e,{upper:o,lower:r,superTrend:h,direction:l}}},t.prototype.momentValue=function(t,i,e){var s=this.atr.momentValue(t,i),n=(t+i)/2,o=n+this.multiplier*s,r=n-this.multiplier*s;this.prevLower&&(r=r>this.prevLower||this.prevClose<this.prevLower?r:this.prevLower,o=o<this.prevSuper||this.prevClose>this.prevUpper?o:this.prevUpper);var h;return{upper:o,lower:r,superTrend:h=this.prevSuper===this.prevUpper?e>o?r:o:e<r?o:r,direction:h===o?1:-1}},t}(),Q=function(t){return(t.o+t.h+t.l+t.c)/4},Z=function(){function t(t,i){void 0===t&&(t=4),void 0===i&&(i=Q),this.sum=0,this.sessionPricesLookup=new Set,this.sessionVolumes={},this.prevCandle=null,this.source=i,this.precision=t,this.valueToRoundWith=Math.pow(10,this.precision)}return t.prototype.getSession=function(t,i){var e=this;void 0===i&&(i=15);var s=this.source(t),n=1/0,o=s;this.sessionPricesLookup.forEach((function(t){var r=e.diffPercent(t,s);r>i?(e.sessionPricesLookup.delete(t),delete e.sessionVolumes[t]):r<n&&(n=r,o=t)}));var r=Array.from(this.sessionPricesLookup).sort(),h=r.indexOf(o),l=new Map;if(-1===h)return l;for(var a=Math.round(r.length/4),u=0,c=0;c<4;c++){for(var p=c*a,d=p+a,m=0,f=0,v=p;v<d;v++){var g=r[p],w=this.sessionVolumes[g];m<w&&(m=w,f=g)}this.diffPercent(u,f)<1&&(m=l.get(u)+m,f=this.roundPrice((f+u)/2),l.delete(u)),l.set(f,m),u=f}return l},t.prototype.getSessionAvg=function(){return this.sum/this.sessionPricesLookup.size},t.prototype.getRawSession=function(){return this.sessionVolumes},t.prototype.nextValue=function(t){var i,e=this.roundPrice(this.source(t)),s=(null===(i=this.prevCandle)||void 0===i?void 0:i.time)===t.time?t.v-this.prevCandle.v:t.v;this.addToSession(e,s),this.sum+=s,this.lastPrice=e,this.prevCandle=t},t.prototype.roundPrice=function(t){return Math.round((t+Number.EPSILON)*this.valueToRoundWith)/this.valueToRoundWith},t.prototype.addToSession=function(t,i){this.sessionPricesLookup.has(t)?this.sessionVolumes[t]+=i:(this.sessionPricesLookup.add(t),this.sessionVolumes[t]=i)},t.prototype.diffPercent=function(t,i){return t<i?100*(i-t)/t:100*(t-i)/i},t}(),tt=function(){function t(t,i){void 0===t&&(t=3),void 0===i&&(i=10),this.accDistribution=0,this.emaFast=new d(t),this.emaSlow=new d(i)}return t.prototype.nextValue=function(t,i,e,s){return this.accDistribution+=e===t&&e===i||t===i?0:(2*e-i-t)/(t-i)*s,this.emaFast.nextValue(this.accDistribution)-this.emaSlow.nextValue(this.accDistribution)},t.prototype.momentValue=function(t,i,e,s){var n=this.accDistribution+(e===t&&e===i||t===i?0:(2*e-i-t)/(t-i)*s);return this.emaFast.momentValue(n)-this.emaSlow.momentValue(n)},t}();t.AC=P,t.ADX=K,t.AO=M,t.ATR=R,t.BollingerBands=j,t.CCI=T,t.ChaikinOscillator=tt,t.CircularBuffer=a,t.Correlation=g,t.DC=N,t.EMA=d,t.EWMA=x,t.Extremums=u,t.HeikenAshi=Y,t.LWMA=E,t.Level=v,t.MACD=$,t.Move=b,t.PSAR=X,t.Pivot=q,t.RMA=y,t.ROC=U,t.RSI=I,t.SMA=c,t.SMMA=V,t.Sampler=m,t.StandardDeviation=z,t.Stochastic=C,t.StochasticRSI=B,t.SuperTrend=J,t.TrendLines=l,t.UniLevel=f,t.VolumeProfile=Z,t.WEMA=p,t.WMA=w,t.WWS=G,t.Wave=S,t.cRSI=H,Object.defineProperty(t,"__esModule",{value:!0})}(i)}},i={};function e(s){var n=i[s];if(void 0!==n)return n.exports;var o=i[s]={exports:{}};return t[s].call(o.exports,o,o.exports,e),o.exports}e.d=(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},e.o=(t,i)=>Object.prototype.hasOwnProperty.call(t,i),e.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};(()=>{"use strict";e.r(s),e.d(s,{default:()=>c});var t=e(978);const i=(i,e)=>{const s=[],n=new t.EMA(e);return i.forEach((t=>{s.push(n.nextValue(t))})),s},n=(i,e)=>{const s=[],n=new t.SMA(e);return i.forEach((t=>{s.push(n.nextValue(t))})),s},o=(t,i)=>{var e;return(0===(e=t.map(((t,e)=>t>i[e]?"up":t<i[e]?"down":"neutral")).reverse()).length?[]:e.reduce(((t,i,e,s)=>{if(0===e)t.push([i]);else{const n=s[e-1],o=t[t.length-1];i!==n?t.push([i]):o.push(i)}return t}),[])).map((t=>{const i=t.length;return t.map(((t,e)=>{let s=i-e;return"down"===t?-s:"up"===t?s:0}))})).flat().reverse()},r=(t,i)=>{let{upper:e,lower:s}=i;const n=e.map(((t,i)=>t-s[i]));return t.map(((t,i)=>(t-s[i])/n[i]*100))},h={getSMA:n,getEMA:i},l=(t,i=10)=>{const{open:e,high:s,low:n,close:o,volume:r}=t,h=Math.min(...n),l=(Math.max(...s)-h)/i,u={upVolume:0,downVolume:0,grossVolume:0},c=Array.from({length:i},((t,i)=>({price:h+l*i,upVolume:0,downVolume:0,grossVolume:0}))),p=1/l;for(let t=0;t<o.length;t++){const l=o[t],a=e[t],u=s[t],d=n[t],m=r[t],f=l>=a?m:0,v=l<a?m:0,g=Math.max(0,Math.floor((d-h)*p)),w=Math.min(i,Math.ceil((u-h)*p));for(let t=g;t<w;t++)c[t].upVolume+=f,c[t].downVolume+=v,c[t].grossVolume+=f+v}for(const{upVolume:t,downVolume:i,grossVolume:e}of c)u.upVolume+=t,u.downVolume+=i,u.grossVolume+=e;return{bins:c,nodes:a(c)}},a=t=>{if(!t||0===t.length)throw new Error("Bins array is empty or not provided");let i=t[0],e=t[0];return t.forEach((t=>{t.grossVolume>i.grossVolume&&(i=t),t.grossVolume<e.grossVolume&&(e=t)})),{highestVolumeNode:i,lowestVolumeNode:e}};class u{constructor({open:t,high:i,low:e,close:s,volume:n}){this.open=t,this.high=i,this.low=e,this.close=s,this.volume=n}init(){if(this.close.length<200)return console.log("PatternRecognizer requires at least 200 datapoints"),{pattern:"Neutral",name:"No Pattern",score:0};const t=[{name:"Bullish Flag",condition:this.isBullishFlag.bind(this),score:2},{name:"Bearish Flag",condition:this.isBearishFlag.bind(this),score:-2},{name:"Bullish Pennant",condition:this.isBullishPennant.bind(this),score:2},{name:"Bearish Pennant",condition:this.isBearishPennant.bind(this),score:-2},{name:"Double Top",condition:this.isDoubleTop.bind(this),score:-1},{name:"Double Bottom",condition:this.isDoubleBottom.bind(this),score:1},{name:"Triple Top",condition:this.isTripleTop.bind(this),score:-1},{name:"Triple Bottom",condition:this.isTripleBottom.bind(this),score:1},{name:"Head And Shoulders",condition:this.isHeadAndShoulders.bind(this),score:-1},{name:"Inverse Head And Shoulders",condition:this.isInverseHeadAndShoulders.bind(this),score:1},{name:"Rising Wedge",condition:this.isRisingWedge.bind(this),score:-1},{name:"Falling Wedge",condition:this.isFallingWedge.bind(this),score:1},{name:"Bullish Triangle",condition:this.isBullishTriangle.bind(this),score:1},{name:"Bearish Triangle",condition:this.isBearishTriangle.bind(this),score:-1},{name:"Bullish Rectangle",condition:this.isBullishRectangle.bind(this),score:1},{name:"Bearish Rectangle",condition:this.isBearishRectangle.bind(this),score:-1}];for(const{name:i,condition:e,score:s}of t)if(e())return{pattern:s>0?"Bullish":"Bearish",name:i,score:s};return{pattern:"",name:"",score:0}}isBullishFlag(){const t=this.close.length,i=Math.floor(t/3),e=(Math.floor(i/2),this.close[t-2*i]);if((this.close[t-i]-e)/e<.15)return!1;const s=this.close[t-i];if((s-this.close[t-1])/s>.05)return!1;for(let e=t-i;e<t-1;e++)if(this.high[e]>this.high[e+1]||this.low[e]>this.low[e+1])return!1;return!0}isBearishFlag(){const t=this.close.length,i=Math.floor(t/3),e=(Math.floor(i/2),this.close[t-2*i]);if((e-this.close[t-i])/e<.15)return!1;const s=this.close[t-i];if((this.close[t-1]-s)/s>.05)return!1;for(let e=t-i;e<t-1;e++)if(this.high[e]<this.high[e+1]||this.low[e]<this.low[e+1])return!1;return!0}isBullishPennant(){const t=this.close.length,i=Math.floor(t/3),e=Math.floor(i/2),s=this.close[t-2*i];if((this.close[t-i]-s)/s<.15)return!1;const n=this.close[t-i];if((n-this.close[t-1])/n>.05)return!1;for(let i=t-e;i<t-1;i++)if(this.high[i]<this.high[i+1]&&this.low[i]<this.low[i+1]||this.high[i]>this.high[i+1]&&this.low[i]>this.low[i+1])return!1;return!0}isBearishPennant(){const t=this.close.length,i=Math.floor(t/3),e=Math.floor(i/2),s=this.close[t-2*i];if((s-this.close[t-i])/s<.15)return!1;const n=this.close[t-i];if((this.close[t-1]-n)/n>.05)return!1;for(let i=t-e;i<t-1;i++)if(this.high[i]>this.high[i+1]&&this.low[i]>this.low[i+1]||this.high[i]<this.high[i+1]&&this.low[i]<this.low[i+1])return!1;return!0}isDoubleTop(){const t=this.close.length,i=Math.floor(t/2),e=Math.max(...this.close.slice(0,i)),s=Math.max(...this.close.slice(i));if(e<=0||s<=0)return!1;const n=Math.min(...this.close.slice(0,i)),o=Math.min(...this.close.slice(i));return!((e-n)/e<.1||(s-o)/s<.1)&&Math.abs(e-s)/e<.03}isDoubleBottom(){const t=this.close.length,i=Math.floor(t/2),e=Math.min(...this.close.slice(0,i)),s=Math.min(...this.close.slice(i));if(e<=0||s<=0)return!1;const n=Math.max(...this.close.slice(0,i)),o=Math.max(...this.close.slice(i));return!((n-e)/e<.1||(o-s)/s<.1)&&Math.abs(e-s)/e<.03}isTripleTop(){const t=this.close.length,i=Math.floor(t/3),e=Math.max(...this.close.slice(0,i)),s=Math.max(...this.close.slice(i,2*i)),n=Math.max(...this.close.slice(2*i));if(e<=0||s<=0||n<=0)return!1;const o=(e-Math.min(...this.close.slice(0,i)))/e,r=(s-Math.min(...this.close.slice(i,2*i)))/s,h=(n-Math.min(...this.close.slice(2*i)))/n;return!(o<.1||r<.1||h<.1)&&Math.abs(e-s)/e<.03&&Math.abs(e-n)/e<.03}isTripleBottom(){const t=this.close.length,i=Math.floor(t/3),e=Math.min(...this.close.slice(0,i)),s=Math.min(...this.close.slice(i,2*i)),n=Math.min(...this.close.slice(2*i));if(e<=0||s<=0||n<=0)return!1;const o=(Math.max(...this.close.slice(0,i))-e)/e,r=(Math.max(...this.close.slice(i,2*i))-s)/s,h=(Math.max(...this.close.slice(2*i))-n)/n;return!(o<.1||r<.1||h<.1)&&Math.abs(e-s)/e<.03&&Math.abs(e-n)/e<.03}isHeadAndShoulders(){const t=this.close.length,i=Math.floor(t/3),e=Math.max(...this.close.slice(0,i)),s=Math.max(...this.close.slice(i,2*i)),n=Math.max(...this.close.slice(2*i));if(e<=0||s<=0||n<=0)return!1;const o=Math.min(...this.close.slice(0,i)),r=Math.min(...this.close.slice(i,2*i)),h=Math.min(...this.close.slice(2*i)),l=(s-r)/s,a=(Math.max(o,h)-Math.min(o,h))/Math.min(o,h);return l>.15&&a<.03}isInverseHeadAndShoulders(){const t=this.close.length,i=Math.floor(t/3),e=Math.min(...this.close.slice(0,i)),s=Math.min(...this.close.slice(i,2*i)),n=Math.min(...this.close.slice(2*i));if(e<=0||s<=0||n<=0)return!1;const o=Math.max(...this.close.slice(0,i)),r=Math.max(...this.close.slice(i,2*i)),h=Math.max(...this.close.slice(2*i)),l=(r-s)/s,a=(Math.min(o,h)-Math.max(o,h))/Math.max(o,h);return l>.15&&a<.03}isRisingWedge(){const t=this.close.length,i=Math.floor(t/3),e=Math.max(...this.close.slice(0,i)),s=Math.max(...this.close.slice(i,2*i)),n=Math.max(...this.close.slice(2*i)),o=Math.min(...this.close.slice(0,i)),r=Math.min(...this.close.slice(i,2*i)),h=Math.min(...this.close.slice(2*i));return e<s&&s<n&&o<r&&r<h}isFallingWedge(){const t=this.close.length,i=Math.floor(t/3),e=Math.max(...this.close.slice(0,i)),s=Math.max(...this.close.slice(i,2*i)),n=Math.max(...this.close.slice(2*i)),o=Math.min(...this.close.slice(0,i)),r=Math.min(...this.close.slice(i,2*i)),h=Math.min(...this.close.slice(2*i));return e>s&&s>n&&o>r&&r>h}isBullishTriangle(){const t=this.close.length,i=Math.floor(t/2),e=Math.max(...this.high.slice(0,i)),s=Math.max(...this.high.slice(i)),n=Math.min(...this.low.slice(0,i)),o=Math.min(...this.low.slice(i));return e>s&&n<o}isBearishTriangle(){const t=this.close.length,i=Math.floor(t/2),e=Math.max(...this.high.slice(0,i)),s=Math.max(...this.high.slice(i));return Math.min(...this.low.slice(0,i))<Math.min(...this.low.slice(i))&&e>s}isBullishRectangle(){const t=this.close.length,i=Math.floor(t/3),e=Math.max(...this.high.slice(0,i)),s=Math.max(...this.high.slice(i,2*i)),n=Math.max(...this.high.slice(2*i)),o=Math.min(...this.low.slice(0,i)),r=Math.min(...this.low.slice(i,2*i)),h=Math.min(...this.low.slice(2*i)),l=Math.abs(e-s)/e<.03&&Math.abs(s-n)/s<.03,a=Math.abs(o-r)/o<.03&&Math.abs(r-h)/r<.03;return l&&a}isBearishRectangle(){const t=this.close.length,i=Math.floor(t/3),e=Math.max(...this.high.slice(0,i)),s=Math.max(...this.high.slice(i,2*i)),n=Math.max(...this.high.slice(2*i)),o=Math.min(...this.low.slice(0,i)),r=Math.min(...this.low.slice(i,2*i)),h=Math.min(...this.low.slice(2*i)),l=Math.abs(e-s)/e<.03&&Math.abs(s-n)/s<.03,a=Math.abs(o-r)/o<.03&&Math.abs(r-h)/r<.03;return l&&a}}class c{constructor(){this.VolumeProfile=l,this.ChartPatterns=t=>new u(t).init()}init(t){return this.ohlcv=t.reduce(((t,{open:i,high:e,low:s,close:n,volume:o,...r})=>{t.open.push(i),t.high.push(e),t.low.push(s),t.close.push(n),t.volume.push(o);for(const i of Object.keys(r))t[i]||(t[i]=[]),t[i].push(r[i]);return t}),{open:[],high:[],low:[],close:[],volume:[]}),this}getHeaders(){return Object.keys(this.ohlcv)}getData(){const{ohlcv:t}=this,i=Object.keys(t),e=i.length;return t.open.map(((s,n)=>{const o={};for(let s=0;s<e;s++){const e=i[s];o[e]=t[e][n]}return o}))}getLastValues(){const t={};for(const[i,e]of Object.entries(this.ohlcv)){let s=e[e.length-1];t[i]=s}return t}addColumn(t,i){const e=this.ohlcv.open.length;if(i.length>e)throw new Error("Invalid column data: The length of the new column exceeds the length of the OHLCV data");i=[...new Array(e-i.length).fill(null),...i],this.ohlcv[t]=i}crossPairs(t){const i=this.ohlcv,e={},s=t=>{if(!i.hasOwnProperty(t)&&"string"==typeof t){const[i,...e]=t.split("_");this[i]&&e.length>0&&this[i](...e)}};for(const{fast:n,slow:r}of t)if(n&&r)if(s(n),s(r),"number"!=typeof r||e[r]||(e[r]=i.close.map((()=>r))),i[n]&&i[r]){const t=o(i[n],i[r]);this.addColumn(`${n}_x_${r}`,t)}else if(i[n]&&e[r]){const t=o(i[n],e[r]);this.addColumn(`${n}_x_${r}`,t)}else console.error(`Missing ohlcv properties for ${n} or ${r}`)}ema(t){return((t,e)=>{const{ohlcv:s}=t,n=s.close,o=i(n,e);t.addColumn(`ema_${e}`,o)})(this,t),this}sma(t){return((t,i)=>{const{ohlcv:e}=t,s=e.close,o=n(s,i);t.addColumn(`sma_${i}`,o)})(this,t),this}macd(t,e,s){return((t,e=12,s=26,n=9)=>{const{ohlcv:r}=t,h=((t,e=12,s=26,n=9)=>{const r=i(t,e),h=i(t,s),l=r.map(((t,i)=>isNaN(t)||isNaN(h[i])?null:t-h[i])),a=i(l,n),u=l.map(((t,i)=>t-a[i])),c=o(l,a);return{macd_diff:l,macd_dea:a,macd_histogram:u,macd_diff_x_macd_dea:c}})(r.close,e,s,n);for(let i in h)t.addColumn(i,h[i])})(this,t,e,s),this}bollingerBands(i,e,s){return((i,e,s)=>{const{ohlcv:n}=i,o=((i,e=20,s=2)=>{const n={lower:[],middle:[],upper:[]},o=new t.BollingerBands(e,s);i.forEach((t=>{const i=o.nextValue(t);if("object"==typeof i){const{lower:t,middle:e,upper:s}=i;n.lower.push(t),n.middle.push(e),n.upper.push(s)}else n.lower.push(null),n.middle.push(null),n.upper.push(null)}));const h=r(i,{upper:n.upper,lower:n.lower});return{...n,range:h}})(n.close,e,s);for(let t in o)i.addColumn(`bollinger_bands_${t}`,o[t])})(this,i,e),this}rsi(i,e,s){return((i,e,s,n)=>{const{ohlcv:r}=i;"number"==typeof e&&void 0===n&&(n=e);const l=((i,e=14,s="SMA",n=14)=>{if(i.length<e)return[];let r=[];e=parseInt(e),n=parseInt(n);const l=new t.RSI(e);i.forEach((t=>{r.push(l.nextValue(t))})),r=r.filter((t=>t));let a={[`rsi_${e}`]:r};if("string"==typeof s&&"number"==typeof n&&h.hasOwnProperty(`get${s}`)){const t=h[`get${s}`](r,n);a[`rsi_${s}_${n}`]=t,a[`rsi_${e}_x_rsi_${s}_${n}`]=o(r,t)}return a})(r.close,e,s,n);for(let t in l)i.addColumn(`${t}`.toLowerCase(),l[t])})(this,i,e,s),this}candles(){return(t=>{const{ohlcv:i}=t,e=(t=>{const{open:i,high:e,low:s,close:n}=t,o=i.length;if(![i,e,s,n].every((t=>Array.isArray(t)&&t.length>1&&t.length===o)))return{pattern:Array(o).fill("Neutral"),name:Array(o).fill("No Pattern"),score:Array(o).fill(0)};const r=(t,i,e=1e-4)=>Math.abs(t-i)<e,h={bullish:[{name:"Marubozu",condition:(t,i)=>r(i.open,i.low)&&r(i.close,i.high),score:2},{name:"Engulfing",condition:(t,i)=>i.open<t.close&&i.close>t.open&&i.low<t.low&&i.high>t.high,score:2},{name:"Kicker",condition:(t,i)=>i.open<t.open&&i.close>i.open&&t.close<t.open,score:2},{name:"Morning Star",condition:(t,i)=>i.close>t.close&&i.open<t.open&&t.close<t.open,score:2},{name:"Piercing Line",condition:(t,i)=>i.close>t.close&&i.open<t.open&&i.close>(t.open+t.close)/2,score:1},{name:"Belt Hold",condition:(t,i)=>i.open>t.open&&r(i.close,i.high)&&r(t.close,t.low),score:1},{name:"Harami",condition:(t,i)=>i.open>t.close&&i.close<t.open&&i.open<t.open&&i.close>t.close,score:1},{name:"Doji",condition:(t,i)=>r(i.close,i.open)&&i.high-i.low>Math.abs(i.close-i.open),score:0}],bearish:[{name:"Marubozu",condition:(t,i)=>r(i.open,i.high)&&r(i.close,i.low),score:-2},{name:"Engulfing",condition:(t,i)=>i.open>t.close&&i.close<t.open&&i.high>t.high&&i.low<t.low,score:-2},{name:"Kicker",condition:(t,i)=>i.open>t.open&&i.close<i.open&&t.close>t.open,score:-2},{name:"Evening Star",condition:(t,i)=>i.close<t.close&&i.open>t.open&&t.close<t.open,score:-2},{name:"Dark Cloud Cover",condition:(t,i)=>i.close<t.close&&i.open>t.open&&i.close<(t.open+t.close)/2,score:-1},{name:"Belt Hold",condition:(t,i)=>i.open<t.open&&r(i.close,i.low)&&r(t.close,t.high),score:-1},{name:"Harami",condition:(t,i)=>i.open<t.close&&i.close>t.open&&i.open>t.open&&i.close<t.close,score:-1},{name:"Doji",condition:(t,i)=>r(i.close,i.open)&&i.high-i.low>Math.abs(i.close-i.open),score:0}]},l=(t,i,e)=>{for(const{name:s,condition:n,score:o}of e)if(n(t,i))return{name:s,score:o};return null},a=["Neutral"],u=["No Pattern"],c=[0];for(let t=1;t<o;t++){const o={open:i[t-1],high:e[t-1],low:s[t-1],close:n[t-1]},r={open:i[t],high:e[t],low:s[t],close:n[t]},p=l(o,r,h.bullish)||l(o,r,h.bearish);p?(a.push(p.score>0?"Bullish":"Bearish"),u.push(p.name),c.push(p.score)):(a.push("Neutral"),u.push("No Pattern"),c.push(0))}return{pattern:a,name:u,score:c}})(i);for(let i in e)t.addColumn(`candle_${i}`.toLowerCase(),e[i])})(this),this}}})(),OHLCV_INDICATORS=s})();
package/index.js CHANGED
@@ -6,10 +6,12 @@ import { rsi } from './src/oscillators/rsi.js'
6
6
  import { VolumeProfile } from './src/studies/volumeProfile.js'
7
7
  import {findCrosses} from './src/utilities.js'
8
8
  import { candles } from './src/studies/candles.js'
9
+ import ChartPatterns from './src/studies/chart.js'
9
10
 
10
11
  export default class OHLCV_INDICATORS {
11
12
  constructor() {
12
13
  this.VolumeProfile = VolumeProfile
14
+ this.ChartPatterns = ohlcv => new ChartPatterns(ohlcv).init()
13
15
  }
14
16
 
15
17
  init(ohlcv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ohlcv-indicators",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "A JavaScript library featuring optimized trading indicators for OHLCV arrays [{open, high, low, close, value}]. This library is optimized for backtesting and trading bot development.",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -29,7 +29,7 @@ export const getCandlestickPattern = ohlcv => {
29
29
  {
30
30
  name: 'Marubozu',
31
31
  condition: (prev, curr) => isCloseTo(curr.open, curr.low) && isCloseTo(curr.close, curr.high),
32
- score: 3
32
+ score: 2
33
33
  },
34
34
  {
35
35
  name: 'Engulfing',
@@ -71,7 +71,7 @@ export const getCandlestickPattern = ohlcv => {
71
71
  {
72
72
  name: 'Marubozu',
73
73
  condition: (prev, curr) => isCloseTo(curr.open, curr.high) && isCloseTo(curr.close, curr.low),
74
- score: -3
74
+ score: -2
75
75
  },
76
76
  {
77
77
  name: 'Engulfing',
@@ -0,0 +1,462 @@
1
+ export default class ChartPatterns {
2
+ constructor({ open, high, low, close, volume }) {
3
+ this.open = open;
4
+ this.high = high;
5
+ this.low = low;
6
+ this.close = close;
7
+ this.volume = volume;
8
+ }
9
+
10
+ init() {
11
+ const length = this.close.length;
12
+ if (length < 200) {
13
+ console.log('PatternRecognizer requires at least 200 datapoints')
14
+ return { pattern: 'Neutral', name: 'No Pattern', score: 0 };
15
+ }
16
+
17
+ const patterns = [
18
+ { name: 'Bullish Flag', condition: this.isBullishFlag.bind(this), score: 2 },
19
+ { name: 'Bearish Flag', condition: this.isBearishFlag.bind(this), score: -2 },
20
+ { name: 'Bullish Pennant', condition: this.isBullishPennant.bind(this), score: 2 },
21
+ { name: 'Bearish Pennant', condition: this.isBearishPennant.bind(this), score: -2 },
22
+ { name: 'Double Top', condition: this.isDoubleTop.bind(this), score: -1 },
23
+ { name: 'Double Bottom', condition: this.isDoubleBottom.bind(this), score: 1 },
24
+ { name: 'Triple Top', condition: this.isTripleTop.bind(this), score: -1 },
25
+ { name: 'Triple Bottom', condition: this.isTripleBottom.bind(this), score: 1 },
26
+ { name: 'Head And Shoulders', condition: this.isHeadAndShoulders.bind(this), score: -1 },
27
+ { name: 'Inverse Head And Shoulders', condition: this.isInverseHeadAndShoulders.bind(this), score: 1 },
28
+ { name: 'Rising Wedge', condition: this.isRisingWedge.bind(this), score: -1 },
29
+ { name: 'Falling Wedge', condition: this.isFallingWedge.bind(this), score: 1 },
30
+ { name: 'Bullish Triangle', condition: this.isBullishTriangle.bind(this), score: 1 },
31
+ { name: 'Bearish Triangle', condition: this.isBearishTriangle.bind(this), score: -1 },
32
+ { name: 'Bullish Rectangle', condition: this.isBullishRectangle.bind(this), score: 1 },
33
+ { name: 'Bearish Rectangle', condition: this.isBearishRectangle.bind(this), score: -1 },
34
+ ];
35
+
36
+ for (const { name, condition, score } of patterns) {
37
+ if (condition()) {
38
+ return { pattern: score > 0 ? 'Bullish' : 'Bearish', name, score };
39
+ }
40
+ }
41
+
42
+ return { pattern: '', name: '', score: 0 };
43
+ }
44
+
45
+
46
+ // Implementation of Bullish Flag
47
+ // https://www.tradingview.com/support/solutions/43000653209/
48
+
49
+ isBullishFlag() {
50
+
51
+ // A Bullish Flag is characterized by a sharp price rise followed by a period of consolidation that has a downward slant.
52
+ const length = this.close.length;
53
+ const flagpoleLength = Math.floor(length / 3); // Roughly the first third of the data
54
+ const consolidationLength = Math.floor(flagpoleLength / 2); // Roughly half the length of the flagpole
55
+
56
+ // Sharp price rise (flagpole)
57
+ const flagpoleStart = this.close[length - flagpoleLength * 2];
58
+ const flagpoleEnd = this.close[length - flagpoleLength];
59
+ const flagpoleGain = (flagpoleEnd - flagpoleStart) / flagpoleStart;
60
+
61
+ if (flagpoleGain < 0.15) { // A significant gain, at least 15%
62
+ return false;
63
+ }
64
+
65
+ // Consolidation period
66
+ const consolidationStart = this.close[length - flagpoleLength];
67
+ const consolidationEnd = this.close[length - 1];
68
+ const consolidationDrop = (consolidationStart - consolidationEnd) / consolidationStart;
69
+
70
+ if (consolidationDrop > 0.05) { // A downward slant, less than 5%
71
+ return false;
72
+ }
73
+
74
+ // Ensure that the consolidation period has lower highs and lower lows
75
+ for (let i = length - flagpoleLength; i < length - 1; i++) {
76
+ if (this.high[i] > this.high[i + 1] || this.low[i] > this.low[i + 1]) {
77
+ return false;
78
+ }
79
+ }
80
+
81
+ return true;
82
+ }
83
+
84
+ // Implementation of Bearish Flag
85
+ // https://www.tradingview.com/support/solutions/43000653209-chart-pattern-bullish-flag/
86
+ isBearishFlag() {
87
+ // A Bearish Flag is characterized by a sharp price decline followed by a period of consolidation that has an upward slant.
88
+ const length = this.close.length;
89
+ const flagpoleLength = Math.floor(length / 3); // Roughly the first third of the data
90
+ const consolidationLength = Math.floor(flagpoleLength / 2); // Roughly half the length of the flagpole
91
+
92
+ // Sharp price decline (flagpole)
93
+ const flagpoleStart = this.close[length - flagpoleLength * 2];
94
+ const flagpoleEnd = this.close[length - flagpoleLength];
95
+ const flagpoleDrop = (flagpoleStart - flagpoleEnd) / flagpoleStart;
96
+
97
+ if (flagpoleDrop < 0.15) { // A significant drop, at least 15%
98
+ return false;
99
+ }
100
+
101
+ // Consolidation period
102
+ const consolidationStart = this.close[length - flagpoleLength];
103
+ const consolidationEnd = this.close[length - 1];
104
+ const consolidationGain = (consolidationEnd - consolidationStart) / consolidationStart;
105
+
106
+ if (consolidationGain > 0.05) { // An upward slant, less than 5%
107
+ return false;
108
+ }
109
+
110
+ // Ensure that the consolidation period has higher lows and higher highs
111
+ for (let i = length - flagpoleLength; i < length - 1; i++) {
112
+ if (this.high[i] < this.high[i + 1] || this.low[i] < this.low[i + 1]) {
113
+ return false;
114
+ }
115
+ }
116
+
117
+ return true;
118
+ }
119
+
120
+ // Implementation of Bullish Pennant
121
+ // https://www.tradingview.com/support/solutions/43000653215-chart-pattern-bullish-pennant/
122
+ isBullishPennant() {
123
+ // A Bullish Pennant is characterized by a sharp price rise followed by a small symmetrical triangle consolidation.
124
+ const length = this.close.length;
125
+ const flagpoleLength = Math.floor(length / 3); // Roughly the first third of the data
126
+ const pennantLength = Math.floor(flagpoleLength / 2); // Roughly half the length of the flagpole
127
+
128
+ // Sharp price rise (flagpole)
129
+ const flagpoleStart = this.close[length - flagpoleLength * 2];
130
+ const flagpoleEnd = this.close[length - flagpoleLength];
131
+ const flagpoleGain = (flagpoleEnd - flagpoleStart) / flagpoleStart;
132
+
133
+ if (flagpoleGain < 0.15) { // A significant gain, at least 15%
134
+ return false;
135
+ }
136
+
137
+ // Small symmetrical triangle consolidation
138
+ const pennantStart = this.close[length - flagpoleLength];
139
+ const pennantEnd = this.close[length - 1];
140
+ const pennantDrop = (pennantStart - pennantEnd) / pennantStart;
141
+
142
+ if (pennantDrop > 0.05) { // A downward slant, less than 5%
143
+ return false;
144
+ }
145
+
146
+ // Ensure the consolidation period forms a small symmetrical triangle
147
+ for (let i = length - pennantLength; i < length - 1; i++) {
148
+ if ((this.high[i] < this.high[i + 1] && this.low[i] < this.low[i + 1]) ||
149
+ (this.high[i] > this.high[i + 1] && this.low[i] > this.low[i + 1])) {
150
+ return false;
151
+ }
152
+ }
153
+
154
+ return true;
155
+ }
156
+
157
+ // Implementation of Bearish Pennant
158
+ // https://www.tradingview.com/support/solutions/43000697937-chart-pattern-bearish-pennant/
159
+ isBearishPennant() {
160
+ const length = this.close.length;
161
+ const flagpoleLength = Math.floor(length / 3); // Roughly the first third of the data
162
+ const pennantLength = Math.floor(flagpoleLength / 2); // Roughly half the length of the flagpole
163
+
164
+ // Sharp price decline (flagpole)
165
+ const flagpoleStart = this.close[length - flagpoleLength * 2];
166
+ const flagpoleEnd = this.close[length - flagpoleLength];
167
+ const flagpoleDrop = (flagpoleStart - flagpoleEnd) / flagpoleStart;
168
+
169
+ if (flagpoleDrop < 0.15) { // A significant drop, at least 15%
170
+ return false;
171
+ }
172
+
173
+ // Small symmetrical triangle consolidation
174
+ const pennantStart = this.close[length - flagpoleLength];
175
+ const pennantEnd = this.close[length - 1];
176
+ const pennantGain = (pennantEnd - pennantStart) / pennantStart;
177
+
178
+ if (pennantGain > 0.05) { // An upward slant, less than 5%
179
+ return false;
180
+ }
181
+
182
+ // Ensure the consolidation period forms a small symmetrical triangle
183
+ for (let i = length - pennantLength; i < length - 1; i++) {
184
+ if ((this.high[i] > this.high[i + 1] && this.low[i] > this.low[i + 1]) ||
185
+ (this.high[i] < this.high[i + 1] && this.low[i] < this.low[i + 1])) {
186
+ return false;
187
+ }
188
+ }
189
+
190
+ return true;
191
+ }
192
+
193
+ // Implementation of Double Top
194
+ // https://www.tradingview.com/support/solutions/43000653211-chart-pattern-double-top/
195
+ isDoubleTop() {
196
+ const length = this.close.length;
197
+ const midpoint = Math.floor(length / 2);
198
+
199
+ const firstPeak = Math.max(...this.close.slice(0, midpoint));
200
+ const secondPeak = Math.max(...this.close.slice(midpoint));
201
+
202
+ if (firstPeak <= 0 || secondPeak <= 0) {
203
+ return false;
204
+ }
205
+
206
+ const firstValley = Math.min(...this.close.slice(0, midpoint));
207
+ const secondValley = Math.min(...this.close.slice(midpoint));
208
+
209
+ const dropFromFirstPeak = (firstPeak - firstValley) / firstPeak;
210
+ const dropFromSecondPeak = (secondPeak - secondValley) / secondPeak;
211
+
212
+ if (dropFromFirstPeak < 0.1 || dropFromSecondPeak < 0.1) {
213
+ return false;
214
+ }
215
+
216
+ return Math.abs(firstPeak - secondPeak) / firstPeak < 0.03;
217
+ }
218
+
219
+ // Implementation of Double Bottom
220
+ // https://www.tradingview.com/support/solutions/43000690659-chart-pattern-double-bottom/
221
+ isDoubleBottom() {
222
+ const length = this.close.length;
223
+ const midpoint = Math.floor(length / 2);
224
+
225
+ const firstValley = Math.min(...this.close.slice(0, midpoint));
226
+ const secondValley = Math.min(...this.close.slice(midpoint));
227
+
228
+ if (firstValley <= 0 || secondValley <= 0) {
229
+ return false;
230
+ }
231
+
232
+ const firstPeak = Math.max(...this.close.slice(0, midpoint));
233
+ const secondPeak = Math.max(...this.close.slice(midpoint));
234
+
235
+ const riseFromFirstValley = (firstPeak - firstValley) / firstValley;
236
+ const riseFromSecondValley = (secondPeak - secondValley) / secondValley;
237
+
238
+ if (riseFromFirstValley < 0.1 || riseFromSecondValley < 0.1) {
239
+ return false;
240
+ }
241
+
242
+ return Math.abs(firstValley - secondValley) / firstValley < 0.03;
243
+ }
244
+
245
+ // Implementation of Triple Top
246
+ // https://www.tradingview.com/support/solutions/43000653218-chart-pattern-triple-top/
247
+ isTripleTop() {
248
+ const length = this.close.length;
249
+ const third = Math.floor(length / 3);
250
+
251
+ const firstPeak = Math.max(...this.close.slice(0, third));
252
+ const secondPeak = Math.max(...this.close.slice(third, third * 2));
253
+ const thirdPeak = Math.max(...this.close.slice(third * 2));
254
+
255
+ if (firstPeak <= 0 || secondPeak <= 0 || thirdPeak <= 0) {
256
+ return false;
257
+ }
258
+
259
+ const dropFromFirstPeak = (firstPeak - Math.min(...this.close.slice(0, third))) / firstPeak;
260
+ const dropFromSecondPeak = (secondPeak - Math.min(...this.close.slice(third, third * 2))) / secondPeak;
261
+ const dropFromThirdPeak = (thirdPeak - Math.min(...this.close.slice(third * 2))) / thirdPeak;
262
+
263
+ if (dropFromFirstPeak < 0.1 || dropFromSecondPeak < 0.1 || dropFromThirdPeak < 0.1) {
264
+ return false;
265
+ }
266
+
267
+ return Math.abs(firstPeak - secondPeak) / firstPeak < 0.03 && Math.abs(firstPeak - thirdPeak) / firstPeak < 0.03;
268
+ }
269
+
270
+ // Implementation of Triple Bottom
271
+ // https://www.tradingview.com/support/solutions/43000690660-chart-pattern-triple-bottom/
272
+ isTripleBottom() {
273
+ const length = this.close.length;
274
+ const third = Math.floor(length / 3);
275
+
276
+ const firstValley = Math.min(...this.close.slice(0, third));
277
+ const secondValley = Math.min(...this.close.slice(third, third * 2));
278
+ const thirdValley = Math.min(...this.close.slice(third * 2));
279
+
280
+ if (firstValley <= 0 || secondValley <= 0 || thirdValley <= 0) {
281
+ return false;
282
+ }
283
+
284
+ const riseFromFirstValley = (Math.max(...this.close.slice(0, third)) - firstValley) / firstValley;
285
+ const riseFromSecondValley = (Math.max(...this.close.slice(third, third * 2)) - secondValley) / secondValley;
286
+ const riseFromThirdValley = (Math.max(...this.close.slice(third * 2)) - thirdValley) / thirdValley;
287
+
288
+ if (riseFromFirstValley < 0.1 || riseFromSecondValley < 0.1 || riseFromThirdValley < 0.1) {
289
+ return false;
290
+ }
291
+
292
+ return Math.abs(firstValley - secondValley) / firstValley < 0.03 && Math.abs(firstValley - thirdValley) / firstValley < 0.03;
293
+ }
294
+
295
+ // Implementation of Head and Shoulders
296
+ // https://www.tradingview.com/support/solutions/43000653213-chart-pattern-head-and-shoulders/
297
+ isHeadAndShoulders() {
298
+ const length = this.close.length;
299
+ const third = Math.floor(length / 3);
300
+
301
+ const leftShoulder = Math.max(...this.close.slice(0, third));
302
+ const head = Math.max(...this.close.slice(third, third * 2));
303
+ const rightShoulder = Math.max(...this.close.slice(third * 2));
304
+
305
+ if (leftShoulder <= 0 || head <= 0 || rightShoulder <= 0) {
306
+ return false;
307
+ }
308
+
309
+ const leftValley = Math.min(...this.close.slice(0, third));
310
+ const middleValley = Math.min(...this.close.slice(third, third * 2));
311
+ const rightValley = Math.min(...this.close.slice(third * 2));
312
+
313
+ const dropFromHead = (head - middleValley) / head;
314
+ const riseFromValleys = (Math.max(leftValley, rightValley) - Math.min(leftValley, rightValley)) / Math.min(leftValley, rightValley);
315
+
316
+ return dropFromHead > 0.15 && riseFromValleys < 0.03;
317
+ }
318
+
319
+ // Implementation of Inverse Head and Shoulders
320
+ // https://www.tradingview.com/support/solutions/43000690666-chart-pattern-inverse-head-and-shoulders/
321
+ isInverseHeadAndShoulders() {
322
+ const length = this.close.length;
323
+ const third = Math.floor(length / 3);
324
+
325
+ const leftShoulder = Math.min(...this.close.slice(0, third));
326
+ const head = Math.min(...this.close.slice(third, third * 2));
327
+ const rightShoulder = Math.min(...this.close.slice(third * 2));
328
+
329
+ if (leftShoulder <= 0 || head <= 0 || rightShoulder <= 0) {
330
+ return false;
331
+ }
332
+
333
+ const leftPeak = Math.max(...this.close.slice(0, third));
334
+ const middlePeak = Math.max(...this.close.slice(third, third * 2));
335
+ const rightPeak = Math.max(...this.close.slice(third * 2));
336
+
337
+ const riseFromHead = (middlePeak - head) / head;
338
+ const dropFromPeaks = (Math.min(leftPeak, rightPeak) - Math.max(leftPeak, rightPeak)) / Math.max(leftPeak, rightPeak);
339
+
340
+ return riseFromHead > 0.15 && dropFromPeaks < 0.03;
341
+ }
342
+
343
+ // Implementation of Rising Wedge
344
+ // https://www.tradingview.com/support/solutions/43000653219-chart-pattern-rising-wedge/
345
+ isRisingWedge() {
346
+ const length = this.close.length;
347
+ const third = Math.floor(length / 3);
348
+
349
+ const firstPeak = Math.max(...this.close.slice(0, third));
350
+ const secondPeak = Math.max(...this.close.slice(third, third * 2));
351
+ const thirdPeak = Math.max(...this.close.slice(third * 2));
352
+
353
+ const firstValley = Math.min(...this.close.slice(0, third));
354
+ const secondValley = Math.min(...this.close.slice(third, third * 2));
355
+ const thirdValley = Math.min(...this.close.slice(third * 2));
356
+
357
+ const risingPeaks = firstPeak < secondPeak && secondPeak < thirdPeak;
358
+ const risingValleys = firstValley < secondValley && secondValley < thirdValley;
359
+
360
+ return risingPeaks && risingValleys;
361
+ }
362
+
363
+ // Implementation of Falling Wedge
364
+ // https://www.tradingview.com/support/solutions/43000697938-chart-pattern-falling-wedge/
365
+ isFallingWedge() {
366
+ const length = this.close.length;
367
+ const third = Math.floor(length / 3);
368
+
369
+ const firstPeak = Math.max(...this.close.slice(0, third));
370
+ const secondPeak = Math.max(...this.close.slice(third, third * 2));
371
+ const thirdPeak = Math.max(...this.close.slice(third * 2));
372
+
373
+ const firstValley = Math.min(...this.close.slice(0, third));
374
+ const secondValley = Math.min(...this.close.slice(third, third * 2));
375
+ const thirdValley = Math.min(...this.close.slice(third * 2));
376
+
377
+ const fallingPeaks = firstPeak > secondPeak && secondPeak > thirdPeak;
378
+ const fallingValleys = firstValley > secondValley && secondValley > thirdValley;
379
+
380
+ return fallingPeaks && fallingValleys;
381
+ }
382
+
383
+ // Implementation of Bullish Triangle
384
+ // https://www.tradingview.com/support/solutions/43000653217/
385
+ isBullishTriangle() {
386
+ const length = this.close.length;
387
+ const half = Math.floor(length / 2);
388
+
389
+ const firstHalfHigh = Math.max(...this.high.slice(0, half));
390
+ const secondHalfHigh = Math.max(...this.high.slice(half));
391
+
392
+ const firstHalfLow = Math.min(...this.low.slice(0, half));
393
+ const secondHalfLow = Math.min(...this.low.slice(half));
394
+
395
+ const contractingHighs = firstHalfHigh > secondHalfHigh;
396
+ const risingLows = firstHalfLow < secondHalfLow;
397
+
398
+ return contractingHighs && risingLows;
399
+ }
400
+
401
+ // Implementation of Bearish Triangle
402
+ // https://www.tradingview.com/support/solutions/43000653217/
403
+ isBearishTriangle() {
404
+ const length = this.close.length;
405
+ const half = Math.floor(length / 2);
406
+
407
+ const firstHalfHigh = Math.max(...this.high.slice(0, half));
408
+ const secondHalfHigh = Math.max(...this.high.slice(half));
409
+
410
+ const firstHalfLow = Math.min(...this.low.slice(0, half));
411
+ const secondHalfLow = Math.min(...this.low.slice(half));
412
+
413
+ const contractingLows = firstHalfLow < secondHalfLow;
414
+ const fallingHighs = firstHalfHigh > secondHalfHigh;
415
+
416
+ return contractingLows && fallingHighs;
417
+ }
418
+
419
+ // Implementation of Bullish Rectangle
420
+ // https://www.tradingview.com/support/solutions/43000653216/
421
+ isBullishRectangle() {
422
+ const length = this.close.length;
423
+ const third = Math.floor(length / 3);
424
+
425
+ const firstSectionHigh = Math.max(...this.high.slice(0, third));
426
+ const secondSectionHigh = Math.max(...this.high.slice(third, third * 2));
427
+ const thirdSectionHigh = Math.max(...this.high.slice(third * 2));
428
+
429
+ const firstSectionLow = Math.min(...this.low.slice(0, third));
430
+ const secondSectionLow = Math.min(...this.low.slice(third, third * 2));
431
+ const thirdSectionLow = Math.min(...this.low.slice(third * 2));
432
+
433
+ const stableHighs = Math.abs(firstSectionHigh - secondSectionHigh) / firstSectionHigh < 0.03 &&
434
+ Math.abs(secondSectionHigh - thirdSectionHigh) / secondSectionHigh < 0.03;
435
+ const stableLows = Math.abs(firstSectionLow - secondSectionLow) / firstSectionLow < 0.03 &&
436
+ Math.abs(secondSectionLow - thirdSectionLow) / secondSectionLow < 0.03;
437
+
438
+ return stableHighs && stableLows;
439
+ }
440
+
441
+ // Implementation of Bearish Rectangle
442
+ // https://www.tradingview.com/support/solutions/43000653216/
443
+ isBearishRectangle() {
444
+ const length = this.close.length;
445
+ const third = Math.floor(length / 3);
446
+
447
+ const firstSectionHigh = Math.max(...this.high.slice(0, third));
448
+ const secondSectionHigh = Math.max(...this.high.slice(third, third * 2));
449
+ const thirdSectionHigh = Math.max(...this.high.slice(third * 2));
450
+
451
+ const firstSectionLow = Math.min(...this.low.slice(0, third));
452
+ const secondSectionLow = Math.min(...this.low.slice(third, third * 2));
453
+ const thirdSectionLow = Math.min(...this.low.slice(third * 2));
454
+
455
+ const stableHighs = Math.abs(firstSectionHigh - secondSectionHigh) / firstSectionHigh < 0.03 &&
456
+ Math.abs(secondSectionHigh - thirdSectionHigh) / secondSectionHigh < 0.03;
457
+ const stableLows = Math.abs(firstSectionLow - secondSectionLow) / firstSectionLow < 0.03 &&
458
+ Math.abs(secondSectionLow - thirdSectionLow) / secondSectionLow < 0.03;
459
+
460
+ return stableHighs && stableLows;
461
+ }
462
+ }