-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
486 additions
and
751 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,17 @@ | ||
// ---------------------------------------------------- | ||
// | MOVING AVERAGE INDICATORS | | ||
// ---------------------------------------------------- | ||
|
||
// ---------------------------------------------------- | ||
// | GLOBALS | | ||
// ---------------------------------------------------- | ||
|
||
const tulind = require('tulind') | ||
|
||
// ---------------------------------------------------- | ||
// | FUNCTIONS | | ||
// ---------------------------------------------------- | ||
import { simpleMovingAverage, exponentialMovingAverage } from 'indicatorts'; | ||
|
||
// Get SMA | ||
export async function indicatorSMA(candles: number[], length: number, limit?: number) { | ||
// Call SMA function from tulind with the candles and desired sma length | ||
const tulindReturn = await tulind.indicators.sma.indicator([candles], [length]) | ||
|
||
// Tulind can return a few things, in this case the SMA data is in the first item in its return | ||
const sma = tulindReturn[0] | ||
if (limit === undefined) limit = 1 | ||
|
||
// If you requested more SMA's then were generated return all that you have | ||
export function indicatorSMA(candles: number[], length: number, limit: number = 1): number[] { | ||
const sma = simpleMovingAverage(candles, { period: length }); | ||
if (limit >= sma.length) return sma | ||
// Return the most recent SMA | ||
if (limit === 1) return sma[sma.length - 1] | ||
// Return only a specific amount of SMA's | ||
if (limit === 1) return [sma[sma.length - 1]] | ||
else return sma.slice(sma.length - limit) | ||
} | ||
|
||
// Get EMA | ||
export async function indicatorEMA(candles: number[], length: number, limit?: number) { | ||
const ema = (await tulind.indicators.ema.indicator([candles], [length]))[0] | ||
if (limit !== undefined) { | ||
if (limit >= ema.length) return ema | ||
if (limit === 1) return ema[ema.length - 1] | ||
else return ema.slice(ema.length - limit) | ||
} | ||
return ema | ||
export function indicatorEMA(candles: number[], length: number, limit: number = 1): number[] { | ||
const ema = exponentialMovingAverage(candles, { period: length }); | ||
if (limit >= ema.length) return ema | ||
if (limit === 1) return [ema[ema.length - 1]] | ||
else return ema.slice(ema.length - limit) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters