Lu Shen Simple Volatility Strategy Pine Language Version
From a simple volatility strategy published by a user two years ago https://www.fmz.com/strategy/200131 I accidentally came across it and rewrote it with PINE, reducing the amount of code by 90%. It is a reference…
From a simple volatility strategy published by a user two years ago
https://www.fmz.com/strategy/200131
I accidentally came across it and rewrote it with PINE, reducing the amount of code by 90%. It is a reference for quantitative friends.

Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 50 | Index Calculation Period |
Source Pine Script
/*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, 'Index Calculation Period')
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()
Published by 发明者量化 on the FMZ strategy square · last modified 2022-05-29. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Lu-Shen-Simple-Volatility-Strategy-Pine-Language-Version.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Dual Bollinger Band Volatility Tracking StrategyPine Script · Volatility · 1d
- Dual Moving Average Volatility Tracking StrategyPine Script · Volatility · 1h
- Multi Indicator Dynamic Volatility Alert Trading SystemPine Script · Volatility · 1m
- Multi Indicator Volatility Trading RSI EMA ATR StrategyPine Script · Volatility · 3m
- Quantitative Trading Strategy Based on Double EMA and Price Volatility IndexPine Script · Volatility · 1h
- Bullish Engulfing Quantitative Trading System with Bollinger Bands Risk ManagementPine Script · Volatility · 1d