0% found this document useful (0 votes)
25 views1 page

File 2

Uploaded by

suhailmughanni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

File 2

Uploaded by

suhailmughanni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//@version=5

strategy("Bollinger Bands with Candlestick Strategy", overlay=true)

// Input parameters
length = input.int(20, title="Bollinger Bands Length")
src = input(close, title="Source")
mult = input.float(2.0, title="Bollinger Bands Multiplier")
riskPercentage = input.float(1.0, title="Risk per Trade (%)", minval=0.1,
maxval=100)

// Bollinger Bands calculation


basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev

// Plot Bollinger Bands


plot(basis, color=color.blue, title="Basis")
p1 = plot(upper, color=color.green, title="Upper Band")
p2 = plot(lower, color=color.red, title="Lower Band")
fill(p1, p2, color=color.new(color.green, 90))

// Candlestick patterns
bullishEngulfing = ta.crossover(close, open[1]) and close > open and open <
close[1]
bearishEngulfing = ta.crossunder(close, open[1]) and close < open and open >
close[1]
doji = math.abs(open - close) / (high - low) < 0.1

// Buy and sell signals


buySignal = bullishEngulfing and close < lower
sellSignal = bearishEngulfing and close > upper

// Execute trades
if (buySignal)
strategy.entry("Buy", strategy.long, comment="Buy Signal")
if (sellSignal)
strategy.entry("Sell", strategy.short, comment="Sell Signal")

// Risk management
capital = strategy.equity
riskAmount = capital * (riskPercentage / 100)
stopLossPct = input.float(1.0, title="Stop Loss (%)", minval=0.1, maxval=10)
takeProfitPct = input.float(2.0, title="Take Profit (%)", minval=0.1, maxval=10)

if (buySignal)
strategy.exit("Exit Buy", from_entry="Buy", stop=low * (1 - stopLossPct / 100),
limit=close * (1 + takeProfitPct / 100))
if (sellSignal)
strategy.exit("Exit Sell", from_entry="Sell", stop=high * (1 + stopLossPct /
100), limit=close * (1 - takeProfitPct / 100))

// Highlight candlestick patterns


bgcolor(bullishEngulfing ? color.new(color.green, 80) : na, title="Bullish
Engulfing Highlight")
bgcolor(bearishEngulfing ? color.new(color.red, 80) : na, title="Bearish Engulfing
Highlight")
bgcolor(doji ? color.new(color.orange, 80) : na, title="Doji Highlight")

You might also like