Skip to content

Commit

Permalink
Cinar/issue69 (#71)
Browse files Browse the repository at this point in the history
* Implement the Larry Connors the 2-period RSI strategy
Fixes #69

* Implement the Larry Connors the 2-period RSI strategy.
Fixes #69
  • Loading branch information
cinar authored Jun 3, 2022
1 parent 4285d78 commit 12d47b6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ The following list of strategies are currently supported by this package:

- [Awesome Oscillator Strategy](src/strategy/momentum/index.md#awesome-oscillator-strategy)
- [Ichimoku Cloud Strategy](src/strategy/momentum/index.md#ichimoku-cloud-strategy)
- [RSI 2 Stategy](src/strategy/momentum/index.md#rsi-2-strategy)
- [Stochastic Oscillator Strategy](src/strategy/momentum/index.md#stochastic-oscillator-strategy)
- [Williams R Strategy](src/strategy/momentum/index.md#williams-r-strategy)

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export * from './strategy/asset';
export * from './strategy/buyAndHoldStrategy';
export * from './strategy/momentum/awesomeOscillatorStrategy';
export * from './strategy/momentum/ichimokuCloudStrategy';
export * from './strategy/momentum/rsi2Strategy';
export * from './strategy/momentum/stochasticOscillatorStrategy';
export * from './strategy/momentum/williamsRStrategy';
export * from './strategy/strategyFunction';
Expand Down
11 changes: 11 additions & 0 deletions src/strategy/momentum/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Momentum strategies generate signals based on a momentum indicator.

- [Awesome Oscillator Strategy](#awesome-oscillator-strategy)
- [Ichimoku Cloud Strategy](#ichimoku-cloud-strategy)
- [RSI 2 Strategy](#rsi-2-strategy)
- [Stochastic Oscillator Strategy](#stochastic-oscillator-strategy)
- [Williams R Strategy](#williams-r-strategy)

Expand All @@ -27,6 +28,16 @@ import {ichimokuCloudStrategy} from 'indicatorts';
const actions = ichimokuCloudStrategy(asset);
```

#### RSI 2 Strategy

The [rsi2Strategy](./rsi2Strategy.ts) uses the _rsi_ values that are generated by the [RSI 2](../../indicator/momentum/index.md#rsi-2) indicator function to provide a _BUY_ action when 2-period RSI moves below 10, and a _SELL_ action when the 2-period RSI moved above 90, and a _HOLD_ action otherwise.

```TypeScript
import {rsi2Strategy} from 'indicatorts';

const actions = rsi2Strategy(asset);
```

#### Stochastic Oscillator Strategy

The [stochasticOscillatorStrategy](./ichimokuCloudStrategy.ts) uses the _ao_ values that are generated by the [Stochastic Oscillator](../../indicator/momentum/index.md#stochastic-oscillator) indicator function to provide a _BUY_ action when _k_ and _d_ are less than 20, a _SELL_ action when the _k_ and _d_ are greather than 80, a _HOLD_ action otherwise.
Expand Down
30 changes: 30 additions & 0 deletions src/strategy/momentum/rsi2Strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2022 Onur Cinar. All Rights Reserved.
// https://github.com/cinar/indicatorts

import { Asset } from '../asset';
import { Action } from '../action';
import { rsi2 } from '../../indicator/momentum/rsi2';

/**
* RSI 2. When 2-period RSI moves below 10, it is considered deeply oversold,
* and the other way around when moves above 90.
*
* @param asset asset object.
* @returns strategy actions.
*/
export function rsi2Strategy(asset: Asset): Action[] {
const indicator = rsi2(asset.closings);

const actions = new Array<Action>(indicator.length);
for (let i = 0; i < actions.length; i++) {
if (indicator[i] < 10) {
actions[i] = Action.BUY;
} else if (indicator[i] > 90) {
actions[i] = Action.SELL;
} else {
actions[i] = Action.HOLD;
}
}

return actions;
}

0 comments on commit 12d47b6

Please sign in to comment.