0bps

Strategy vault / Other

T Step LSMA

Pine Script strategy by Zer3192.

Pine ScriptOtherSMA
Author
Zer3192
Complexity
Starter · 35 lines
Parameters
3
Backtest bar
4h · intraday
Tested on
BTC/USDT · futures

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
v_input_1100length
v_input_20.5sc
v_input_3falseNo Smoothing

Source Pine Script

 /*backtest
start: 2021-05-08 00:00:00
end: 2022-05-07 23:59:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
study("T-Step LSMA",overlay=true)
length = input(100),sc = input(.5),ns = input(false,"No Smoothing")
//----
b = 0.,ls = 0.
src = sc*close+(1-sc)*nz(ls[1],close)
//----
er = 1 - abs(change(src,length))/sum(abs(change(src)),length)
n = cum(1)-1
a = cum(abs(src - nz(b[1],src)))/n*(1+er)
b := src > nz(b[1],src) + a ? src : src < nz(b[1],src) - a ? src : nz(b[1],src)
//----
alpha = fixnan(correlation(src,b,length) * (stdev(src,length)/stdev(b,length)))
beta = sma(src,length) - alpha*sma(b,length)
ls := alpha*b+beta
//----
osc = 0
osc := b > b[1] ? 1 : b < b[1] ? 0 : osc[1] 
css = osc == 1 ? color.blue :#e65100
plot(ns ? b : fixnan(ls),color=css,linewidth=3,transp=0)
alertcondition(change(osc)>0,title="Up",message="Up-trending Market Estimated")
alertcondition(change(osc)<0,title="Dn",message="Down-trending Market Estimated")
buySignal = change(osc)>0
sellSignal= change(osc)<0
if buySignal
    strategy.entry("buy", strategy.long)
else if sellSignal
    strategy.entry("sell", strategy.short) 

Published by Zer3192 on the FMZ strategy square · last modified 2022-06-25. 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/T-Step-LSMA.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