简体   繁体   English

如何在 TradingView Pine-Script 中运行条件语句?

[英]How to Run a Conditional Statement in TradingView Pine-Script?

After looking through the Pine-Script documentation I could not figure out there "Switch" style conditional statement.在查看了 Pine-Script 文档后,我无法弄清楚“Switch”样式的条件语句。

I'm trying to subtract the opening and the closing from only the green candles.我试图仅从绿色蜡烛中减去开盘价和收盘价。

This is my current code:这是我当前的代码:

//@version=3 study(title="High Minus Low", shorttitle="HM0", overlay=true)

openall  = high[0]+high[1]+high[2]
closeall = open[0]+open[1]+open[2] total = openall + closeall

plot(total)

I only want to grab the latest 3 green candle bars using a conditional statement.我只想使用条件语句获取最新的 3 个绿色蜡烛条。

Is this possible?这可能吗?

There is no "switch" statement in PineScript. PineScript 中没有“switch”语句。 However you may use 'if' statements for your task.但是,您可以为您的任务使用“if”语句。 For example例如

green_delta = 0.0
if close > open
    green_delta := open - close 
plot(green_delta)    

Pinescript v5 支持switch语句:https ://www.tradingview.com/pine-script-reference/v5/#op_switch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM