Support Board
Date/Time: Sat, 30 Nov 2024 01:33:34 +0000
Post From: wave trend oscillator
[2022-07-13 20:20:00] |
User411320 - Posts: 289 |
any way the wave trend oscillator can be put in SC? this is code from Tradeovate. const predef = require("./tools/predef"); const meta = require("./tools/meta"); const EMA = require("./tools/EMA"); const SMA = require("./tools/SMA"); const typicalPrice = require("./tools/typicalPrice"); const p = require("./tools/plotting"); class waveTrendOscillator { init() { this.c1 = EMA(this.props.channelLength); this.c2 = EMA(this.props.channelLength); this.a = EMA(this.props.averageLength); this.s = SMA(this.props.smoothLength); this.pWt1 = 0.0; this.pWt2 = 0.0; this.obIndex = 0; this.osIndex = 0; this.crossunderIndex = 0; this.crossoverIndex = 0; } map(d, i, history) { const typ = typicalPrice(d); let esa = this.c1(typ); let dist = this.c2(Math.abs(typ - esa)); let ci = (typ - esa) / (this.props.cciConstant * dist); let ci2 = Number.isNaN(ci) ? 0 : ci let wt1 = this.a(ci2); let wt2 = this.s(wt1); const obValue = Math.min(this.props.overbought1, this.props.overbought2) const osValue = Math.max(this.props.oversold1, this.props.oversold2); // save index of where ob/os condition occurred if (this.pWt1 obValue) { this.obIndex = i; } if (this.pWt1 >= osValue && wt1 < osValue) { this.osIndex = i; } // crossunder from overbought let sell = false; let buy = false; if (this.pWt1 >= this.pWt2 && wt1 < wt2) { if (this.obIndex < i && this.obIndex > this.crossunderIndex) { this.crossunderIndex = i; sell = true; } } // crossover from oversold if (this.pWt1 wt2) { if (this.osIndex < i && this.osIndex > this.crossoverIndex) { this.crossoverIndex = i; buy = true; } } this.pWt1 = wt1; this.pWt2 = wt2; return { waveTrend: wt1, waveTrendSmooth: wt2, ob1: this.props.overbought1, ob2: this.props.overbought2, os1: this.props.oversold1, os2: this.props.oversold2, mid: 0, buy, sell, buyColor: this.props.buyColor, sellColor: this.props.sellColor, } } filter(_, i) { return i >= this.props.averageLength && i >= this.props.channelLength; } } function tradePlotter(canvas, indicatorInstance, history) { for(let i=0; i 0) { if (item.buy || item.sell) { const x = p.x.get(item); const item1 = history.get(i - 1); const x1 = p.x.get(item1); const y = item.buy ? Math.min(item.waveTrend, item.waveTrendSmooth) : Math.max(item.waveTrend, item.waveTrendSmooth) canvas.drawLine( p.offset(x1, y), p.offset(x, y), { color: item.buy ? item.buyColor : item.sellColor, relativeWidth: 2, opacity: 1.0 }); } } } } module.exports = { name: "waveTrendOscillator", description: "Wave Trend Oscillator", calculator: waveTrendOscillator, params: { channelLength: predef.paramSpecs.period(10), averageLength: predef.paramSpecs.period(21), smoothLength: predef.paramSpecs.period(4), cciConstant: predef.paramSpecs.number(0.015, 0.001, 0.001), overbought1: predef.paramSpecs.period(60), overbought2: predef.paramSpecs.period(53), oversold1: predef.paramSpecs.period(-60), oversold2: predef.paramSpecs.period(-53), buyColor: predef.paramSpecs.color('cyan'), sellColor: predef.paramSpecs.color('magenta'), }, tags: [predef.tags.Oscillators], areaChoice: meta.AreaChoice.NEW, inputType: meta.InputType.BARS, plots: { waveTrend: { title: "Wave Trend"}, waveTrendSmooth: { title: "Wave Trend Smoothed"}, ob1: { title: "Overbought 1", displayOnly: true}, ob2: { title: "Overbought 2", displayOnly: true}, os1: { title: "Oversold 1", displayOnly: true}, os2: { title: "Oversold 2", displayOnly: true}, mid: { title: "Mid", displayOnly: true}, }, plotter: [ predef.plotters.singleline("waveTrend"), predef.plotters.singleline("waveTrendSmooth"), predef.plotters.singleline("ob1"), predef.plotters.singleline("ob2"), predef.plotters.singleline("os1"), predef.plotters.singleline("os2"), predef.plotters.singleline("mid"), predef.plotters.custom(tradePlotter), ], schemeStyles: { dark: { waveTrend: predef.styles.plot("#00C0C0"), waveTrendSmooth: predef.styles.plot("#C000C0"), ob1: predef.styles.plot("#FF0000"), ob2: predef.styles.plot({ color: "#FF0000", lineStyle: 3 }), os1: predef.styles.plot("#00FF00"), os2: predef.styles.plot({ color: "#00FF00", lineStyle: 3 }), mid: predef.styles.plot("#707070"), } } }; |