IND

283
//version=5
strategy("Prajapati", overlay=true)

// Input Settings
riskPercent = input.float(3, title="Risk Percentage per Trade (%)", minval=0.1, step=0.1)
rewardRatio = input.float(3, title="Risk-Reward Ratio", minval=1.0)
capital = input.float(10000, title="Starting Capital ($)", minval=1)
atrMultiplier = input.float(1.5, title="ATR Multiplier for Stop Loss")
show_TT = input.bool(true, title = "Show T and TT")
show_sma = input.bool(true, title = "Show SMA")

// ATR Calculation for Volatility-based Stop-Loss
atrLength = input.int(14, title="ATR Length")
atrValue = ta.atr(atrLength)
stopLossDistance = atrValue * atrMultiplier
takeProfitDistance = stopLossDistance * rewardRatio


// Simple Moving Averages
fastMA = ta.sma(close, 13)
slowMA = ta.sma(close, 5)

// Entry and Exit Conditions using Simple Moving Averages
longCondition = ta.crossover(fastMA, slowMA)
shortCondition = ta.crossunder(fastMA, slowMA)

// Candlestick Patterns Functions
isBullishEngulfing() => (open[1] > close[1] and close > open and close >= open[1] and close[1] >= open and close - open > open[1] - close[1])
isBearishEngulfing() => (close[1] > open[1] and open > close and open >= close[1] and open[1] >= close and open - close > close[1] - open[1])
isHammer() => (((high - low) > 3 * (open - close)) and ((close - low) / (.001 + high - low) > 0.6) and ((open - low) / (.001 + high - low) > 0.6))
isInvertedHammer() => (((high - low) > 3 * (open - close)) and ((high - close) / (.001 + high - low) > 0.6) and ((high - open) / (.001 + high - low) > 0.6))
isBullishHarami() => (open[1] > close[1] and close > open and close <= open[1] and close[1] <= open and close - open < open[1] - close[1])
isBearishHarami() => (close[1] > open[1] and open > close and open <= close[1] and open[1] <= close and open - close < close[1] - open[1])

// Color Bars for Candlestick Patterns
barcolor(isBullishEngulfing() ? color.rgb(0, 102, 255) : na)
barcolor(isHammer() ? (#1f0cef) : na)
barcolor(isBullishHarami() ? color.rgb(0, 93, 214) : na)
barcolor(isBearishEngulfing() ? color.rgb(255, 196, 0) : na)
barcolor(isBearishHarami() ? color.rgb(251, 255, 0) : na)
barcolor(isInvertedHammer() ? color.rgb(247, 0, 247) : na)

// Calculate SMA for Visualization
sma_22 = ta.sma(close, 22)
lineColor = close > sma_22 ? color.black : color.black
plot(show_sma ? sma_22 : na, color=lineColor, linewidth=1)

// Determine T and TT Labels based on Conditions
candleCrossG = ta.crossover(close, sma_22)
candleCrossR = ta.crossunder(close, sma_22)


// Place Trades Based on Conditions
if (longCondition)
strategy.entry("BUY ", strategy.long)
strategy.exit("Take Profit", from_entry="Long", limit=close + takeProfitDistance, stop=close - stopLossDistance)

if (shortCondition)
strategy.entry("SELL", strategy.short)
strategy.exit("Take Profit", from_entry="Short", limit=close - takeProfitDistance, stop=close + stopLossDistance)

// Plotting Stop Loss and Take Profit Levels for Visualization
plot(longCondition ? close - stopLossDistance : na, color=na, title="Stop Loss", linewidth=1, style=plot.style_line)
plot(longCondition ? close + takeProfitDistance : na, color=na, title="Take Profit", linewidth=1, style=plot.style_line)
plot(shortCondition ? close + stopLossDistance : na, color=na, title="Stop Loss (Short)", linewidth=1, style=plot.style_line)
plot(shortCondition ? close - takeProfitDistance : na, color=na, title="Take Profit (Short)", linewidth=1, style=plot.style_line)

Wyłączenie odpowiedzialności

Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.