OPEN-SOURCE SCRIPT

Consecutive Candles Strategy

Entry Conditions:
Long Entry:
Requires two consecutive green candles (where close > open)
The second green candle must be a strong candle (not a doji)
A strong candle is defined by its body being at least 50% of its total range (adjustable via minBodyToShadowRatio)
Short Entry:
Requires two consecutive red candles (where close < open)
The second red candle must be a strong candle (not a doji)
Same body-to-shadow ratio requirement as long entries
Exit Conditions:
All positions (both long and short) are automatically closed at the next candle's close
For example:
If you enter a long position on candle #1
The position will be closed at the end of candle #2
Trade Management:
Cooldown Period:
After each trade exits, there's a 2-candle waiting period
No new trades can be entered during this cooldown
This helps avoid overtrading and gives the market time to settle
Candle Strength Measurement:
bodySize = math.abs(close - open): Measures the actual body size of the candle
totalRange = high - low: Measures the total range including shadows
bodyToShadowRatio = bodySize / totalRange: Calculates what portion of the candle is body
A candle is considered "strong" if its body is at least 50% of its total range
Visual Indicators:
Green triangles below bars: Show long entry signals
Red triangles above bars: Show short entry signals
Yellow dots: Show the cooldown period countdown
Blue dots: Show the body-to-shadow ratio of current candle
Example Trade Sequence:

Market shows two green candles, second one is strong
Strategy enters a long position
Position is closed at the end of the next candle
Strategy waits for 2 candles (cooldown)
Only then looks for new trade opportunities
You can adjust the strategy's sensitivity by modifying:

minBodyToShadowRatio: Higher values (closer to 1.0) require stronger candles
Currently set to 0.5 (50%), meaning the candle body must be at least half of the total candle range
Candlestick analysisChart patterns

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明