Skip to content

Commit 55c6536

Browse files
committed
l163 is missing
1 parent 4c2b58a commit 55c6536

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

src/trend/PSAR/PSAR.ts

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {NotEnoughDataError} from '../../error/index.js';
2-
import {IndicatorSeries} from '../../types/Indicator.js';
31
import type {HighLow} from '../../types/HighLowClose.js';
2+
import {IndicatorSeries} from '../../types/Indicator.js';
43

54
export type PSARConfig = {
65
/**
@@ -104,22 +103,20 @@ export class PSAR extends IndicatorSeries<HighLow<number>> {
104103
// Adjust SAR position if needed
105104
if (this.isLong) {
106105
// Adjust SAR based on previous lows
107-
if (this.previousCandle) {
108-
// If pre-previous candle exists and current low is less than SAR
109-
const hasPrevPrev = this.prePreviousCandle != null;
110-
if (hasPrevPrev && low < sar) {
111-
// Apply pre-previous low adjustment if needed
112-
if (this.prePreviousCandle!.low < sar) {
113-
sar = this.prePreviousCandle!.low;
114-
}
115-
116-
// Apply previous low adjustment
117-
sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
118-
}
119-
// No pre-previous candle, but check previous low
120-
else if (this.previousCandle.low < sar) {
121-
sar = this.previousCandle.low;
106+
// If pre-previous candle exists and current low is less than SAR
107+
const hasPrevPrev = this.prePreviousCandle != null;
108+
if (hasPrevPrev && low < sar) {
109+
// Apply pre-previous low adjustment if needed
110+
if (this.prePreviousCandle!.low < sar) {
111+
sar = this.prePreviousCandle!.low;
122112
}
113+
114+
// Apply previous low adjustment
115+
sar = this.previousCandle.low < sar ? this.previousCandle.low : sar;
116+
}
117+
// No pre-previous candle, but check previous low
118+
else if (this.previousCandle.low < sar) {
119+
sar = this.previousCandle.low;
123120
}
124121

125122
// Update acceleration factor and extreme point if price makes new high
@@ -144,22 +141,20 @@ export class PSAR extends IndicatorSeries<HighLow<number>> {
144141
} else {
145142
// Short position
146143
// Adjust SAR based on previous highs
147-
if (this.previousCandle) {
148-
// If pre-previous candle exists and current high is greater than SAR
149-
const hasPrevPrev = this.prePreviousCandle != null;
150-
if (hasPrevPrev && high > sar) {
151-
// Apply pre-previous high adjustment if needed
152-
if (this.prePreviousCandle!.high > sar) {
153-
sar = this.prePreviousCandle!.high;
154-
}
155-
156-
// Apply previous high adjustment
157-
sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
158-
}
159-
// No pre-previous candle, but check previous high
160-
else if (this.previousCandle.high > sar) {
161-
sar = this.previousCandle.high;
144+
// If pre-previous candle exists and current high is greater than SAR
145+
const hasPrevPrev = this.prePreviousCandle != null;
146+
if (hasPrevPrev && high > sar) {
147+
// Apply pre-previous high adjustment if needed
148+
if (this.prePreviousCandle!.high > sar) {
149+
sar = this.prePreviousCandle!.high;
162150
}
151+
152+
// Apply previous high adjustment
153+
sar = this.previousCandle.high > sar ? this.previousCandle.high : sar;
154+
}
155+
// No pre-previous candle, but check previous high
156+
else if (this.previousCandle.high > sar) {
157+
sar = this.previousCandle.high;
163158
}
164159

165160
// Update acceleration factor and extreme point if price makes new low
@@ -197,10 +192,6 @@ export class PSAR extends IndicatorSeries<HighLow<number>> {
197192
}
198193

199194
override getResultOrThrow(): number {
200-
if (this.lastSar === null) {
201-
throw new NotEnoughDataError(this.getRequiredInputs());
202-
}
203-
204195
return super.getResultOrThrow();
205196
}
206197
}

0 commit comments

Comments
 (0)