@@ -39,8 +39,8 @@ const data = [/* bar data */];
3939const close = new Series (data , (bar ) => bar .close );
4040const open = new Series (data , (bar ) => bar .open );
4141
42- // With Babel plugin: Native operators!
43- const change = close - open ; // Transforms to: close .sub(open)
42+ // Series method calls for arithmetic
43+ const change = close .sub (open );
4444```
4545
4646** Level 3: TA-Series Functions**
@@ -123,7 +123,7 @@ const high = new Series(bars, (bar) => bar.high);
123123const low = new Series (bars , (bar ) => bar .low );
124124
125125// Calculate with Series
126- const range = high .sub (low ); // Or: high - low (with Babel plugin)
126+ const range = high .sub (low );
127127const rsi = ta .rsi (close , 14 );
128128
129129// Extract values
@@ -186,40 +186,6 @@ const result = materialized.div(low).add(volume);
186186- After expensive computations to free intermediate results
187187- When you need a "snapshot" of computed values
188188
189- ### Native Operators with Babel Plugin
190-
191- Enable PineScript-like syntax with the Babel plugin:
192-
193- ``` typescript
194- // Without Babel plugin
195- const bop = close .sub (open ).div (high .sub (low ));
196-
197- // With Babel plugin
198- const bop = (close - open ) / (high - low ); // Transforms to the above!
199- ```
200-
201- ** Setup:**
202-
203- 1 . Install Babel:
204- ``` bash
205- npm install --save-dev @babel/core @babel/cli @babel/preset-typescript
206- ```
207-
208- 2 . Create ` babel.config.js ` :
209- ``` javascript
210- module .exports = {
211- presets: [' @babel/preset-typescript' ],
212- plugins: [
213- ' ./node_modules/@deepentropy/oakscriptjs/babel-plugin/pinescript-operators.cjs'
214- ]
215- };
216- ```
217-
218- 3 . Build with Babel:
219- ``` bash
220- npx babel src --out-dir dist
221- ```
222-
223189### Available Namespaces
224190
225191#### Technical Analysis (` ta ` and ` taCore ` )
@@ -291,8 +257,6 @@ This section is for developers transpiling PineScript to JavaScript using OakScr
291257PineScript Source
292258 ↓ (OakScriptEngine Parser)
293259Indicator Function (TypeScript)
294- ↓ (Babel Plugin - Optional but Recommended)
295- Transformed Indicator with Series Method Calls
296260 ↓ (TypeScript Compiler)
297261JavaScript Module
298262 ↓ (User's Application)
@@ -331,8 +295,8 @@ export function balanceOfPower(bars: any[]): IndicatorResult {
331295 const high = new Series (bars , (bar ) => bar .high );
332296 const low = new Series (bars , (bar ) => bar .low );
333297
334- // Calculate (with Babel plugin)
335- const bop = ( close - open ) / (high - low );
298+ // Calculate using Series methods
299+ const bop = close . sub ( open ). div (high . sub ( low ) );
336300
337301 // Return structured result
338302 return {
@@ -358,11 +322,6 @@ export function balanceOfPower(bars: any[]): IndicatorResult {
358322}
359323```
360324
361- ** Without Babel Plugin:**
362- ``` typescript
363- const bop = close .sub (open ).div (high .sub (low ));
364- ```
365-
366325### Transpilation Mapping
367326
368327#### 1. Built-in Series
@@ -397,16 +356,16 @@ ta.sma(close, 20) // OakScriptJS (same!)
397356
398357#### 3. Operators
399358
400- With Babel plugin enabled :
359+ Series arithmetic uses method calls :
401360
402- | PineScript | OakScriptJS (Before Babel) | Runtime (After Babel) |
403- | ------------| --------------------------- | ---------------------- |
404- | ` close - open ` | ` close - open ` | ` close .sub(open)` |
405- | ` high + low ` | ` high + low ` | ` high .add(low)` |
406- | ` close * 2 ` | ` close * 2 ` | ` close .mul(2)` |
407- | ` a / b ` | ` a / b ` | ` a .div(b)` |
408- | ` rsi > 70 ` | ` rsi > 70 ` | ` rsi .gt(70)` |
409- | ` a && b ` | ` a && b ` | ` a .and(b)` |
361+ | PineScript | OakScriptJS |
362+ | ------------| -------------|
363+ | ` close - open ` | ` close.sub(open) ` |
364+ | ` high + low ` | ` high.add(low) ` |
365+ | ` close * 2 ` | ` close.mul(2) ` |
366+ | ` a / b ` | ` a.div(b) ` |
367+ | ` rsi > 70 ` | ` rsi.gt(70) ` |
368+ | ` a && b ` | ` a.and(b) ` |
410369
411370#### 4. Indicator Result Structure
412371
@@ -720,8 +679,8 @@ export function bopIndicator(bars: any[]): IndicatorResult {
720679 const high = new Series (bars , (bar ) => bar .high );
721680 const low = new Series (bars , (bar ) => bar .low );
722681
723- // Native operators (requires Babel plugin)
724- const bop = ( close - open ) / (high - low );
682+ // Series method calls for arithmetic
683+ const bop = close . sub ( open ). div (high . sub ( low ) );
725684
726685 return {
727686 metadata: {
@@ -754,7 +713,11 @@ npm install @deepentropy/oakscriptjs
754713
755714** Problem** : Operators not working (` close - open ` gives error)
756715
757- ** Solution** : Enable Babel plugin (see [ Native Operators] ( #native-operators-with-babel-plugin ) )
716+ ** Solution** : Use Series method calls instead of native operators:
717+ ``` typescript
718+ // Instead of: close - open
719+ // Use: close.sub(open)
720+ ```
758721
759722### Runtime Issues
760723
@@ -785,13 +748,11 @@ import { Series } from '@deepentropy/oakscriptjs';
785748- Install OakScriptJS
786749- Use core functions for calculations
787750- Use Series class for operator chaining
788- - Optional: Enable Babel plugin for native operators
789751
790752### For OakScriptEngine Developers
791753- Generate functions that return ` IndicatorResult `
792754- Use Series class for calculations
793755- Map PineScript functions 1:1 to OakScriptJS equivalents
794- - Use Babel plugin for native operators (recommended)
795756
796757** Result** : Clean, maintainable code that's easy to understand and extend!
797758
0 commit comments