一次设置 2 个系列 [英] Set 2 series at once
问题描述
我试图同时在 2 个系列中设置高点和低点,但似乎无法正确设置代码.
它应该在指定日期的每个日内柱上绘制输入的最高和最低值.
该代码旨在与股票代码 SPX 配合使用.
I'm trying to set Highs and Lows in 2 series at the same time, but can't seem to get the code right.
It should plot the entered high and low values at every intraday bar, for the specified date.
The code is designed to work with ticker SPX.
//@version=4
study("SPX 5", overlay=true)
// === FUNCTIONS ===
isDate(y,m,d) => year==y and month==m and dayofmonth==d
float lo = na
float hi = na
drawHiLo(y,m,d,l,h) =>
float ret1 = na
float ret2 = na
if isDate(y,m,d) and timeframe.isintraday
ret1 := l
ret2 := h
else
ret1 = lo[1]
ret2 = hi[1]
[ret1,ret2]
// === MAIN ===
[lo,hi] = drawHiLo(2020,04,13,2700,2770)
[lo,hi] = drawHiLo(2020,04,14,2800,2860)
plot(lo, style=plot.style_circles, color=color.lime)
plot(hi, style=plot.style_circles, color=color.lime)
上面的脚本给出了以下错误:line 22: 'lo' is already defined.
The above script gives the following error: line 22: 'lo' is already defined.
我尝试了几种不同的方法,但似乎都不起作用.
有人知道如何做到这一点吗?
I've tried several different approaches, but none seem to work.
Does someone have an idea on how to accomplish this?
推荐答案
您现在可以通过脚本的输入更改值.在代码中添加了一些注释.如果有什么不清楚的,请随时询问:
You can now change the values through the script's inputs. Added a few comments in code. Feel free to ask if what's going isn't clear:
//@version=4
study("SPX 5", overlay=true)
// Get values through Inputs.
spHi1 = input(2770)
spLo1 = input(2700)
spHi2 = input(2860)
spLo2 = input(2800)
// === FUNCTIONS ===
isDate(y,m,d) => year==y and month==m and dayofmonth==d
drawHiLo(y,m,d,l,h) =>
// Vars are initialized to na, so we only need to assign them a value when our conditions becomes true.
float ret1 = na
float ret2 = na
if isDate(y,m,d) and timeframe.isintraday
ret1 := l
ret2 := h
[ret1, ret2]
// === MAIN ===
// Make 2 separate call to function, but need to store results in different variables for each call.
[lo1,hi1] = drawHiLo(2020,04,13,spLo1,spHi1)
[lo2,hi2] = drawHiLo(2020,04,14,spLo2,spHi2)
plot(hi1, style=plot.style_circles, color=color.lime)
plot(lo1, style=plot.style_circles, color=color.lime)
plot(hi2, style=plot.style_circles, color=color.green)
plot(lo2, style=plot.style_circles, color=color.green)
这个功能的概念很好,顺便说一句.恭喜.
Nice concept with the function, btw. Congrats.
这篇关于一次设置 2 个系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!