Strategy vault / Trend following
Trend Following Strategy Based on Price Friction Zones
This strategy measures price dwell time in different zones to identify low friction areas, and trades breakouts in these zones. It belongs to trend following strategies.
Overview
This strategy measures price dwell time in different zones to identify low friction areas, and trades breakouts in these zones. It belongs to trend following strategies.
Strategy Logic
Calculate price dwell ratio around current levels over past N periods as price friction.
Identify if price enters low friction zones with minimal dwell time recently.
Use fast weighted MA to determine recent trend direction. Trade breakouts in low friction zones along trend.
Take profit when price re-enters high friction zones anticipating trend reversal.
Customizable parameters including friction lookback, breakout zone etc.
Advantages
Price friction avoids ranging markets and finds trend outbreak zones.
Fast MA combines with friction to determine direction.
Intuitive visuals displaying price friction levels.
Default parameters optimized for crypto high frequency trading.
Simple and clear logic easy to comprehend and customize.
Risks
Price friction unable to fully predict future moves.
Fast MA may produce inaccurate timing.
Ineffective smoothing into and out of trades.
Optimization risks overfitting.
Fixed parameters may underperform in volatile markets.
Enhancement
Test different periods to calculate price friction.
Evaluate different MA types to determine recent trend.
Optimize breakout zone parameters for higher stability.
Add stop loss and take profit for risk management.
Consider dynamic parameters to adapt to changing markets.
Backtest across more symbols and timeframes.
Conclusion
This strategy trades price friction zones with high probability breakout potential, with pros and cons. Enhancements like dynamic optimization and risk management can make it more robust and efficient.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 500 | bars back to measure friction |
| v_input_2 | 50 | 0-100 friction level to stop trade |
| v_input_3 | -10 | pic lower than 0 to number selected above to initiate trade |
| v_input_4 | 100 | bars back to measure lowest friction |
| v_input_5_close | 0 | Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4 |
| v_input_6 | 2 | leverage |
| v_input_7 | true | enable shorts? |
Source Pine Script
/*backtest
start: 2023-08-20 00:00:00
end: 2023-09-19 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//made for 30m chart with BTCUSD or other cryptocurrency
strategy("LUBE",overlay=false )
friction=0.0
barsback=input(500,"bars back to measure friction",step=100)
flevel=input(50,"0-100 friction level to stop trade",step=2)
tlevel=input(-10,"pic lower than 0 to number selected above to initiate trade",step=2)
fl=flevel/100
tl=tlevel/100
for i = 1 to barsback
friction := if high[i] >= close and low[i] <= close
friction+(1+barsback)/(i+barsback)
else
friction
range=input(100,"bars back to measure lowest friction",step=10)
lowf = lowest(friction,range)
highf = highest(friction,range)
midf = (lowf*(1-fl)+highf*fl)
lowf2 = (lowf*(1-tl)+highf*tl)
plot(friction)
m=plot(midf[5],color=color.red)
l=plot(lowf2[5],color=color.white)
h=plot(highf[5],color=color.white)
fill(l,h,color.white)
src = input(title="Source", type=input.source, defval=close)
//FIR Filter
_fir(src) =>
(4 * src + 3 * nz(src[1]) + 2 * nz(src[2]) + nz(src[3])) / 10
fir = _fir(src)
trend = fir > fir[1]? 1:-1
//bgcolor(trend==1?color.lime:color.red,transp=50)
long=friction<lowf2[5] and trend == 1
short=friction<lowf2[5] and trend == -1
end=friction > midf[5]
keeplong=0
keeplong:=long?1:nz(keeplong[1])
keeplong:=short or end?0:keeplong
keepshort=0
keepshort:=short?1:nz(keepshort[1])
keepshort:=long or end?0:keepshort
bgcolor(keeplong==1?color.lime:keepshort==1?color.red:na,transp=50)
leverage=input(2,"leverage",step=.5)
enableshort=input(true,"enable shorts?")
barcount=0
barcount:=nz(barcount[1])+1
contracts=min(max(.000001,(strategy.equity/close)*leverage),50000)
strategy.entry("Long",strategy.long,when=long and barcount>20, qty=contracts)
strategy.close("Long",when=short or end )
strategy.entry("Short",strategy.short,when=short and enableshort==true and barcount>20, qty=contracts)
strategy.close("Short",when=(long or end) and enableshort==true)
alertcondition(keeplong==1 and keeplong[1]==0,"LONG")
alertcondition(keepshort==1 and keepshort[1]==0,"SHORT")
alertcondition((keeplong[1]==1 or keepshort[1]==1) and (keeplong==0 and keepshort==0),"CLOSE TRADE")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-20. 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/Trend-Following-Strategy-Based-on-Price-Friction-Zones.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
- 200 EMA VWAP MFI Trend Following StrategyPine Script · Trend following · 1d
- 4 EMA Trend StrategyPine Script · Trend following · 1d
- ADX MA and EMA Long Only Trend Tracking StrategyPine Script · Trend following · 1d
- ATR Dynamic Profit Target and Stop Loss StrategyPine Script · Trend following · 1d
- ATR Dynamic Trend Following and EMA Crossover Trading StrategyPine Script · Trend following · 1d
- ATR and Moving Average Crossover Hybrid StrategyPine Script · Trend following · 1h