Skip to content

Parabolic SAR #780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 1, 2025
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Most of the time, the minimum amount of data depends on the interval / time peri
1. Momentum (MOM / MTM)
1. Moving Average Convergence Divergence (MACD)
1. On-Balance Volume (OBV)
1. Parabolic SAR (PSAR)
1. Rate-of-Change (ROC)
1. Relative Moving Average (RMA)
1. Relative Strength Index (RSI)
Expand Down
216 changes: 216 additions & 0 deletions docs/classes/FasterPSAR.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<!doctype html>
<html class="default" lang="en" data-base="..">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=edge" />
<title>FasterPSAR | trading-signals</title>
<meta name="description" content="Documentation for trading-signals" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="../assets/style.css" />
<link rel="stylesheet" href="../assets/highlight.css" />
<script defer src="../assets/main.js"></script>
<script async src="../assets/icons.js" id="tsd-icons-script"></script>
<script async src="../assets/search.js" id="tsd-search-script"></script>
<script async src="../assets/navigation.js" id="tsd-nav-script"></script>
<script async src="../assets/hierarchy.js" id="tsd-hierarchy-script"></script>
</head>
<body>
<script>
document.documentElement.dataset.theme = localStorage.getItem('tsd-theme') || 'os';
document.body.style.display = 'none';
setTimeout(() => (app ? app.showPage() : document.body.style.removeProperty('display')), 500);
</script>
<header class="tsd-page-toolbar">
<div class="tsd-toolbar-contents container">
<div class="table-cell" id="tsd-search">
<div class="field">
<label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"
><svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-search"></use></svg></label
><input type="text" id="tsd-search-field" aria-label="Search" />
</div>
<div class="field"><div id="tsd-toolbar-links"></div></div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="../index.html" class="title">trading-signals</a>
</div>
<div class="table-cell" id="tsd-widgets">
<a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"
><svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-menu"></use></svg
></a>
</div>
</div>
</header>
<div class="container container-main">
<div class="col-content">
<div class="tsd-page-title">
<ul class="tsd-breadcrumb">
<li><a href="../modules.html">trading-signals</a></li>
<li><a href="FasterPSAR.html">FasterPSAR</a></li>
</ul>
<h1>Class FasterPSAR</h1>
</div>
<section class="tsd-panel tsd-hierarchy" data-refl="2066">
<h4>Hierarchy (<a href="../hierarchy.html#FasterPSAR">View Summary</a>)</h4>
<ul class="tsd-hierarchy">
<li class="tsd-hierarchy-item">
<a href="NumberIndicatorSeries.html" class="tsd-signature-type tsd-kind-class">NumberIndicatorSeries</a
><span class="tsd-signature-symbol">&lt;</span
><a href="../types/HighLowNumber.html" class="tsd-signature-type tsd-kind-type-alias">HighLowNumber</a
><span class="tsd-signature-symbol">&gt;</span>
<ul class="tsd-hierarchy">
<li class="tsd-hierarchy-item"><span class="tsd-hierarchy-target">FasterPSAR</span></li>
</ul>
</li>
</ul>
</section>
<aside class="tsd-sources">
<ul>
<li>
Defined in
<a href="https://github.com/bennycode/trading-signals/blob/main/src/SAR/ParabolicSAR.ts#L160"
>SAR/ParabolicSAR.ts:160</a
>
</li>
</ul>
</aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<details class="tsd-index-content tsd-accordion" open>
<summary class="tsd-accordion-summary tsd-index-summary">
<h5 class="tsd-index-heading uppercase" role="button" aria-expanded="false" tabindex="0">
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
<use href="../assets/icons.svg#icon-chevronSmall"></use>
</svg>
Index
</h5>
</summary>
<div class="tsd-accordion-details">
<section class="tsd-index-section">
<h3 class="tsd-index-heading">Constructors</h3>
<div class="tsd-index-list">
<a href="FasterPSAR.html#constructor" class="tsd-index-link"
><svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-512"></use></svg
><span>constructor</span></a
>
</div>
</section>
<section class="tsd-index-section">
<h3 class="tsd-index-heading">Properties</h3>
<div class="tsd-index-list">
<a href="FasterPSAR.html#accelerationStep" class="tsd-index-link"
><svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-1024"></use></svg
><span>acceleration<wbr />Step</span></a
>
<a href="FasterPSAR.html#accelerationMax" class="tsd-index-link"
><svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-1024"></use></svg
><span>acceleration<wbr />Max</span></a
>
</div>
</section>
<section class="tsd-index-section">
<h3 class="tsd-index-heading">Accessors</h3>
<div class="tsd-index-list">
<a href="FasterPSAR.html#isstable" class="tsd-index-link"
><svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-262144"></use></svg
><span>is<wbr />Stable</span></a
>
</div>
</section>
<section class="tsd-index-section">
<h3 class="tsd-index-heading">Methods</h3>
<div class="tsd-index-list">
<a href="FasterPSAR.html#update" class="tsd-index-link"
><svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-2048"></use></svg
><span>update</span></a
>
<a href="FasterPSAR.html#getresultorthrow" class="tsd-index-link"
><svg class="tsd-kind-icon" viewBox="0 0 24 24">
<use href="../assets/icons.svg#icon-2048"></use></svg
><span>get<wbr />Result<wbr />Or<wbr />Throw</span></a
>
</div>
</section>
</div>
</details>
</section>
</section>
<div class="col-sidebar">
<div class="page-menu">
<div class="tsd-navigation settings">
<details class="tsd-accordion">
<summary class="tsd-accordion-summary">
<h3>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none">
<use href="../assets/icons.svg#icon-chevronDown"></use></svg
>Settings
</h3>
</summary>
<div class="tsd-accordion-details">
<div class="tsd-filter-visibility">
<span class="settings-label">Member Visibility</span>
<ul id="tsd-filter-options">
<li class="tsd-filter-item">
<label class="tsd-filter-input"
><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked /><svg
width="32"
height="32"
viewBox="0 0 32 32"
aria-hidden="true">
<rect
class="tsd-checkbox-background"
width="30"
height="30"
x="1"
y="1"
rx="6"
fill="none"></rect>
<path
class="tsd-checkbox-checkmark"
d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25"
stroke="none"
stroke-width="3.5"
stroke-linejoin="round"
fill="none"></path></svg
><span>Inherited</span></label
>
</li>
</ul>
</div>
<div class="tsd-theme-toggle">
<label class="settings-label" for="tsd-theme">Theme</label
><select id="tsd-theme">
<option value="os">OS</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</div>
</div>
</details>
</div>
</div>
<div class="site-menu">
<nav class="tsd-navigation">
<a href="../modules.html">trading-signals</a>
<ul class="tsd-small-nested-navigation" id="tsd-nav-container">
<li>Loading...</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<footer>
<p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</footer>
<div class="overlay"></div>
</body>
</html>
118 changes: 118 additions & 0 deletions docs/classes/FasterPSAR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
[trading-signals](../README.md) / [Exports](../modules.md) / FasterPSAR

