Created
March 9, 2025 14:22
-
-
Save feliperazeek/23d2f2df009980815b0757c4db1b6064 to your computer and use it in GitHub Desktop.
NakInvest - PFR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=5 | |
strategy("NakInvest - PFR Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10) | |
// === INPUTS === | |
shortEmaLength = input.int(9, title="Short EMA Length") | |
longEmaLength = input.int(100, title="Long EMA Length") | |
stochLength = input.int(8, title="Stochastic Length") | |
stochK = input.int(3, title="Stoch %K Smoothing") | |
stochD = input.int(3, title="Stoch %D Smoothing") | |
rsiLength = input.int(8, title="RSI Length") | |
volumeThreshold = input.float(1.5, title="Volume Threshold Multiplier") | |
profitMultiplier = input.float(2.0, title="Profit Target Multiplier") | |
supportLookback = input.int(5, title="Support Zone Lookback Candles") | |
requireStochConfirm = input.bool(true, title="Require Stochastic Confirmation") | |
requireRsiConfirm = input.bool(true, title="Require RSI Confirmation") | |
requireTrendConfirm = input.bool(true, title="Require Trend Confirmation") | |
requireVolumeConfirm = input.bool(true, title="Require Volume Confirmation") | |
minScoreRequired = input.int(2, title="Minimum Confirmations for Entry") | |
// === INDICATORS === | |
shortEma = ta.ema(close, shortEmaLength) | |
longEma = ta.ema(close, longEmaLength) | |
rsi = ta.rsi(close, rsiLength) | |
stoK = ta.sma(ta.stoch(close, high, low, stochLength), stochK) | |
stoD = ta.sma(stoK, stochD) | |
// === PFR CONDITIONS === | |
reversalBody = math.abs(close - open) | |
prevBody1 = math.abs(close[1] - open[1]) | |
prevBody2 = math.abs(close[2] - open[2]) | |
bullishCandle = close > open | |
bearishCandle = close < open | |
bullishPFR = bullishCandle and low < ta.lowest(low[1], 2) and high > ta.highest(high[1], 2) and close > close[1] and | |
reversalBody > prevBody1 and reversalBody > prevBody2 | |
bearishPFR = bearishCandle and high > ta.highest(high[1], 2) and low < ta.lowest(low[1], 2) and close < close[1] and | |
reversalBody > prevBody1 and reversalBody > prevBody2 | |
// === CONFIRMATIONS === | |
stochConfirm = not requireStochConfirm or (stoK < 30 and ta.crossover(stoK, stoD)) | |
rsiConfirm = not requireRsiConfirm or (rsi < 30) | |
trendConfirm = not requireTrendConfirm or (shortEma > longEma) | |
volumeConfirm = not requireVolumeConfirm or (volume < ta.sma(volume, 20) * volumeThreshold) | |
// === SIGNAL STRENGTH SCORE === | |
strengthScore = (stochConfirm ? 1 : 0) + (rsiConfirm ? 1 : 0) + (trendConfirm ? 1 : 0) + (volumeConfirm ? 1 : 0) | |
// === STOP LOSS BASED ON SUPPORT ZONE === | |
longStopLoss = ta.lowest(low, supportLookback) | |
shortStopLoss = ta.highest(high, supportLookback) | |
// === TAKE PROFIT BASED ON MULTIPLIER === | |
longProfitTarget = close + (close - longStopLoss) * profitMultiplier | |
shortProfitTarget = close - (shortStopLoss - close) * profitMultiplier | |
// === ENTRY CONDITIONS === | |
longCondition = bullishPFR and strengthScore >= minScoreRequired and trendConfirm | |
shortCondition = bearishPFR and strengthScore >= minScoreRequired and not trendConfirm | |
if longCondition | |
strategy.entry("Long", strategy.long) | |
strategy.exit("Long Exit", from_entry="Long", stop=longStopLoss, limit=longProfitTarget) | |
// label.new(x=bar_index, y=low - ta.atr(14), text="🟢 LONG ENTRY\nSL: " + str.tostring(longStopLoss) + " TP: " + str.tostring(longProfitTarget) + " Score: " + str.tostring(strengthScore), color=color.green, style=label.style_label_down, textcolor=color.white) | |
label.new(x=bar_index, y=low - ta.atr(5000), color=color.green, style=label.style_diamond, textcolor=color.white) | |
if shortCondition | |
strategy.entry("Short", strategy.short) | |
strategy.exit("Short Exit", from_entry="Short", stop=shortStopLoss, limit=shortProfitTarget) | |
label.new(x=bar_index, y=high + ta.atr(14), text="🔴 SHORT ENTRY\nSL: " + str.tostring(shortStopLoss) + " TP: " + str.tostring(shortProfitTarget) + " Score: " + str.tostring(strengthScore), color=color.red, style=label.style_label_up, textcolor=color.white) | |
// === PLOT ENTRY AND EXIT MARKERS === | |
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Long Entry", text="BUY") | |
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Short Entry", text="SELL") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment