【发布时间】:2021-01-24 09:18:28
【问题描述】:
我想为 pine 脚本写一个简单的条件,如果价格达到加号,则背景颜色将为绿色,如下图所示。但我写了它,它不是我所期望的它只为两支蜡烛制作背景,我想要它为所有接下来的蜡烛。我怎样才能做到这一点?谢谢This is the picture
//@version=4
study(title="My Indicator", overlay=true)
// Entry Point
entryPointLong = highest(high, 100)
entryPointShort = lowest(low, 100)
// Entry Point Condition
entryPointLongCond = close >= entryPointLong ? color.green : na
entryPointShortCond = close <= entryPointShort ? color.red : na
// Plot
plot(entryPointLong, title="Entry Long", style=plot.style_cross, linewidth=5, show_last=1, color=color.green)
plot(entryPointShort, title="Entry Short", style=plot.style_cross, linewidth=5, show_last=1, color=color.red)
// Background Color
bgcolor(entryPointLongCond, transp=70)
bgcolor(entryPointShortCond, transp=70)
更新代码:
//@version=4
study(title="My Indicator", overlay=true)
// Entry Point
entryPointLong = highest(high, 100)
entryPointShort = lowest(low, 100)
// Stop Loss
stopLossLongInput = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1, defval=3) * 0.01
stopLossLong = entryPointLong * (1 - stopLossLongInput)
// Entry Point Condition
entryPointLongTrue = close >= entryPointLong
if entryPointLongTrue
entryPointLong := stopLossLong
color.green
entryPointLongCond = close >= entryPointLong ? color.green : na
entryPointShortCond = close <= entryPointShort ? color.red : na
// Plot
plot(entryPointLong, title="Entry Long", style=plot.style_cross, linewidth=5, show_last=1, color=color.green)
plot(entryPointShort, title="Entry Short", style=plot.style_cross, linewidth=5, show_last=1, color=color.red)
plot(stopLossLong, title="Entry Short", style=plot.style_cross, linewidth=5, show_last=1, color=color.red)
// Background Color
bgcolor(entryPointLongCond, transp=70)
bgcolor(entryPointShortCond, transp=70)
【问题讨论】:
-
我正在为 Trading View 平台编写指标。加号代表最高价的 200 支蜡烛。我想写一个条件,如果价格达到加号,背景颜色将为绿色,然后开多头头寸,但现在我只希望我的背景颜色为绿色。
-
背景颜色只会使两根蜡烛变成绿色,但我正在尝试编写一个代码,将止损设置在进场点下方 3% 的位置,这样下一根蜡烛就会变成绿色。请帮我。谢谢
标签: function conditional-statements pine-script indicator