-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Keltner channel and chandelier exit
- Loading branch information
1 parent
b0cee2a
commit 83c81c4
Showing
17 changed files
with
1,353 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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[]; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
; |
Oops, something went wrong.