Untitled
unknown
plain_text
a month ago
3.7 kB
3
Indexable
// @version=5 indicator("Two-Candle Price Action Pattern", overlay=true) //-----------------------------------------------------------------------------// Input Parameters //----------------------------------------------------------------------------- timeframe = input.timeframe("", title="Timeframe Override", tooltip="Leave empty to use chart timeframe") rr = input.float(defval=2.0, title="Risk:Reward Ratio", minval=0.1, step=0.1) showTargets = input.bool(defval=true, title="Show Targets") //-----------------------------------------------------------------------------// Price Data //----------------------------------------------------------------------------- // Previous candle (Candle 1) high1 = high[1] low1 = low[1] open1 = open[1] close1 = close[1] // Current candle (Candle 2) high0 = high low0 = low open0 = open close0 = close //-----------------------------------------------------------------------------// Pattern Detection //----------------------------------------------------------------------------- // Determine candle colors isGreen1 = close1 > open1 isRed1 = close1 < open1 isGreen0 = close0 > open0 isRed0 = close0 < open0 // Bearish Pattern Conditions bearishPattern = isGreen1 and isRed0 and high0 > high1 and close0 < open1 // Bullish Pattern Conditions (reverse of bearish) bullishPattern = isRed1 and isGreen0 and low0 < low1 and close0 > open1 //-----------------------------------------------------------------------------// Trade Levels Calculation //----------------------------------------------------------------------------- // Bearish Pattern Levels bearishEntryLevel = close0 bearishStopLevel = high0 // Fixed stop above candle 2 high for bearish pattern bearishRisk = bearishStopLevel - bearishEntryLevel bearishTargetLevel = bearishEntryLevel - (bearishRisk * rr) // Bullish Pattern Levels bullishEntryLevel = close0 bullishStopLevel = low0 // Fixed stop below candle 2 low for bullish pattern bullishRisk = bullishEntryLevel - bullishStopLevel bullishTargetLevel = bullishEntryLevel + (bullishRisk * rr) //-----------------------------------------------------------------------------// Visual Signals - SIGNALS REMOVED //----------------------------------------------------------------------------- //-----------------------------------------------------------------------------// Trade Levels Visualization //----------------------------------------------------------------------------- // Draw bearish pattern levels if bearishPattern and showTargets line.new(x1=bar_index, y1=bearishStopLevel, x2=bar_index + 2, y2=bearishStopLevel, color=color.red, width=2) line.new(x1=bar_index, y1=bearishEntryLevel, x2=bar_index + 2, y2=bearishEntryLevel, color=color.blue, width=2) line.new(x1=bar_index, y1=bearishTargetLevel, x2=bar_index + 2, y2=bearishTargetLevel, color=color.green, width=2) // Draw bullish pattern levels if bullishPattern and showTargets line.new(x1=bar_index, y1=bullishStopLevel, x2=bar_index + 2, y2=bullishStopLevel, color=color.red, width=2) line.new(x1=bar_index, y1=bullishEntryLevel, x2=bar_index + 2, y2=bullishEntryLevel, color=color.blue, width=2) line.new(x1=bar_index, y1=bullishTargetLevel, x2=bar_index + 2, y2=bullishTargetLevel, color=color.green, width=2) //-----------------------------------------------------------------------------// Alerts //----------------------------------------------------------------------------- alertcondition(bearishPattern, title="Bearish Pattern Detected", message="Bearish Two-Candle Pattern: SELL") alertcondition(bullishPattern, title="Bullish Pattern Detected", message="Bullish Two-Candle Pattern: BUY")
Editor is loading...
Leave a Comment