0bps

Strategy vault / Volatility

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…

Pine ScriptVolatilitySMA
Author
发明者量化
Complexity
Starter · 36 lines
Parameters
1
Backtest bar
1d · swing
Tested on
BTC/USD · spot

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.

IMG

Parameters

NameDefaultWhat it controls
v_input_150Index 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.

in Claude Code, Cursor, Codex & 4 more
/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
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open