Create A Pine ScriptIndicator that Highlight Trade when Shooting Star or Pin Bar (Bearish pin bar: A long upper tail that is three or more times longer than the body. It appears after a solid upward movement or at the end of an uptrend.) formed with Higher Volume than last 5 Candle and Place Sell Order on Next Candle of CandleStick Pattern at the low of CandleStick Pattern if low is Crossed first and if High Broke first of Pattern then Trade is Invalid, and cancel that. When Place Order Put Stop Loss above 2% of Daily ATR Pin Bar or Shooting Star and 1:2 Risk and Reward, Also Make Sure CandleStick Pattern has High above than last 10 Candle to Consider as Trend Reversal (Formula to Calculate: isShootingStar = showShootingStar and bodySize < (high - low) * shootingStarBodyRatio and upperWick > lowerWick * shootingStarWickMultiplier and volume == maxVolume
) Make Sure that Trend is Bearish in Higher Time Frame
Assistant
pine
//@version=5
strategy("Shooting Star / Bearish Pin Bar Strategy", overlay=true, max_bars_back=500)
// Inputs
shootingStarBodyRatio = input.float(title="Shooting Star Body Ratio", defval=0.3, minval=0, step=0.1)
shootingStarWickMultiplier = input.float(title="Shooting Star Wick Multiplier", defval=3, minval=1, step=0.1)
htf = input.timeframe(title="Higher Timeframe", defval="D") // Higher Timeframe
atrLength = input.int(title="ATR Length", defval=14, minval=1)
riskRewardRatio = input.float(title="Risk Reward Ratio", defval=2.0, minval=1)
showShootingStar = input.bool(title="Show Shooting Star", defval=true)
// Calculations
bodySize = math.abs(close - open)
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
totalRange = high - low
// Volume higher than last 5 candles
maxVolumeLast5 = ta.highest(volume[1], 5)
volumeHigherThanLast5 = volume > maxVolumeLast5
// High higher than last 10 candles
maxHighLast10 = ta.highest(high[1], 10)
highHigherThanLast10 = high > maxHighLast10
// Higher Timeframe Trend is Bearish
htf_close = request.security(syminfo.tickerid, htf, close)
htf_ma = request.security(syminfo.tickerid, htf, ta.sma(close, 20))
isBearishTrendHTF = htf_close < htf_ma
// Shooting Star Condition
isShootingStar = showShootingStar and bodySize < totalRange * shootingStarBodyRatio and upperWick > lowerWick * shootingStarWickMultiplier and volumeHigherThanLast5
// Final Signal
isSignal = isShootingStar and highHigherThanLast10 and isBearishTrendHTF
// Variables to Track Trade
var bool orderPlaced = false
var float patternHigh = na
var float patternLow = na
var float tradeStopLoss = na
var float tradeTakeProfit = na
// When Signal Occurs
if isSignal
patternHigh := high
patternLow := low
daily_atr = request.security(syminfo.tickerid, 'D', ta.atr(atrLength))
stopLoss = patternHigh + daily_atr * 0.02
riskPerShare = stopLoss - patternLow
takeProfit = patternLow - (riskPerShare * riskRewardRatio)
// Place Stop Order to Enter Short
strategy.entry(id="Short", direction=strategy.short, qty=100, stop=patternLow)
// Set Stop Loss and Take Profit
strategy.exit("Exit Short", from_entry="Short", stop=stopLoss, limit=takeProfit)
orderPlaced := true
// Check for Trade Invalidation
if orderPlaced and strategy.position_size == 0
if high > patternHigh
strategy.cancel(id="Short")
patternHigh := na
patternLow := na
orderPlaced := false
// Reset Parameters When Trade is Entered or Cancelled
if strategy.position_size != 0
tradeStopLoss := stopLoss
tradeTakeProfit := takeProfit
orderPlaced := false
patternHigh := na
patternLow := na
else if not orderPlaced
tradeStopLoss := na
tradeTakeProfit := na
// Plotting Signals
plotshape(isSignal, title="Shooting Star", style=shape.labeldown, location=location.abovebar, color=color.red, text="Shooting Star")
// Plot Stop Loss and Take Profit Levels
plot(tradeStopLoss, color=color.red, style=plot.style_linebr, linewidth=1, title="Stop Loss")
plot(tradeTakeProfit, color=color.green, style=plot.style_linebr, linewidth=1, title="Take Profit")
This Pine Script strategy identifies Shooting Star or Bearish Pin Bar patterns that meet specific criteria:
The candle has a long upper wick at least three times longer than the body.
The body size is less than a certain ratio of the total range.
Volume is higher than the previous 5 candles.
The high is higher than the last 10 candles, indicating a potential trend reversal.
Confirms that the higher timeframe trend is bearish.
When a valid pattern is detected, the strategy:
Places a sell stop order at the low of the pattern.
Sets a stop loss above the pattern high plus 2% of the daily ATR.
Sets a take profit level using a 1:2 risk-reward ratio.
Cancels the order if the high of the pattern is breached before entry.
The strategy plots signals on the chart and visualizes the stop loss and take profit levels.