0bps

Strategy vault / Trend following

Future Lines of Demarcation Backtest Strategy

The main idea of this strategy is to predict the future price trend by drawing future price extension lines and comparing the current price with the lines. It can make long or short positions accordingly when the…

Author
ChaoZhang
Complexity
Starter · 34 lines
Parameters
3
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

The main idea of this strategy is to predict the future price trend by drawing future price extension lines and comparing the current price with the lines. It can make long or short positions accordingly when the price is higher or lower than the extension line.

Strategy Principle

The Future Lines of Demarcation (FLD) represents the median, highest or lowest price in a certain future period. The strategy uses FLD to determine the future price movement. The principle is:

  1. Calculate the displacement period Period of FLD based on cycle length, which is the future price of Price.
  2. Compare current Close price with FLD's future price at displacement period.
    • When Close price is lower than future FLD price, it is a bullish signal.
    • When Close price is higher than future FLD price, it is a bearish signal.
  3. Make corresponding long or short positions based on bullish and bearish signals.

Advantage Analysis

The main advantages of this strategy:

  1. Using FLD to determine future trend has high accuracy.
  2. Customizable cycle parameter, adaptable to different market environments.
  3. Can choose median, highest or lowest price as FLD source, high adaptability.

Risk Analysis

The main risks of this strategy:

  1. FLD itself may fail, resulting in missing opportunities or wrong signals. Can combine other indicators.
  2. Improper cycle parameter settings may cause excessive wrong signals. Need cycle length optimization.
  3. Sudden price fluctuations causing FLD prediction failure. Can set stop loss to control risk.

Optimization Directions

The strategy can be optimized in the following aspects:

  1. Combine with other indicators to filter signals and improve accuracy, e.g. MACD, KDJ etc.
  2. Optimize cycle parameters to find best combination.
  3. Add stop loss and take profit mechanisms to control single trade loss and profit.
  4. Adjust long and short rules based on backtest results to reduce wrong signals.

Summary

The strategy judges future price trend by comparing price with displaced future price extension line. It's a typical trend following strategy. The logic is clear and easy to understand, with relatively small implementation risk. By parameter optimization and indicator combination, good strategy results can be obtained.

Parameters

NameDefaultWhat it controls
v_input_140Period
v_input_2_hl20Source: hl2 | high | low | open | close | hlc3 | hlcc4 | ohlc4
v_input_3falseTrade reverse

Source Pine Script

/*backtest
start: 2023-01-29 00:00:00
end: 2024-02-04 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
////////////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 15/02/2017
//  An FLD is a line that is plotted on the same scale as the price and is in fact the 
//  price itself displaced to the right (into the future) by (approximately) half the 
//  wavelength of the cycle for which the FLD is plotted. There are three FLD's that can be 
//  plotted for each cycle:
//    An FLD based on the median price.
//    An FLD based on the high price.
//    An FLD based on the low price.
///////////////////////////////////////////////////////////////////
strategy(title="FLD's - Future Lines of Demarcation", overlay=true)
Period = input(title="Period", defval=40)
src = input(title="Source", defval=hl2)
reverse = input(false, title="Trade reverse")
FLD = src
pos = iff(FLD[Period] < close , 1,
       iff(FLD[Period] > close, -1, nz(pos[1], 0))) 
possig = iff(reverse and pos == 1, -1,
         iff(reverse and pos == -1, 1, pos))	   
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)	   	    
barcolor(possig == -1 ? red: possig == 1 ? green : blue)
plot(FLD, title="FLD", style=line, linewidth=1, color=black, offset = Period)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-05. 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/Future-Lines-of-Demarcation-Backtest-Strategy.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