Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'tulind' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// OG data secured
const request = require('request')
const tulind = require('tulind')
const I = tulind.indicators
const fs = require('fs')
const write_to = './data/data.json'
const t1 = Math.floor(new Date().getTime() / 1000)
const t0 = t1 - 3600 * 4200
// Hey Coingy, we will borrow some data, ok?
const mrk = 'BITF/BTC/USD'
const url = `https://www.coinigy.com/getjson/chart_feed/${mrk}/60/${t0}/${t1}`
request
.get(url, {}, function(err,res,body) {
if (err) {
console.log('Not this time, bro')
process.exit()
return new Promise((resolve, reject) => {
if (s.lookback.length >= Math.max(shortPeriod, longPeriod)) {
let tmpMarket = optMarket
if (!tmpMarket) {
tmpMarket = s.lookback.slice(0, 1000).map((x) => x.close)
tmpMarket.reverse()
// add current period
tmpMarket.push(s.period.close)
} else {
tmpMarket = tmpMarket.map((x) => x.close)
}
tulind.indicators.macd.indicator([tmpMarket], [shortPeriod, longPeriod, signalPeriod], (err, result) => {
if (err) {
console.log(err)
reject(err)
return
}
resolve({
macd: result[0],
macd_histogram: result[2],
macd_signal: result[1],
})
})
} else {
reject()
}
})
if (s.lookback.length >= Math.max(kPeriods, dPeriods, skPeriods)) {
// dont calculate until we have enough data
let tmpMarket = optMarket
if (!tmpMarket) {
tmpMarket = s.lookback.slice(0, 1000)
tmpMarket.reverse()
// add current period
tmpMarket.push(s.period)
}
const tmpMarketHigh = tmpMarket.map((x) => x.high)
const tmpMarketClose = tmpMarket.map((x) => x.close)
const tmpMarketLow = tmpMarket.map((x) => x.low)
// addCurrentPeriod
tulind.indicators.stoch.indicator(
[tmpMarketHigh, tmpMarketLow, tmpMarketClose],
[kPeriods, skPeriods, dPeriods],
(err, result) => {
if (err) {
console.log(err)
reject(err)
return
}
resolve({
d: result[1],
k: result[0],
})
}
)
} else {
let tmpMarket = optMarket
if (!tmpMarket) {
tmpMarket = s.lookback.slice(0, 1000).map((x) => x.close)
tmpMarket.reverse()
// add current period
tmpMarket.push(s.period.close)
} else {
tmpMarket = tmpMarket.map((x) => x.close)
}
if (tmpMarket.length >= rsiPeriod) {
// doublecheck length.
if (tmpMarket.length >= rsiPeriod) {
// extract int from string input for ma_type
tulind.indicators.rsi.indicator([tmpMarket], [rsiPeriod], (err, result) => {
if (err) {
console.log(err)
reject(err)
return
}
const trsi = result[0]
// 0 oldest -- end newest
trsi.reverse()
const stochRSI = []
for (let i = 0; i < kPeriods + dPeriods - 1; i++) {
const rsiForPeriod = trsi.slice(i, rsiPeriod + i)
const highestRSI = Math.max(...rsiForPeriod)
const lowestRSI = Math.min(...rsiForPeriod)
if (highestRSI === lowestRSI) {
let tmpMarket = optMarket
if (!tmpMarket) {
tmpMarket = s.lookback.slice(0, 1000).map((x) => x.close)
tmpMarket.reverse()
// add current period
tmpMarket.push(s.period.close)
} else {
tmpMarket = tmpMarket.map((x) => x.close)
}
if (tmpMarket.length >= rsiPeriod) {
// doublecheck length.
if (tmpMarket.length >= rsiPeriod) {
// extract int from string input for ma_type
tulind.indicators.rsi.indicator([tmpMarket], [rsiPeriod], (err, result) => {
if (err) {
console.log(err)
reject(err)
return
}
resolve({
rsi: result[0],
})
})
} else {
reject('MarketLenth not populated enough')
}
} else {
reject('MarketLenth not populated enough')
}
})
async evaluate(ticker) {
let series = ticker.series;
if (series && series.length() >= this.periods[2]) {
let slice = series.transpose(this.props, this.periods[2] * 5); // this grabs the desired properties from the series
let last = series.last();
// [macd, macd signal, macd histogram]
let [foo, bar, histo] = await tulind.indicators.macd.indicator(slice, this.periods);
if (this.hasBuySignal(histo)) return sig.BUY;
else if (this.hasSellSignal(histo)) return sig.SELL;
}
return sig.PASS;
}
if (s.lookback.length > s.marketData.close.length) {
for (let i = s.lookback.length - s.marketData.close.length - 1; i >= 0; i--) {
s.marketData.close.push(s.lookback[i].close)
}
}
if (s.marketData.close.length < minPeriods) {
resolve()
return
}
const tmpClose = s.marketData.close.slice()
tmpClose.push(s.period.close)
ti.indicators.hma.indicator([tmpClose], [trendFull], (err, results) => {
resolve(results[0][results[0].length - 1])
})
})
}
public async evaluate(ticker:OHLCVTicker):Promise {
let series = ticker.series;
if (series && series.length() > 0) {
let slice:Number[][] = series.transpose(this.props, 50);
let last:Tick = series.last();
let obv = await tulind.indicators.obv.indicator(slice, []);
if (this.hasBuySignal(obv[0])) return Signal.BUY;
else if (this.hasSellSignal(obv[0])) return Signal.SELL;
}
return Signal.PASS;
}
export const Tulind = (indicatorName: keyof Indicators) => {
const indicator = tulind.indicators[indicatorName].indicator
return (inputs: number[], options: number[] = null) =>
new Promise((resolve, reject) => indicator(inputs, options, (err, result) => (err ? reject(err) : resolve(result))))
}
return (data, callback) => execute(callback, {
indicator: tulind.indicators.mass,
inputs: [data.high, data.low],
options: [params.optInTimePeriod],
results: ['result'],
});
}