0bps

Strategy vault / Machine learning

Interactive Model Based Candlestick Trading Strategy

This strategy generates buy and sell signals based on candlestick patterns and interactive models. It mainly utilizes breakouts of support and resistance levels along with certain candlestick formations to assist in…

Author
ChaoZhang
Complexity
Starter · 36 lines
Parameters
2
Backtest bar
1m · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This strategy generates buy and sell signals based on candlestick patterns and interactive models. It mainly utilizes breakouts of support and resistance levels along with certain candlestick formations to assist in decision making.

Strategy Logic

The strategy primarily identifies the following candlestick patterns:

  1. Bullish Marubozu: Close higher than open with short real body
  2. Inverted Hammer: Open near high and close near low
  3. Doji Star: Previous candle crosses current doji candle

In conjunction with pattern recognition, support and resistance levels are set. The specific logic is:

  1. When a Bullish Marubozu appears above resistance level, a buy signal is generated
  2. When an Inverted Hammer appears below support level, a sell signal is triggered

This combination filtering helps avoid false signals and makes the trading decisions more reliable.

Advantage Analysis

The advantages of this strategy are:

  1. Combines chart patterns and indicators for more robust signals
  2. Support/Resistance levels avoid unnecessary whipsaws
  3. Candlestick patterns are simple to understand and implement
  4. Customizable parameters suit different market environments

Overall, the strategy is relatively simple and practical for testing ideas and assisting manual trading.

Risk Analysis

There are also some risks:

  1. Candlestick patterns can be misleading resulting in bad signals
  2. Poor support/resistance levels negatively impact performance
  3. Unable to handle black swan events and huge volatility
  4. Insufficient backtest data leading to overestimated results

Mitigations mainly involve strict parameter checking, support/resistance tuning, and incorporating stop losses to control risk. Additionally, extensive historical data backtesting is required to properly evaluate the actual strategy performance.

Enhancement Opportunities

Some ways the strategy can be enhanced:

  1. Incorporate more candlestick pattern detections for more trade signals
  2. Optimize support/resistance calculation methods to better fit market trends
  3. Add secondary indicators like moving average distance, volume changes to supplement decisions
  4. Introduce machine learning to autonomously determine chart pattern features

These improvements can help automate strategy tuning and make trade decisions more intelligent to handle increasingly complex markets.

Conclusion

Overall this is a simple, practical strategy well-suited for individual traders to test ideas and assist with decisions. Trading signals are generated by combining candlestick patterns and support/resistance analysis to effectively filter out false signals. With some enhancements, this strategy can become a relatively reliable quantitative system.

Parameters

NameDefaultWhat it controls
v_input_1100Support Level
v_input_2200Resistance Level

Source Pine Script

/*backtest
start: 2023-12-13 00:00:00
end: 2023-12-20 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Candlestick Pattern Strategy", overlay=true)

// Input for support and resistance levels
supportLevel = input(100, title="Support Level")
resistanceLevel = input(200, title="Resistance Level")

// Detecting Candlestick Patterns
isDoji = close == open
isPressure = close < open and open - close > close - open
isInvertedHammer = close > open and low == (close < open ? close : open) and close - open < 0.1 * (high - low)
isHammer = close > open and close - open > 0.6 * (high - low)

// Buy and Sell Conditions
buyCondition = isHammer and close > resistanceLevel
sellCondition = isInvertedHammer and close < supportLevel

// Strategy Logic
strategy.entry("Buy", strategy.long, when = buyCondition)
strategy.close("Buy", when = sellCondition)

// Plot Buy and Sell signals on the chart
plotshape(series=buyCondition, title="Buy Signal", color=color.green, style=shape.triangleup, location=location.belowbar)
plotshape(series=sellCondition, title="Sell Signal", color=color.red, style=shape.triangledown, location=location.abovebar)

// Plot Support and Resistance levels
plot(supportLevel, color=color.green, title="Support Level")
plot(resistanceLevel, color=color.red, title="Resistance Level")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-21. 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/Interactive-Model-Based-Candlestick-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