Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion indicators/adr/adr.ts

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

2 changes: 1 addition & 1 deletion indicators/bop/bop.ts

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

2 changes: 1 addition & 1 deletion indicators/dema/dema.ts

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

2 changes: 1 addition & 1 deletion indicators/hma/hma.ts

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

38 changes: 6 additions & 32 deletions indicators/lsma/lsma.ts

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

2 changes: 1 addition & 1 deletion indicators/mass-index/mass-index.ts

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

6 changes: 3 additions & 3 deletions indicators/mc-ginley-dynamic/mc-ginley-dynamic.ts

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

2 changes: 1 addition & 1 deletion indicators/momentum/momentum.ts

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

2 changes: 1 addition & 1 deletion indicators/roc/roc.ts

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

10 changes: 5 additions & 5 deletions indicators/sma/sma.ts

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

2 changes: 1 addition & 1 deletion indicators/tema/tema.ts

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

19 changes: 14 additions & 5 deletions oakscriptjs/src/math/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import { float, int, simple_int, series_float } from '../types';
import { Series } from '../runtime/series';

/**
* Returns the absolute value of a number.
Expand Down Expand Up @@ -192,14 +193,15 @@ export function avg(...values: float[]): float {
/**
* Returns the sum of values over a sliding window.
*
* @param source - Series of values
* @param source - Series of values or array
* @param length - Window length for summation
* @returns Series with rolling sum values
* @returns Series or array with rolling sum values
*
* @remarks
* - Calculates sum of last `length` values at each point
* - Returns NaN for first `length-1` values (insufficient data)
* - Window slides forward one value at a time
* - When passed a Series, returns a Series; when passed an array, returns an array
*
* @example
* ```typescript
Expand All @@ -209,21 +211,28 @@ export function avg(...values: float[]): float {
*
* @see {@link https://www.tradingview.com/pine-script-reference/v6/#fun_math.sum | PineScript math.sum}
*/
export function sum(source: series_float, length: simple_int): series_float {
export function sum(source: series_float | Series, length: simple_int): series_float | Series {
// Handle Series objects - extract to array first
const sourceArray = source instanceof Series ? source.toArray() : source;
const result: series_float = [];

for (let i = 0; i < source.length; i++) {
for (let i = 0; i < sourceArray.length; i++) {
if (i < length - 1) {
result.push(NaN);
} else {
let total = 0;
for (let j = 0; j < length; j++) {
total += source[i - j]!;
total += sourceArray[i - j]!;
}
result.push(total);
}
}

// If input was a Series, return a Series
if (source instanceof Series) {
return Series.fromArray(source.bars, result);
}

return result;
}

Expand Down
8 changes: 8 additions & 0 deletions oakscriptjs/src/runtime/series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export class Series {
this.extractor = extractor;
}

/**
* Get the underlying bar data
* @returns Bar array
*/
get bars(): Bar[] {
return this.data;
}

// ============================================
// Static Factory Methods
// ============================================
Expand Down
Loading
Loading