Skip to content

Commit

Permalink
remove replace from ADX
Browse files Browse the repository at this point in the history
  • Loading branch information
bennycode committed Dec 12, 2024
1 parent 071e0c0 commit b8aec8e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
20 changes: 10 additions & 10 deletions src/AC/AC.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {AC, FasterAC} from './AC.js';
import {NotEnoughDataError} from '../error/index.js';
import type {HighLowNumber} from '../util/index.js';
import {AC, FasterAC} from './AC.js';

describe('AC', () => {
// Test data verified with:
Expand Down Expand Up @@ -256,21 +255,22 @@ describe('AC', () => {
it('guarantees that a replacement is done correctly', () => {
const ac = new AC(5, 34, 5);
const acWithReplace = new AC(5, 34, 5);

ac.updates(mappedCandles);
acWithReplace.updates(mappedCandles);

ac.update({
const correct = {
high: 200,
low: 100,
});
acWithReplace.update({
};
const wrong = {
high: 5_000,
low: 3_000,
});
acWithReplace.replace({
high: 200,
low: 100,
});
};

ac.update(correct);
acWithReplace.update(wrong);
acWithReplace.replace(correct);

expect(acWithReplace.getResult().toFixed()).toBe(ac.getResult().toFixed());
});
Expand Down
40 changes: 20 additions & 20 deletions src/ADX/ADX.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import {ADX, FasterADX} from './ADX.js';

describe('ADX', () => {
// Test data verified with:
// https://tulipindicators.org/adx
const candles = [
{close: 81.59, high: 82.15, low: 81.29},
{close: 81.06, high: 81.89, low: 80.64},
{close: 82.87, high: 83.03, low: 81.31},
{close: 83.0, high: 83.3, low: 82.65},
{close: 83.61, high: 83.85, low: 83.07},
{close: 83.15, high: 83.9, low: 83.11},
{close: 82.84, high: 83.33, low: 82.49},
{close: 83.99, high: 84.3, low: 82.3},
{close: 84.55, high: 84.84, low: 84.15},
{close: 84.36, high: 85.0, low: 84.11},
{close: 85.53, high: 85.9, low: 84.03},
{close: 86.54, high: 86.58, low: 85.39},
{close: 86.89, high: 86.98, low: 85.76},
{close: 87.77, high: 88.0, low: 87.17},
{close: 87.29, high: 87.87, low: 87.01},
];

describe('getResult', () => {
it('calculates the Average Directional Index (ADX)', () => {
// Test data verified with:
// https://tulipindicators.org/adx
const candles = [
{close: 81.59, high: 82.15, low: 81.29},
{close: 81.06, high: 81.89, low: 80.64},
{close: 82.87, high: 83.03, low: 81.31},
{close: 83.0, high: 83.3, low: 82.65},
{close: 83.61, high: 83.85, low: 83.07},
{close: 83.15, high: 83.9, low: 83.11},
{close: 82.84, high: 83.33, low: 82.49},
{close: 83.99, high: 84.3, low: 82.3},
{close: 84.55, high: 84.84, low: 84.15},
{close: 84.36, high: 85.0, low: 84.11},
{close: 85.53, high: 85.9, low: 84.03},
{close: 86.54, high: 86.58, low: 85.39},
{close: 86.89, high: 86.98, low: 85.76},
{close: 87.77, high: 88.0, low: 87.17},
{close: 87.29, high: 87.87, low: 87.01},
];

const expectations = [41.38, 44.29, 49.42, 54.92, 59.99, 65.29, 67.36];

const adx = new ADX(5);
Expand Down
8 changes: 4 additions & 4 deletions src/ADX/ADX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export class ADX extends BigIndicatorSeries<HighLowClose> {
return this.dx.pdi;
}

update(candle: HighLowClose, replace: boolean = false): Big | void {
update(candle: HighLowClose): Big | void {
const result = this.dx.update(candle);
if (result) {
this.adx.update(result);
}
if (this.adx.isStable) {
return this.setResult(this.adx.getResult(), replace);
return this.setResult(this.adx.getResult(), false);
}
}
}
Expand All @@ -82,13 +82,13 @@ export class FasterADX extends NumberIndicatorSeries<HighLowCloseNumber> {
return this.dx.pdi;
}

update(candle: HighLowCloseNumber, replace: boolean = false): void | number {
update(candle: HighLowCloseNumber): void | number {
const result = this.dx.update(candle);
if (result !== undefined) {
this.adx.update(result);
}
if (this.adx.isStable) {
return this.setResult(this.adx.getResult(), replace);
return this.setResult(this.adx.getResult(), false);
}
}
}

0 comments on commit b8aec8e

Please sign in to comment.