Skip to content

Commit

Permalink
Add Keltner channel and chandelier exit
Browse files Browse the repository at this point in the history
  • Loading branch information
anandanand84 committed Oct 12, 2018
1 parent b0cee2a commit 83c81c4
Show file tree
Hide file tree
Showing 17 changed files with 1,353 additions and 4 deletions.
2 changes: 2 additions & 0 deletions declarations/index.d.ts
Expand Up @@ -81,4 +81,6 @@ export { hasInverseHeadAndShoulder } from './patterndetection/patterndetection';
export { isTrendingUp } from './patterndetection/patterndetection';
export { isTrendingDown } from './patterndetection/patterndetection';
export { ichimokucloud, IchimokuCloud } from './ichimoku/IchimokuCloud';
export { keltnerchannels, KeltnerChannels, KeltnerChannelsInput, KeltnerChannelsOutput } from './volatility/KeltnerChannels';
export { chandelierexit, ChandelierExit, ChandelierExitInput, ChandelierExitOutput } from './volatility/ChandelierExit';
export { setConfig, getConfig } from './config';
19 changes: 19 additions & 0 deletions declarations/volatility/ChandelierExit.d.ts
@@ -0,0 +1,19 @@
import { Indicator, IndicatorInput } from '../indicator/indicator';
export declare class ChandelierExitInput extends IndicatorInput {
period: number;
multiplier: number;
high: number[];
low: number[];
close: number[];
}
export declare class ChandelierExitOutput extends IndicatorInput {
exitLong: number;
exitShort: number;
}
export declare class ChandelierExit extends Indicator {
generator: IterableIterator<ChandelierExitOutput | undefined>;
constructor(input: ChandelierExitInput);
static calculate: typeof chandelierexit;
nextValue(price: ChandelierExitInput): ChandelierExitOutput | undefined;
}
export declare function chandelierexit(input: ChandelierExitInput): number[];
23 changes: 23 additions & 0 deletions declarations/volatility/KeltnerChannels.d.ts
@@ -0,0 +1,23 @@
import { Indicator, IndicatorInput } from '../indicator/indicator';
export declare class KeltnerChannelsInput extends IndicatorInput {
maPeriod: number;
atrPeriod: number;
useSMA: boolean;
multiplier: number;
high: number[];
low: number[];
close: number[];
}
export declare class KeltnerChannelsOutput extends IndicatorInput {
middle: number;
upper: number;
lower: number;
}
export declare class KeltnerChannels extends Indicator {
result: KeltnerChannelsOutput[];
generator: IterableIterator<KeltnerChannelsOutput | undefined>;
constructor(input: KeltnerChannelsInput);
static calculate: typeof keltnerchannels;
nextValue(price: KeltnerChannelsInput): KeltnerChannelsOutput | undefined;
}
export declare function keltnerchannels(input: KeltnerChannelsInput): KeltnerChannelsOutput[];
2 changes: 1 addition & 1 deletion dist/browser.es6.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser.js

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -84,6 +84,9 @@ export function getAvailableIndicators () {
AvailableIndicators.push('isTrendingUp');
AvailableIndicators.push('isTrendingDown');
AvailableIndicators.push('ichimokucloud');

AvailableIndicators.push('keltnerchannels');
AvailableIndicators.push('chandelierexit');
return AvailableIndicators;
};

