【发布时间】:2020-12-05 19:13:12
【问题描述】:
我正在尝试找出是否有一种方法可以运行多行代码,同时防止其他几行在 pine-script 中运行。希望下面的示例代码场景能阐明我的意图:
//@version=4
study("Example Code", overlay = true, shorttitle = "ExampleCode")
//I have created an drop down selector input:
DropDownInput = input(title="Select Input”, defval="Green", options=["Green", "Yellow", "Red"])
// Is there a way for me to select multiple rows of the below code to run based on whichever color is selected at the above DropDownInput
// "Green" Code would be something like and if "Green" is selected at DropDownInput only these rows of code would execute
ShortMA = input(defval=15)
LongMA = input(defval=30)
ShortMACode = sma(close,ShortMA)
LongMACode = sma(close,LongMA)
BUYSignal1 = crossover(sma(close,ShortMA), sma(close,LongMA))
line1 = plot(ShortMACode, color=color.silver, title="Short MA", style=plot.style_line, linewidth = 0)
line2 = plot(LongMACode, color=color.black, title="Long MA", style=plot.style_line, linewidth = 0)
fill(line1, line2, color = ShortMACode>LongMACode ? color.green : color.red)
plotshape(BUYSignal1, style=shape.triangleup,location=location.abovebar, color=color.green, size=size.small)
//End of "Green" executed code
// "Yellow" Code would be something like and if "Yellow" is selected at DropDownInput only these rows of code would execute
ShortMA = input(defval=20)
LongMA = input(defval=40)
ShortMACode = sma(close,ShortMA)
LongMACode = sma(close,LongMA)
BUYSignal1 = crossover(sma(close,ShortMA), sma(close,LongMA))
line1 = plot(ShortMACode, color=color.silver, title="Short MA", style=plot.style_line, linewidth = 0)
line2 = plot(LongMACode, color=color.black, title="Long MA", style=plot.style_line, linewidth = 0)
fill(line1, line2, color = ShortMACode>LongMACode ? color.green : color.red)
plotshape(BUYSignal1, style=shape.triangleup,location=location.abovebar, color=color.green, size=size.small)
//End of "Yellow" executed code
// "Red" Code would be something like and if "Red" is selected at DropDownInput only these rows of code would execute
ShortMA = input(defval=30)
LongMA = input(defval=60)
ShortMACode = sma(close,ShortMA)
LongMACode = sma(close,LongMA)
BUYSignal1 = crossover(sma(close,ShortMA), sma(close,LongMA))
line1 = plot(ShortMACode, color=color.silver, title="Short MA", style=plot.style_line, linewidth = 0)
line2 = plot(LongMACode, color=color.black, title="Long MA", style=plot.style_line, linewidth = 0)
fill(line1, line2, color = ShortMACode>LongMACode ? color.green : color.red)
plotshape(BUYSignal1, style=shape.triangleup,location=location.abovebar, color=color.green, size=size.small)
//End of "Red" executed code
【问题讨论】:
标签: pine-script