# Class: FasterPSAR

Faster Parabolic SAR (PSAR) Type: Trend

A high-performance implementation of the Parabolic Stop and Reverse (PSAR) indicator that uses JavaScript native number types instead of Big.js. The Parabolic SAR indicator identifies potential price reversals and can be used to determine trend direction, set trailing stop-loss orders, and identify entry/exit points.

## Hierarchy

- [`NumberIndicatorSeries`](NumberIndicatorSeries.md)\<[`HighLowNumber`](../types/HighLowNumber.md)\>

↳ **`FasterPSAR`**

## Table of contents

### Constructors

- [constructor](FasterPSAR.md#constructor)

### Properties

- [accelerationStep](FasterPSAR.md#accelerationstep)
- [accelerationMax](FasterPSAR.md#accelerationmax)

### Accessors

- [isStable](FasterPSAR.md#isstable)

### Methods

- [update](FasterPSAR.md#update)
- [getResultOrThrow](FasterPSAR.md#getresultorthrow)

## Constructors

### constructor

• **new FasterPSAR**(`config`)

#### Parameters

| Name | Type | Description |
| :------- | :----------- | :----------------------------------------------------------------------------------- |
| `config` | `PSARConfig` | Configuration object containing acceleration step and max acceleration factor values |

#### Overrides

[NumberIndicatorSeries](NumberIndicatorSeries.md).[constructor](NumberIndicatorSeries.md#constructor)

## Properties

### accelerationStep

• `Private` `Readonly` **accelerationStep**: `number`

The acceleration factor step - how quickly the SAR accelerates towards the price

### accelerationMax

• `Private` `Readonly` **accelerationMax**: `number`

The maximum value the acceleration factor can reach

## Accessors

### isStable

• `get` **isStable**(): `boolean`

#### Returns

`boolean`

Whether the indicator has calculated at least one result

## Methods

### update

▸ **update**(`candle`, `replace`): `number` | `null`

Update the indicator's state with a new candle

#### Parameters

| Name | Type | Description |
| :-------- | :-------------- | :---------------------------------------- |
| `candle` | `HighLowNumber` | The new price candle with high/low values |
| `replace` | `boolean` | Whether to replace the last candle |

#### Returns

`number` | `null`

The updated SAR value or null if insufficient data

### getResultOrThrow

▸ **getResultOrThrow**(): `number`

Get the current result or throw an error if the indicator is not stable

#### Returns

`number`

The current SAR value

#### Throws

`NotEnoughDataError`

If there is not enough data to calculate the SAR (at least 2 candles required)

## Performance Considerations

The FasterPSAR implementation is optimized for performance and should be preferred in scenarios where computational efficiency is more important than decimal precision. It's especially suitable for backtesting with large datasets or real-time trading applications with limited resources.
Loading
Loading