[英]writing a simple condition for pine script
我想為 pine 腳本寫一個簡單的條件,如果價格達到加號,則背景顏色將為綠色,如下圖所示。 但我寫了它,它不是我所期望的它只為兩支蠟燭制作背景,我想要它為所有接下來的蠟燭。 我怎樣才能做到這一點? 謝謝這是圖片
//@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)
//@version=4
study("My Script", overlay=true)
CO1 = "Crossover", CO2 = "Above"
priceLevel = input(1650)
condition = input(CO1, options=[CO1, CO2])
var bool triggered = na
if condition == CO1
triggered := crossover(close, priceLevel)
else if condition == CO2
triggered := close > priceLevel
else
triggered := false
bgcolor(triggered ? color.green : na)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.