@@ -201,32 +201,29 @@ export function smoothAndTrimAllCharts(series: Indicator[], baseSeries: Indicato
201
201
s . series = smoothSeries ( s . series , smoothWindow [ 0 ] [ i ] )
202
202
return s
203
203
} )
204
- trimSteps ( series , stepRange [ 0 ] , stepRange [ 1 ] , smoothRange , trimSmoothEnds )
204
+ trimSteps ( series , stepRange [ 0 ] , stepRange [ 1 ] , smoothWindow [ 0 ] , trimSmoothEnds )
205
205
}
206
206
207
207
if ( baseSeries != null ) {
208
208
baseSeries . map ( ( s , i ) => {
209
209
s . series = smoothSeries ( s . series , smoothWindow [ 1 ] [ i ] )
210
210
return s
211
211
} )
212
- trimSteps ( baseSeries , stepRange [ 0 ] , stepRange [ 1 ] , smoothRange , trimSmoothEnds )
212
+ trimSteps ( baseSeries , stepRange [ 0 ] , stepRange [ 1 ] , smoothWindow [ 1 ] , trimSmoothEnds )
213
213
}
214
214
}
215
215
216
- function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothRange : number = 0 , trimSmoothEnds : boolean = true ) {
217
- series . forEach ( s => {
218
- let localSmoothRange = smoothRange / 2 // remove half from each end
216
+ function trimSteps ( series : Indicator [ ] , min : number , max : number , smoothWindow : number [ ] , trimSmoothEnds : boolean = true ) {
217
+ series . forEach ( ( s , i ) => {
218
+ let localSmoothWindow = smoothWindow [ i ] / 2 // remove half from each end
219
+ localSmoothWindow = Math . floor ( localSmoothWindow )
220
+ if ( localSmoothWindow < 0 ) {
221
+ localSmoothWindow = 0
222
+ }
219
223
if ( s . series . length <= 1 ) {
220
- localSmoothRange = 0
221
- } else {
222
- let trimStepCount = localSmoothRange / ( s . series [ 1 ] . step - s . series [ 0 ] . step )
223
- if ( trimStepCount < 1 ) { // not going to trim anything - or else will filter out single steps
224
- localSmoothRange = 0
225
- }
226
-
227
- if ( smoothRange >= s . series [ s . series . length - 1 ] . step - s . series [ 0 ] . step ) {
228
- localSmoothRange = ( s . series [ s . series . length - 1 ] . step - s . series [ 0 ] . step ) / 2
229
- }
224
+ localSmoothWindow = 0
225
+ } else if ( smoothWindow [ i ] >= s . series . length ) {
226
+ localSmoothWindow = Math . floor ( s . series . length / 2 )
230
227
}
231
228
232
229
@@ -237,14 +234,15 @@ function trimSteps(series: Indicator[], min: number, max: number, smoothRange: n
237
234
localMin = s . series [ 0 ] . step
238
235
}
239
236
if ( trimSmoothEnds ) {
240
- localMin = Math . max ( localMin , s . series [ 0 ] . step + localSmoothRange )
237
+ localMin = Math . max ( localMin , s . series [ localSmoothWindow ] . step )
241
238
}
242
239
243
240
if ( localMax == - 1 ) {
244
241
localMax = s . series [ s . series . length - 1 ] . step
245
242
}
246
243
if ( trimSmoothEnds ) {
247
- localMax = Math . min ( localMax , s . series [ s . series . length - 1 ] . step - localSmoothRange )
244
+ localMax = Math . min ( localMax , s . series [ s . series . length - 1 - localSmoothWindow +
245
+ ( s . series . length % 2 == 0 && localSmoothWindow != 0 ? 1 : 0 ) ] . step ) // get the mid value for even length series
248
246
}
249
247
250
248
localMin = Math . floor ( localMin - 1 )
0 commit comments