Strategy vault / Trend following
Daily Close Price Comparison Strategy
This strategy determines direction by comparing the current bar's closing price to previous bar's closing price. It is a simple trend following strategy, going long when price rises and short when price drops. No…
Overview
This strategy determines direction by comparing the current bar's closing price to previous bar's closing price. It is a simple trend following strategy, going long when price rises and short when price drops. No complex indicators are needed, just the most basic price information is used to determine trend direction.
Strategy Logic
Calculate percentage difference between current bar's closing price and previous bar's closing price.
If percentage is greater than the threshold, it indicates rising price, go long.
If percentage is less than negative threshold, it indicates falling price, go short.
Threshold is set to 0, meaning go long on any rise and short on any drop.
No stop loss or take profit logic, relying solely on trend persistence for profitability.
Advantage Analysis
Very simple and intuitive trend determination method, easy to understand and implement.
No need to compute any technical indicators, reducing resource consumption.
Only focuses on core price information, avoiding unnecessary indicator noise.
Excellent backtest results but live performance is questionable.
Risk Analysis
No stop loss exposes unlimited loss risks.
Ineffective in range-bound choppy markets, prone to being trapped.
Overfitting risks exist, live performance yet to be validated.
Pure trend following cannot lock in profits, realized profit is limited.
Optimization Directions
Add trailing stop loss for risk control.
Incorporate volatility measures to reduce whipsaws in choppy markets.
Test different period parameters for increased robustness.
Add trend determination indicators to avoid irrational price moves.
Optimize profit taking like lookback highest price to expand profit potential.
Summary
The strategy's core idea is simple but its live performance is questionable. Stronger risk control mechanisms and parameter optimization testing are needed before real application. But the basic concept is worth learning from.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | false | Price Difference Threshold |
Source Pine Script
/*backtest
start: 2023-08-17 00:00:00
end: 2023-09-16 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("Daily Close Comparison Strategy (by ChartArt)", shorttitle="CA_-_Daily_Close_Strat", overlay=false)
// ChartArt's Daily Close Comparison Strategy
//
// Version 1.0
// Idea by ChartArt on February 28, 2016.
//
// This strategy is equal to the very
// popular "ANN Strategy" coded by sirolf2009,
// but without the Artificial Neural Network (ANN).
//
// Main difference besides stripping out the ANN
// is that I use close prices instead of OHLC4 prices.
// And the default threshold is set to 0 instead of 0.0014
// with a step of 0.001 instead of 0.0001.
//
// This strategy goes long if the close of the current day
// is larger than the close price of the last day.
// If the inverse logic is true, the strategy
// goes short (last close larger current close).
//
// This simple strategy does not have any
// stop loss or take profit money management logic.
//
// List of my work:
// https://www.tradingview.com/u/ChartArt/
//
// __ __ ___ __ ___
// / ` |__| /\ |__) | /\ |__) |
// \__, | | /~~\ | \ | /~~\ | \ |
//
//
threshold = input(title="Price Difference Threshold", type=float, defval=0, step=0.001)
getDiff() =>
yesterday=security(syminfo.tickerid, 'D', close[1])
today=security(syminfo.tickerid, 'D', close)
delta=today-yesterday
percentage=delta/yesterday
closeDiff = getDiff()
buying = closeDiff > threshold ? true : closeDiff < -threshold ? false : buying[1]
hline(0, title="zero line")
bgcolor(buying ? green : red, transp=25)
plot(closeDiff, color=silver, style=area, transp=75)
plot(closeDiff, color=aqua, title="prediction")
longCondition = buying
if (longCondition)
strategy.entry("Long", strategy.long)
shortCondition = buying != true
if (shortCondition)
strategy.entry("Short", strategy.short)Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-17. 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/Daily-Close-Price-Comparison-Strategy.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