0bps

Strategy vault / Trend following

Elliott Wave Theory 4 9 Impulse Wave Automatic Detection Trading Strategy

This strategy is based on the Elliott Wave Theory and attempts to automatically detect impulse waves. It defines an upward impulse wave by looking for a combination of 4 consecutive up-closing candles where the…

Pine ScriptTrend following
Author
ChaoZhang
Complexity
Starter · 51 lines
Parameters
2
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is based on the Elliott Wave Theory and attempts to automatically detect impulse waves. It defines an upward impulse wave by looking for a combination of 4 consecutive up-closing candles where the current close is higher than the close 9 days ago; a downward impulse wave is defined using the opposite logic. Once an impulse wave is detected, it generates buy or sell signals and reverses the position, with the stop loss set at the low or high of the signal candle. Since impulse waves are usually accompanied by rapid movements, this stop loss method should yield positive results. Additionally, the accumulation of green or red triangles before the start of a strong trend often indicates good entry points in a calm market before the trend initiation.

Strategy Principles

  1. Define the number of periods for consecutive up/down closes as consclos (default 3) and the number of days to compare the current close with the close N days ago as daysago (default 9).
  2. Use variables long_cc and short_cc to record whether the most recent consclos candles have consecutively closed up/down. The value is 1 if consecutive, otherwise 0.
  3. Compare the current close with the close daysago days ago. If the current price is higher/lower, long_daysago/short_daysago is true.
  4. Combine long_cc, short_cc with long_daysago, short_daysago to get the final long and short signals.
  5. Plot green and red triangles corresponding to the long and short signals.
  6. If a long signal appears and there is no current long position, go long and set the stop loss price to the low of the signal candle.
  7. If a short signal appears and there is no current short position, go short and set the stop loss price to the high of the signal candle.

Advantage Analysis

  1. Automatically identifies impulse waves in Elliott Wave Theory, reducing the influence of subjective analysis.
  2. Impulse waves are often accompanied by strong trends, which this strategy can capture.
  3. The stop loss placement is consistent with the trend direction, improving the risk-reward ratio.
  4. Can discover potential entry opportunities before trend initiation.
  5. Parameters are adjustable, making it widely applicable.

Risk Analysis

  1. There may be deviations in the interpretation of wave theory, leading to misjudgments.
  2. The duration of trends is difficult to predict, and the stop loss may be set too close, resulting in being stopped out.
  3. May be ineffective in sideways markets, generating frequent trades.
  4. Lacks consideration of position sizing and money management.

Optimization Directions

  1. Optimize the configuration of consclos and daysago parameters through backtesting to improve signal accuracy.
  2. Introduce trend confirmation indicators such as MACD to reduce noise.
  3. Consider adding trailing stops to better protect profits.
  4. When the trend is not yet clear, start with a small position and add to it once the trend becomes clear.
  5. Control position sizing and risk, such as limiting the percentage of funds per trade and setting a maximum drawdown.

Summary

This strategy is based on the classic Elliott Wave Theory and can capture strong trend movements with some applicability and profit potential. However, the subjectivity of wave theory itself and the definition of impulse waves may affect the strategy's performance. In practical application, attention should be paid to parameter optimization, position management, reducing trading frequency, etc. By introducing trend confirmation indicators, trailing stops, gradual position building, and other means, the performance and stability of this strategy can be further improved.

Parameters

NameDefaultWhat it controls
v_input_int_13Consecutive close
v_input_int_29Days ago

Source Pine Script

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

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Smollet

//@version=5
strategy("LW: 4-9 indicator", overlay = true)

consclos = input.int(3, "Consecutive close")
daysago = input.int(9, "Days ago")


var int long_cc = 0
var int short_cc = 0

long_cc := 1
short_cc := 1

for i = 1 to consclos
    long_cc := close[i-1] > close[i] ? long_cc*1 : long_cc*0
    short_cc := close[i-1] < close[i] ? short_cc*1 : short_cc*0

long_daysago = close > close[daysago]
short_daysago = close < close[daysago]



long = long_cc ==1 and long_daysago
short = short_cc ==1 and short_daysago


plotshape(long, style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(short, style=shape.triangledown, location=location.abovebar, color=color.red)



//Strategy code
if long and strategy.position_size <= 0
    strategy.entry("Long", strategy.long)
    strategy.exit("Long SL", "Long", stop = low)

if short and strategy.position_size >= 0
    strategy.entry("Short", strategy.short)
    strategy.exit("Short SL", "Short", stop = high)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-04-26. 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/Elliott-Wave-Theory-4-9-Impulse-Wave-Automatic-Detection-Trading-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