-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overlays set up #230
Comments
You can find the how-to in docs, but it's cleary shown on tests/examples. It's simple:
|
Got it, but still not clear few moments:
Thanks for help |
I'm guessing you'll need a timestamp to map to the x-axis. original code: https://github.com/tvjsx/tvjs-overlays/blob/master/src/overlays/Stoch/Stoch.vue#L38 I've made some customizations. import { Overlay } from 'trading-vue-js'
export default {
name: 'Stochastic',
mixins: [
Overlay
],
computed: {
lineWidth () {
return this.settings.lineWidth || 0.75
},
kWidth () {
return this.settings.kWidth || this.lineWidth
},
dWidth () {
return this.settings.dWidth || this.lineWidth
},
kColor () {
return this.settings.kColor || '#0915f4'
},
dColor () {
return this.settings.dColor || '#f43409'
},
bandColor () {
return this.settings.bandColor || '#b5b3b3'
},
backColor () {
// return this.settings.backColor || '#381e9c16'
return 'rgba(182, 178, 184, 0.1)'
}
},
methods: {
meta_info () {
return {
author: 'StdSquad',
version: '1.0.1',
desc: this.desc
}
},
draw (ctx) {
const layout = this.$props.layout
const upper = layout.$2screen(this.settings.upper || 80)
const lower = layout.$2screen(this.settings.lower || 20)
// K
ctx.lineWidth = this.kWidth
ctx.strokeStyle = this.kColor
ctx.beginPath()
for (const p of this.$props.data) {
const x = layout.t2screen(p[0])
const y = layout.$2screen(p[1])
ctx.lineTo(x, y)
}
ctx.stroke()
// D
ctx.lineWidth = this.dWidth
ctx.strokeStyle = this.dColor
ctx.beginPath()
for (const p of this.$props.data) {
const x = layout.t2screen(p[0])
const y = layout.$2screen(p[2])
ctx.lineTo(x, y)
}
ctx.stroke()
ctx.strokeStyle = this.bandColor
ctx.setLineDash([5]) // Will be removed after draw()
ctx.beginPath()
// Fill the area between the bands
ctx.fillStyle = this.backColor
ctx.fillRect(0, upper, layout.width, lower - upper)
// Upper band
ctx.moveTo(0, upper)
ctx.lineTo(layout.width, upper)
// Lower band
ctx.moveTo(0, lower)
ctx.lineTo(layout.width, lower)
ctx.stroke()
},
use_for () {
return ['Stochastic']
},
data_colors () {
return [this.color]
},
y_range (hi, lo) {
return [
Math.max(hi, this.settings.upper || 80),
Math.min(lo, this.settings.lower || 20)
]
},
calc () {
return {
props: {
type: {
def: 'slow'
},
hiddenK: {
def: false
},
hiddenD: {
def: false
},
k: {
def: 5,
text: '%K'
},
d: {
def: 3,
text: '%D'
},
smooth: {
def: 3,
text: 'Smooth'
}
},
update: `
const fast_k_array = stoch(close, high, low, k, 'stoch')
const fast_d_array = sma(fast_k_array, d, 'sma')
if (type === "slow") {
const slow_k = !hiddenK ? sma(fast_k_array, smooth, fast_k_array._id)[0] : undefined
const slow_d = !hiddenD ? sma(fast_d_array, smooth, fast_d_array._id)[0] : undefined
return [slow_k, slow_d]
} else {
return [!hiddenK ? fast_k_array[0] : undefined, !hiddenD ? fast_d_array[0] : undefined]
}
`
}
}
}
} |
I'm pretty new in using this lib so things are confusing for me. I've read all docs but still can't figure out few things. How can I add SMA,EMA,RSI etc indicators on my chart and get calculated points? I've tried to do like this
but can't specify the range of days. I've also saw examples like this https://github.com/tvjsx/trading-vue-js/blob/master/docs/guide/OVERLAYS.md#null-overlay but don't understand how to include it on my chart.
The text was updated successfully, but these errors were encountered: