//version=5 indicator("Swing High/Low Entry Strategy with SL/TP", overlay=true)
// Input for the time range (10:30am to 16:45pm UTC-5) startTime = timestamp("GMT-5", year, month, dayofmonth, 10, 30) endTime = timestamp("GMT-5", year, month, dayofmonth, 16, 45)
// Variables to store the highest and lowest swing points within a specific time range var float swingHigh = na var float swingLow = na
// Lookback period for calculating swing high and low lookbackPeriod = 10
// Calculate swing high and low between the specified time period if (time >= startTime and time <= endTime) swingHigh := na swingLow := na else swingHigh := ta.highest(high, lookbackPeriod) // Highest high in the last 10 bars swingLow := ta.lowest(low, lookbackPeriod) // Lowest low in the last 10 bars
// Detect when swing high is broken (swept) sweepHigh = not na(swingHigh) and high > swingHigh
// Bearish Order Block Detection (simple method using previous bearish candle) bearishOrderBlock = close[1] > open[1] and close < open
// Buy and Sell logic based on swing high being swept and a bearish order block detected buyCondition = sweepHigh and bearishOrderBlock sellCondition = sweepHigh and bearishOrderBlock
// Stop loss and take profit logic SL_buy = swingHigh SL_sell = swingLow TP_buy = swingLow TP_sell = swingHigh
// Plot Buy and Sell Signals with labels and lines for SL and TP if (buyCondition) label.new(bar_index, low, text="BUY", style=label.style_label_up, color=color.green, textcolor=color.white, size=size.small) line.new(x1=bar_index, y1=SL_buy, x2=bar_index + 10, y2=SL_buy, color=color.red, width=2, extend=extend.right) line.new(x1=bar_index, y1=TP_buy, x2=bar_index + 10, y2=TP_buy, color=color.green, width=2, extend=extend.right)