// --- Support and Resistance Calculation --- lookback_support_resistance = 50 support_level = ta.lowest(low, lookback_support_resistance) resistance_level = ta.highest(high, lookback_support_resistance)
// --- Candle Stop Function --- is_candle_stop(trend) => body = math.abs(close - open) upper_shadow = high - math.max(open, close) lower_shadow = math.min(open, close) - low if trend == "up" lower_shadow >= 1.5 * body and upper_shadow < body and close > open and math.abs(ema7 - close) < body else if trend == "down" upper_shadow >= 1.5 * body and lower_shadow < body and close < open and math.abs(ema7 - close) < body else false
take_profit_long := profit_percent_long >= 4 and risk_reward_long >= 2 // Assign value to take_profit_long stop_loss_hit_long := close <= stop_loss_price // Assign value to stop_loss_hit_long take_profit_short := profit_percent_short >= 4 and risk_reward_short >= 2 // Assign value to take_profit_short stop_loss_hit_short := close >= stop_loss_price // Assign value to stop_loss_hit_short
if (trend == "up" and (take_profit_long or stop_loss_hit_long)) or (trend == "down" and (take_profit_short or stop_loss_hit_short)) if trend == "up" strategy.close("Long") else strategy.close("Short") position := 0 entry_price := 0.0 breakout_detected := false