Dari strategi mudah fluktuasi yang didedahkan pengguna dua tahun lalu
https://www.fmz.com/strategy/200131
Saya tidak sengaja membalik, menulis semula kod dengan PINE dan mengurangkan 90% jumlahnya.
/*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()