0bps

Strategy vault / Trend following

Diamond Trend

Diamond Trend is an indicator clearly way to catch the trend in the begining $$ backtest

Author
ChaoZhang
Complexity
Starter · 47 lines
Parameters
5
Backtest bar
15m · intraday
Tested on
BTC/USDT · futures

Diamond Trend is an indicator clearly way to catch the trend in the begining $$

backtest

IMG

Parameters

NameDefaultWhat it controls
v_input_10.02start
v_input_20.02increment
v_input_30.2maximum
v_input_4100len
v_input_51.9Deviation

Source Pine Script

/*backtest
start: 2022-04-09 00:00:00
end: 2022-05-08 23:59:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © meer2019
//@version=4
study(title="PSAR x", overlay=true)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2)
c=close

psar = sar(start, increment, maximum)
cp = psar
len = input(100, minval=1),off= 0,dev= input(1.9, "Deviation")
lreg = linreg(cp, len, off), lreg_x =linreg(cp, len, off+1)
b = bar_index, s = lreg - lreg_x,intr = lreg - b*s
dS = 0.0
for i=0 to len-1
    dS:= dS + pow(cp[i]-(s*(b-i)+intr), 2)  
de = sqrt(dS/(len))
up = (-de*dev) + psar
down= (de*dev) + psar

up_t   = 0.0
up_t   := c[1] > up_t[1]   ? max(up, up_t[1])   : up
down_t = 0.0
down_t := c[1] < down_t[1] ? min(down, down_t[1]) : down
trend = 0
trend := c > down_t[1]  ? 1: c < up_t[1]  ? -1 : nz(trend[1], 1)

//
r_line = trend ==1 ? up_t : down_t
plot(r_line)
buy=crossover( c, r_line) 
sell=crossunder(c, r_line) 

if buy
    strategy.entry("Enter Long", strategy.long)
else if sell
    strategy.entry("Enter Short", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-10. 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/Diamond-Trend.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