OPEN-SOURCE SCRIPT

FX MAN PRO

127
//version=5
indicator(title="FCB Signals with SMA, Momentum & Stochastic", shorttitle="FCB+AllFilters+Stoch", overlay=true)

// ---------- Inputs ----------
Pattern = input.int(1, "Pattern Length", minval=1)
showSignals = input.bool(true, "Show Buy/Sell Signals")
signalOffset = input.int(0, "Signal Offset", minval=-5, maxval=5)
smaFastLength = input.int(7, "SMA Fast")
smaSlowLength = input.int(21, "SMA Slow")
momentumLength = input.int(10, "Momentum Length")

// ---------- Stochastic Inputs ----------
stochKLength = input.int(14, "Stoch K Length")
stochDLength = input.int(3, "Stoch D Length")
stochSmooth = input.int(3, "Stoch Smooth")
stochOverbought = input.int(80, "Overbought Level")
stochOversold = input.int(20, "Oversold Level")

// ---------- Fractal Functions ----------
fractalUp(pattern) =>
p = high[pattern + 1]
okl = 1
okr = 1
res = 0.0
for i = pattern to 1
okl := high < high[i + 1] and okl == 1 ? 1 : 0
for i = pattern + 2 to pattern * 2 + 1
okr := high < high[i - 1] and okr == 1 ? 1 : 0
res := okl == 1 and okr == 1 ? p : res[1]
res

fractalDn(pattern) =>
p = low[pattern + 1]
okl = 1
okr = 1
res = 0.0
for i = pattern to 1
okl := low > low[i + 1] and okl == 1 ? 1 : 0
for i = pattern + 2 to pattern * 2 + 1
okr := low > low[i - 1] and okr == 1 ? 1 : 0
res := okl == 1 and okr == 1 ? p : res[1]
res

// ---------- Compute ----------
xUpper = fractalUp(Pattern)
xLower = fractalDn(Pattern)

// ---------- Hide FCB ----------
plot(xUpper, color=na, title="FCB Up")
plot(xLower, color=na, title="FCB Down")

// ---------- Candle Analysis ----------
body = math.abs(close - open)
shadowTop = high - math.max(open, close)
shadowBot = math.min(open, close) - low
strongBody = body > (shadowTop + shadowBot)

isGreen = close > open
isRed = close < open

// ---------- SMA ----------
smaFast = ta.sma(close, smaFastLength)
smaSlow = ta.sma(close, smaSlowLength)

// ---------- Momentum ----------
momentumValue = ta.mom(close, momentumLength)

// ---------- Stochastic ----------
kLine = ta.sma(ta.stoch(close, high, low, stochKLength), stochSmooth)
dLine = ta.sma(kLine, stochDLength)

// ---------- Stochastic Direction ----------
kUp = kLine > kLine[1]
dUp = dLine > dLine[1]
kDown = kLine < kLine[1]
dDown = dLine < dLine[1]

// ---------- Check Stochastic Neutral ----------
inNeutral = (kLine < stochOverbought and kLine > stochOversold) and (dLine < stochOverbought and dLine > stochOversold)

// ---------- First Candle Signal Logic ----------
var bool buyActive = false
var bool sellActive = false

buyCond = close > xUpper and strongBody and isGreen and smaFast > smaSlow and momentumValue > momentumValue[1] and kUp and dUp and inNeutral
sellCond = close < xLower and strongBody and isRed and smaFast < smaSlow and momentumValue < momentumValue[1] and kDown and dDown and inNeutral

buySignal = buyCond and not buyActive
sellSignal = sellCond and not sellActive

buyActive := buyCond ? true : not buyCond ? false : buyActive
sellActive := sellCond ? true : not sellCond ? false : sellActive

// ---------- Plot Signals with golden text ----------
plotshape(showSignals and buySignal,
title="Buy Signal",
style=shape.triangleup,
location=location.belowbar,
color=color.green,
size=size.tiny,
text="BUY",
textcolor=color.new(color.yellow, 0), // طلایی
offset=signalOffset)

plotshape(showSignals and sellSignal,
title="Sell Signal",
style=shape.triangledown,
location=location.abovebar,
color=color.red,
size=size.tiny,
text="SELL",
textcolor=color.new(color.yellow, 0), // طلایی
offset=signalOffset)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.