吕神简易波动率策略Pine语言版本

Author: 发明者量化, Date: 2022-05-08 15:41:01
Tags:

https://www.fmz.com/strategy/200131

```/*backtest
start: 2021-05-16 00:00:00
end: 2022-05-15 23:59:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/

N = input(50, '指数计算周期')

vix = math.log(close) / math.log(close[N-1]) - 1
vix_ma = ta.sma(vix, N)
vix_ma_up = ta.highest(vix_ma, N)
vix_ma_down = ta.lowest(vix_ma, N)

plot(vix, 'vix')
plot(vix_ma, 'vix_ma')
upline = plot(vix_ma_up, 'vix_ma_up')
downline = plot(vix_ma_down, 'vix_ma_down')
fill(upline, downline, color=color.new(color.gray, 50))

qty = math.round(strategy.equity / close, 2)

if strategy.position_size == 0
if vix > vix_ma_up and vix[1] <= vix_ma_up[1]
strategy.entry("LONG", strategy.long, qty=qty)
else if vix < vix_ma_down and vix[1] >= vix_ma_down[1]
strategy.entry("SHORT", strategy.short, qty=qty)
else if strategy.position_size > 0
if vix < vix_ma and vix[1] >= vix_ma[1]
strategy.close_all()
else if strategy.position_size < 0
if vix > vix_ma and vix[1] <= vix_ma[1]
strategy.close_all()

```
template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6