Expand Down
2 changes: 2 additions & 0 deletions lib/index.js
Expand Up @@ -81,4 +81,6 @@ export { hasInverseHeadAndShoulder } from './patterndetection/patterndetection';
export { isTrendingUp } from './patterndetection/patterndetection';
export { isTrendingDown } from './patterndetection/patterndetection';
export { ichimokucloud, IchimokuCloud } from './ichimoku/IchimokuCloud';
export { keltnerchannels, KeltnerChannels, KeltnerChannelsInput, KeltnerChannelsOutput } from './volatility/KeltnerChannels';
export { chandelierexit, ChandelierExit, ChandelierExitInput, ChandelierExitOutput } from './volatility/ChandelierExit';
export { setConfig, getConfig } from './config';
73 changes: 73 additions & 0 deletions lib/volatility/ChandelierExit.js
@@ -0,0 +1,73 @@
import { Indicator, IndicatorInput } from '../indicator/indicator';
import { ATR } from '../directionalmovement/ATR';
import LinkedList from '../Utils/FixedSizeLinkedList';
export class ChandelierExitInput extends IndicatorInput {
constructor() {
super(...arguments);
this.period = 22;
this.multiplier = 3;
}
}
export class ChandelierExitOutput extends IndicatorInput {
}
;
export class ChandelierExit extends Indicator {
constructor(input) {
super(input);
var highs = input.high;
var lows = input.low;
var closes = input.close;
this.result = [];
var atrProducer = new ATR({ period: input.period, high: [], low: [], close: [], format: (v) => { return v; } });
var dataCollector = new LinkedList(input.period * 2, true, true, false);
this.generator = (function* () {
var result;
var tick = yield;
var atr;
while (true) {
var { high, low } = tick;
dataCollector.push(high);
dataCollector.push(low);
atr = atrProducer.nextValue(tick);
if ((dataCollector.totalPushed >= (2 * input.period)) && atr != undefined) {
result = {
exitLong: dataCollector.periodHigh - atr * input.multiplier,
exitShort: dataCollector.periodLow + atr * input.multiplier
};
}
tick = yield result;
}
})();
this.generator.next();
highs.forEach((tickHigh, index) => {
var tickInput = {
high: tickHigh,
low: lows[index],
close: closes[index],
};
var result = this.generator.next(tickInput);
if (result.value != undefined) {
this.result.push(result.value);
}
});
}
;
nextValue(price) {
var result = this.generator.next(price);
if (result.value != undefined) {
return result.value;
}
}
;
}
ChandelierExit.calculate = chandelierexit;
export function chandelierexit(input) {
Indicator.reverseInputs(input);
var result = new ChandelierExit(input).result;
if (input.reversedInput) {
result.reverse();
}
Indicator.reverseInputs(input);
return result;
}
;
76 changes: 76 additions & 0 deletions lib/volatility/KeltnerChannels.js
@@ -0,0 +1,76 @@
import { Indicator, IndicatorInput } from '../indicator/indicator';
import { SMA } from '../moving_averages/SMA';
import { EMA } from '../moving_averages/EMA';
import { ATR } from '../directionalmovement/ATR';
export class KeltnerChannelsInput extends IndicatorInput {
constructor() {
super(...arguments);
this.maPeriod = 20;
this.atrPeriod = 10;
this.useSMA = false;
this.multiplier = 1;
}
}
export class KeltnerChannelsOutput extends IndicatorInput {
}
;
export class KeltnerChannels extends Indicator {
constructor(input) {
super(input);
var maType = input.useSMA ? SMA : EMA;
var maProducer = new maType({ period: input.maPeriod, values: [], format: (v) => { return v; } });
var atrProducer = new ATR({ period: input.atrPeriod, high: [], low: [], close: [], format: (v) => { return v; } });
var tick;
this.result = [];
this.generator = (function* () {
var KeltnerChannelsOutput;
var result;
tick = yield;
while (true) {
var { close } = tick;
var ma = maProducer.nextValue(close);
var atr = atrProducer.nextValue(tick);
if (ma != undefined && atr != undefined) {
result = {
middle: ma,
upper: ma + (input.multiplier * (atr)),
lower: ma - (input.multiplier * (atr))
};
}
tick = yield result;
}
})();
this.generator.next();
var highs = input.high;
highs.forEach((tickHigh, index) => {
var tickInput = {
high: tickHigh,
low: input.low[index],
close: input.close[index],
};
var result = this.generator.next(tickInput);
if (result.value != undefined) {
this.result.push(result.value);
}
});
}
;
nextValue(price) {
var result = this.generator.next(price);
if (result.value != undefined) {
return result.value;
}
}
;
}
KeltnerChannels.calculate = keltnerchannels;
export function keltnerchannels(input) {
Indicator.reverseInputs(input);
var result = new KeltnerChannels(input).result;
if (input.reversedInput) {
result.reverse();
}
Indicator.reverseInputs(input);
return result;
}
;

0 comments on commit 83c81c4

Please sign in to comment.