Giter VIP home page Giter VIP logo

trading-indicator's Introduction

trading-indicator

npm version

provide trading technical indicator values based on market data of almost crypto currency exchanges https://www.npmjs.com/package/trading-indicator

☕ Give me a coffee ❤️

Installation

Node.js version 10 or later is required

npm install --save trading-indicator

Fetch ticker information

  • Parameter:
    • Exchange name
    • Symbol
    • IsFuture exchange
let ticker = await indicators.ticker("binance", symbol, true)

The structure of a ticker is as follows:

{
    'symbol':        string symbol of the market ('BTC/USD', 'ETH/BTC', ...)
    'info':        { the original non-modified unparsed reply from exchange API },
    'timestamp':     int (64-bit Unix Timestamp in milliseconds since Epoch 1 Jan 1970)
    'datetime':      ISO8601 datetime string with milliseconds
    'high':          float, // highest price
    'low':           float, // lowest price
    'bid':           float, // current best bid (buy) price
    'bidVolume':     float, // current best bid (buy) amount (may be missing or undefined)
    'ask':           float, // current best ask (sell) price
    'askVolume':     float, // current best ask (sell) amount (may be missing or undefined)
    'vwap':          float, // volume weighed average price
    'open':          float, // opening price
    'close':         float, // price of last trade (closing price for current period)
    'last':          float, // same as `close`, duplicated for convenience
    'previousClose': float, // closing price for the previous period
    'change':        float, // absolute change, `last - open`
    'percentage':    float, // relative change, `(change/open) * 100`
    'average':       float, // average price, `(last + open) / 2`
    'baseVolume':    float, // volume of base currency traded for last 24 hours
    'quoteVolume':   float, // volume of quote currency traded for last 24 hours
}

Available Indicators

Available Alerts

Supported exchanges

Supported interval

  • 1m : 1 minute
  • 5m: 5 minutes
  • 15m: 15 minutes
  • 30m: 30 minutes
  • 45m: 45 minutes
  • 1h : 1 hour
  • 2h : 2 hours
  • 4h : 4 hours
  • 1d : 1 day
  • 1w : 1 week
  • 1M : 1 month

Sample code

ATR (Average True Range)

  • Parameters:
    • Period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { atr, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
  let atrData = await atr(14, "close", input)
  console.log(atrData[atrData.length - 1])

ADX (Average Directional Index)

  • Parameters:
    • Period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { adx, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
  let adxData = await adx(14, "close", input)
  console.log(adxData[adxData.length - 1])

BB (Bollinger bands)

  • Parameters:
    • Bollinger bands period: integer
    • stdDev : integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { bb, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
    let bbData = await bb(50, 2, "close", input)
    console.log(bbData[bbData.length - 2])

EMA (Exponential Moving Average)

  • Parameters:
    • MA period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { ema, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
  let emaData = await ema(8, "close", input)
  console.log(emaData[emaData.length - 1])

IchimokuCloud

  • Parameters:
    • conversionPeriod: integer
    • basePeriod: integer
    • spanPeriod: integer
    • displacement: integer
    • Input : detach from OHLCV
  const { ichimokuCloud, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
  console.log(await ichimokuCloud(9, 26, 52, 26, input))

MACD (Moving Average Convergence Divergence)

  • Parameters:
    • Fast period: integer
    • Slow period: integer
    • Signal period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { macd, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
    console.log(await macd(12, 26, 9, "close", input))

MFI

  • Parameters:
    • MFI period: integer
    • Input : detach from OHLCV
  const { mfi, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await mfi(14, input))

CCI

  • Parameters:
    • CCI period: integer
    • Input : detach from OHLCV
  const { cci, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await cci(14, input))

VWAP

  • Parameters:
    • Input : detach from OHLCV
  const { vwap, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await vwap(input))

OBV

  • Parameters:
    • Input : detach from OHLCV
  const { obv, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await obv(input))

RSI

  • Parameters:
    • RSI period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { rsi, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await rsi(14, "close", input))

SMA (Simple Moving Average)

  • Parameters:
    • MA period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { sma, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
  let smaData = await sma(8, "close", input)
  console.log(smaData[smaData.length - 1])

Stochastic RSI

  • Parameters:
    • kPeriod: integer
    • dPeriod: integer
    • rsiPeriod: integer
    • stochasticPeriod: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { stochasticRSI, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await stochasticRSI(3, 3, 14, 14, "close", input))

WMA (Weighted Moving Average)

  • Parameters:
    • MA period: integer
    • Input source: "open" | "high" | "low" | "close"
    • Input : detach from OHLCV
  const { wma, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
  let wmaData = await wma(8, "close", input)
  console.log(wmaData[wmaData.length - 1])

KST

  • Parameters:
    • Input : detach from OHLCV
    • ROC1
    • ROC2
    • ROC3
    • ROC4
    • SMA1
    • SMA2
    • SMA3
    • SMA4
    • SignalLength
  const { kst, getDetachSourceFromOHLCV } = require('trading-indicator')
  const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
   console.log(await kst(input, 10, 15, 20, 30, 10, 10, 10, 15, 9))

Golden cross / Death cross

  • Parameter:

    • MA_FAST (should be 50)
    • MA_SLOW (should be 200)
    • Input : detach from OHLCV

    Sample code

      const { goldenCross, deathCross, maCross, getDetachSourceFromOHLCV }  = require('trading-indicator')
      const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
    
      await goldenCross(50, 200, input) 
      await deathCross(50, 200, input) 
      
      // check both golden/death cross
      await maCross(50, 200, input) // response  { goldenCross: false, deathCross: false }

RSI in overBought/overSold area

  • Parameter:

    • RSI Period
    • OverBoughtThreshold (75)
    • OverSoldThreshold (25)
    • Input : detach from OHLCV

    Sample code

      const { rsiCheck, getDetachSourceFromOHLCV } = require('trading-indicator')
      const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
      await rsiCheck(14, 75, 25, input) 
      // Test RSIcheck
      // { overBought: false, overSold: false, rsiVal: 27.81 }

Price crosses SMA/EMA

  • Parameter:

    • MA Period
    • Input : detach from OHLCV

    Sample code

      const { priceCrossSMA, priceCrossEMA, getDetachSourceFromOHLCV }  = require('trading-indicator')
      const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
      await priceCrossSMA(14, input) 
      //Test SMA cross
      // { cross: true, direction: 'up' }
    
    
      await priceCrossEMA(14, input) 
      // Test EMA cross
      // { cross: true, direction: 'down' }
      ```

VWAP crosses SMA/EMA

  • Parameter:

    • MA Period
    • Input : detach from OHLCV

    Sample code

      const { vwapCrossSMA, vwapCrossEMA, getDetachSourceFromOHLCV }  = require('trading-indicator')
      const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
      await vwapCrossSMA(14, input) 
      //Test SMA cross
      // { cross: true, direction: 'up' }
    
    
      await vwapCrossEMA(14, input) 
      // Test EMA cross
      // { cross: true, direction: 'down' }

KST crossing

  • Parameter:

    • Input : detach from OHLCV
    • ROC1
    • ROC2
    • ROC3
    • ROC4
    • SMA1
    • SMA2
    • SMA3
    • SMA4
    • SignalLength

    Sample code

      const { kstCross, getDetachSourceFromOHLCV }  = require('trading-indicator')
      const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
      await kstCross(input, 10, 15, 20, 30, 10, 10, 10, 15, 9) 
      //Test KST cross
      // { cross: true, direction: 'up' }

Dependencies

trading-indicator's People

Contributors

mohamad-supangat avatar tan-kitty avatar thanhnguyennguyen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

trading-indicator's Issues

stochasticRSI isn't working TypeError: stochasticRSI is not a function

I'm trying to get stochasticRSI indicator but I got this TypeError
My code is copy from example for test

console.log(await stochasticRSI(3, 3, 14, 14, 'close', input));
                    ^
TypeError: stochasticRSI is not a function

Did I miss something for make it work?

full code:

const { stochasticRSI, getDetachSourceFromOHLCV } = require('trading-indicator');
const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false); // true if you want to get future market
  console.log(await stochasticRSI(3, 3, 14, 14, 'close', input));

TypeError: indicators.atr.calculate is not a function

hello,i just use the bellow code,the the error
image

anything i missed? how can i fixed it.

my code is :

async function test(){
const { atr, getDetachSourceFromOHLCV } = require('trading-indicator')
const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
console.log(input);
let atrData = await atr(14, "close", input)
console.log(atrData[atrData.length - 1])
}

(async function(){
// await ready()
await test()
})();

rading-indicator/indicators/atr.js:14

rading-indicator/indicators/atr.js:14
}
^

SyntaxError: Unexpected token '}'
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object. (/root/trading-indicator/index.js:15:8)

Proper Example of Driver Code to Run the trading-indicator Project

Hello and thanks for your contribution,

My bad if this is a noobie question since I am rather new to JS. I am wondering what is the proper way to setup extremely basic driver code in order to call the indicators and run the project.

I have simply created an app.js in the root directory and tried to run the RSI indicator snippet, as an example:

Screen Shot 2023-11-06 at 16 26 48

However, I get this issue / error:

SyntaxError: await is only valid in async functions and the top level bodies of modules

Something that may be a contributing issue to the above one, I tried to npm start this project and the run stops at:

"example to fetch data from binance"

Which is line 7 on package.json.

Thanks for any insight, thanks for this contribution, and best regards.

ATR INDICATOR

Hello , how can i add an indicator because i want to implement Average True Range indicator un your project 👍

Alerts moved?

Greetings!

Excellent library btw.

for your ema cross I don't see alerts being exported from main module.

  alerts = require('trading-indicator').alerts

  await alerts.priceCrossSMA(14, 'binance', 'BTC/USDT', '1h', false) 
  //Test SMA cross
  // { cross: true, direction: 'up' }


  await alerts.priceCrossEMA(14, 'binance', 'BTC/USDT', '1h', false) 
  // Test EMA cross
  // { cross: true, direction: 'down' }
  

Alerts here is returning undefined

I do see priceCrossEma on require('trading-indicator')

but when i try to use it , says ema is missing

ADX

Hello, can you add ADX indicator ?

Detect candlestick patterns

Detect below candlestick patterns:

  • Abandoned Baby.
  • Bearish Engulfing Pattern.
  • Bullish Engulfiing Pattern.
  • Dark Cloud Cover.
  • Downside Tasuki Gap.
  • Doji.
  • DragonFly Doji.
  • GraveStone Doji.
  • BullishHarami.
  • Bearish Harami Cross.
  • Bullish Harami Cross.
  • Bullish Marubozu.
  • Bearish Marubozu.
  • Evening Doji Star.
  • Evening Star.
  • Bearish Harami.
  • Piercing Line.
  • Bullish Spinning Top.
  • Bearish Spinning Top.
  • Morning Doji Star.
  • Morning Star.
  • Three Black Crows.
  • Three White Soldiers.
  • Bullish Hammer.
  • Bearish Hammer.
  • Bullish Inverted Hammer.
  • Bearish Inverted Hammer.
  • Hammer Pattern.
  • Hammer Pattern (Unconfirmed).
  • Hanging Man.
  • Hanging Man (Unconfirmed).
  • Shooting Star.
  • Shooting Star (Unconfirmed).
  • Tweezer Top.
  • Tweezer Bottom.

(This content is created via Gittool)
On behalf of thanhnguyennguyen

MFI Timestamp

How can we use timestamp property in MFI ? I think this is very important.

sma.js & ema.js vwap function usage & wrong variable definition

const vwapCrossSMA = async (period, input) => { let vwap = await vwap(input) let maVal = await sma(parseInt(period), 'close', input), price = vwapval.slice(-2), up = crossover(price, maVal), down = crossunder(price, maVal) return { cross: up || down, direction: up ? 'up' : down ? 'down' : 'none', } }

let vwap usage is preventing vwap function to call. That's why it is causing error. After i change the let vwap variable as let vwapVal it is worked. sma.js & ema.js have the same error and needs to be updated.

You can see the files here.
image

For ema.js this line is also missing.
const { vwap } = require('../indicators/vwap.js')

Get Current single value MACD (or other indicator)

Hi,

How to get the single value of MACD (or other any indicator), i get 400 values, i want to see only the current value in last 1 hour

For exemple the current MACD of BTCUDT is 100 but i got a banch of values from -300 to 1200

Thnks!

TypeError: indicators.atr.calculate is not a function

hello,i just use the bellow code,the the error
image

anything i missed? how can i fixed it.

my code is :

async function test(){
const { atr, getDetachSourceFromOHLCV } = require('trading-indicator')
const { input } = await getDetachSourceFromOHLCV('binance', 'BTC/USDT', '1h', false) // true if you want to get future market
console.log(input);
let atrData = await atr(14, "close", input)
console.log(atrData[atrData.length - 1])
}

(async function(){
// await ready()
await test()
})();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.