我想为买入条件编写代码:收盘价在过去 5 根柱线中一直在上涨
I want to write a code for a buy condition: closing price has been rising for the last 5 bars
假设我的策略是买入在过去 5 个柱中一直上涨的股票。
我会这样写:
longCondition = (close > close[1]) and (close[1] > close[2]) and (close[2] > close[3]) and (close[3] > close[4]) and (close[4] > close[5])
但是,我觉得有一种更简单的方法可以通过使用自我更新的变量来对此进行编码。不过我不太确定。我该如何改进?
您可以使用内置函数 rising()
和 falling()
例如
longCondition = rising(close, 5)
https://www.tradingview.com/pine-script-reference/v4/#fun_rising
假设我的策略是买入在过去 5 个柱中一直上涨的股票。
我会这样写:
longCondition = (close > close[1]) and (close[1] > close[2]) and (close[2] > close[3]) and (close[3] > close[4]) and (close[4] > close[5])
但是,我觉得有一种更简单的方法可以通过使用自我更新的变量来对此进行编码。不过我不太确定。我该如何改进?
您可以使用内置函数 rising()
和 falling()
例如
longCondition = rising(close, 5)
https://www.tradingview.com/pine-script-reference/v4/#fun_rising