calculate rsi

 const newFunction = async () => {

     // https://stackoverflow.com/questions/70452789/node-js-find-the-same-rsi-as-tradingview
     // https://gist.github.com/jmoz/1f93b264650376131ed65875782df386
     // https://stackoverflow.com/questions/50203625/calculate-rsi-based-on-kraken-ohlc
     // topdown1.count({}, function( err, count){
          //  console.log( "Number of data in db :", count );
          // topdown1.find(async (err,items)=>{
               // if(err){  
               //      console.log(err)
               // }
               // else{
                    const ticker = await exchange.fetchTicker('BTC/USDT')
                    const ohlcv = await exchange.fetchOHLCV('BTC/USDT','1m')
                    console.log( ohlcv[ohlcv.length - 1][4])
                    // console.log(ohlcv[ohlcv.length - 1])
                    // console.log(ohlcv[ohlcv.length - 2])
                    // console.log(ohlcv)
 
                    let jrr = [];
                    // const dc = parseInt(count)
                    const data  =  [
                         
               ohlcv[ohlcv.length -15][4],
               ohlcv[ohlcv.length -14][4],
               ohlcv[ohlcv.length -13][4],
               ohlcv[ohlcv.length -12][4],
               ohlcv[ohlcv.length -11][4],
               ohlcv[ohlcv.length -10][4],
               ohlcv[ohlcv.length -9][4],
               ohlcv[ohlcv.length -8][4],
               ohlcv[ohlcv.length -7][4],
               ohlcv[ohlcv.length -6][4],
               ohlcv[ohlcv.length -5][4],
               ohlcv[ohlcv.length -4][4],
               ohlcv[ohlcv.length - 3][4],
               ohlcv[ohlcv.length - 2][4],
               ohlcv[ohlcv.length - 1][4],
          ]
          // const result = rsi2(data);
          // console.log(result)
          // console.log(data)
          console.log(data.length)

          // ta.add( ohlcv[ohlcv.length - 1][4]);
 
          // Calculate the RSI
          // ta.RSI
          // const rsi1 = ta.rsi(data); // You can adjust the number of periods (14) to your liking
         
          // console.log(`BTC/USDT RSI: ${rsi1}`);



          var length = 15; // default = 14
          let res = await ta.rsi(data, length);
         
          //    console.log({mine:res})

          // let arr = [];
          let sub = [];
          let add = [];
          let avgGain = 0.0;
          let aveLoss = 0.0;
          for(var i = 0 ; i < data.length;i++){
              let sd = data[i+1]
              if(sd != undefined){
                  // console.log(sd)
                  let d = sd -  data[i];
                  if(d > 0 ){
                    let nd1 = d.toFixed(2)
                    avgGain += d;
                    add.push(parseFloat(nd1))
                  }
                  else if(d<0){
                    let nd2 = d.toFixed(2)
                    sub.push(parseFloat(nd2))
                    aveLoss += d * -1;
                  }
                  let nd = d.toFixed(2)
                  jrr.push(parseFloat(nd))
              }
          }
         
          avgGain /= 14;
          // console.log(avgGain)
          // console.log(aveLoss)
          aveLoss /= 14

          // console.log(jrr)
                    let  sum =0
                    for(a=0;a<add.length;a++){
                         // if(a == add.length -1){
       
                         // }
                         // else {
                             sum +=  add[a]
                         // }
                    }
                    let min = 0;
                    for(a=0;a<sub.length;a++){
                         // if(a == sub.length-1 ){

                         // }
                         // else {
                     
                             min +=  sub[a]
                         // }
                    }
                    let s = 0;
                    for(a=0;a<jrr.length;a++){
                         if(a == jrr.length -1){
       
                         }
                         else {
                             s +=  jrr[a]
                         }
                    }
                    let sma = s/13
     
                    console.log({jrr:jrr[jrr.length-1]})
                 let currentdiff = jrr[jrr.length-1]
                   
                    let nmin = min * -1
                         let ag = sum/ 15;
                         let al = nmin/ 15;
                         var rs = ag / al;

                         let rsi =  (100 - (100 / (1 + rs)))
 
                         console.log({releativestrengthindex: (rsi)})
          //   }
          //  })                
          // })                
}
// newFunction()
setInterval(newFunction, 1000)




Comments

All time Best Post

Write a program that declares a class named Person. It should have instance variables to record name, age and salary. Use new operator to create a Person object. Set and display its instance variables.

IMAGE CRUD OPERATION USING EXPRESS MONGOOSE MULTER

connect websocket to binance api and store t he true value in the db

CRUD APP WITH SORT IN NODE EXPRESS AND MONGODB

express session login system using node express mongodb

how to delete image from the folder directly from a Request (MULTER)

java program for 1 to 10 print using while loop

How to fetch last one minute volume of BTC in CCXT Nodejs.