PHP Code:
//@version=6
indicator(title = 'Master Trend BUY&SELL', shorttitle = '.', overlay = true)
// Color variables
upTrendColor = color.green
neutralColor = #0e0e0e
downTrendColor = color.red
fillColor = color.rgb(12, 12, 12, 70) // Color between lines
yellowColor = color.rgb(230, 214, 2)
blackTextColor = color.rgb(0, 0, 0)
blueColor = color.rgb(233, 217, 0)
whiteTextColor = color.rgb(7, 7, 7)
greenColor = color.green
redColor = color.red
// Source
source = input(defval = close, title = 'Source')
// Sampling Period
period = input.int(defval = 50, minval = 1, title = 'Sampling Period')
// Range Multiplier
multiplier = input.float(defval = 3.0, minval = 0.1, title = 'Range Multiplier')
// Take Profit Settings
takeProfitPips = input.float(defval = 600.0, title = 'Take Profit (in pips)')
// Smooth Average Range
smoothRange(x, t, m) =>
adjustedPeriod = t * 2 - 1
avgRange = ta.ema(math.abs(x - x[1]), t)
smoothRange = ta.ema(avgRange, adjustedPeriod) * m
smoothRange
smoothedRange = smoothRange(source, period, multiplier)
// Trend Filter
trendFilter(x, r) =>
filtered = x
filtered := x > nz(filtered[1]) ? x - r < nz(filtered[1]) ? nz(filtered[1]) : x - r : x + r > nz(filtered[1]) ? nz(filtered[1]) : x + r
filtered
filter = trendFilter(source, smoothedRange)
// Filter Direction
upCount = 0.0
upCount := filter > filter[1] ? nz(upCount[1]) + 1 : filter < filter[1] ? 0 : nz(upCount[1])
downCount = 0.0
downCount := filter < filter[1] ? nz(downCount[1]) + 1 : filter > filter[1] ? 0 : nz(downCount[1])
// Colors
filterColor = upCount > 0 ? upTrendColor : downCount > 0 ? downTrendColor : neutralColor
// Double Line Design
lineOffset = smoothedRange * 0.1
upperLinePlot = plot(filter + lineOffset, color = filterColor, linewidth = 1, title = 'Yükseliş Trend Çizgisi')
lowerLinePlot = plot(filter - lineOffset, color = filterColor, linewidth = 1, title = 'Düşüş Trend Çizgisi')
//fill(upperLinePlot, lowerLinePlot, color = fillColor, title = 'Trend Fill')
// Break Outs
longCondition = bool(na)
shortCondition = bool(na)
longCondition := source > filter and source > source[1] and upCount > 0 or source > filter and source < source[1] and upCount > 0
shortCondition := source < filter and source < source[1] and downCount > 0 or source < filter and source > source[1] and downCount > 0
initialCondition = 0
initialCondition := longCondition ? 1 : shortCondition ? -1 : initialCondition[1]
longSignal = longCondition and initialCondition[1] == -1
shortSignal = shortCondition and initialCondition[1] == 1
// Take Profit Logic
var float entryPriceBuy = na
var float entryPriceSell = na
takeProfitSignalBuy = false
takeProfitSignalSell = false
if longSignal
entryPriceBuy := source
entryPriceBuy
if not na(entryPriceBuy) and source >= entryPriceBuy + takeProfitPips * syminfo.mintick
takeProfitSignalBuy := true
entryPriceBuy := na
entryPriceBuy
if shortSignal
entryPriceSell := source
entryPriceSell
if not na(entryPriceSell) and source <= entryPriceSell - takeProfitPips * syminfo.mintick
takeProfitSignalSell := true
entryPriceSell := na
entryPriceSell
// Alerts and Signals
plotshape(longSignal, title = 'Smart Buy Signal', text = 'Al', textcolor = color.white, style = shape.labelup, size = size.small, location = location.belowbar, color = greenColor)
plotshape(shortSignal, title = 'Smart Sell Signal', text = 'Sat', textcolor = color.white, style = shape.labeldown, size = size.small, location = location.abovebar, color = redColor)
//plotshape(takeProfitSignalBuy, title = 'Book Profit Buy', text = 'Book Profit', textcolor = blackTextColor, style = shape.labeldown, size = size.small, location = location.abovebar, color = yellowColor)
//plotshape(takeProfitSignalSell, title = 'Book Profit Sell', text = 'Book Profit', textcolor = whiteTextColor, style = shape.labelup, size = size.small, location = location.belowbar, color = blueColor)
/////
// === Inputs ===
fairLen = input.int(50, "Fair Value EMA Length")
zLen = input.int(100, "Z-Score Lookback Length")
zThreshold = input.float(3.0, "Z-Score Threshold")
src = input.source(close, "Source")
rsiLen = input.int(14, "RSI Length")
rsiEmaLen = input.int(7, "EMA of RSI Slope")
colorMode = input.string("None", "Bar Coloring Mode", options=[
"None",
"Reversal Solid",
"Reversal Fade",
"Exceeding Bands",
"Classic Heat"
])
enableSignals = input.bool(false,'Show Signals')
// === Smooth RGB Gradient Function
f_colorGradient(_ratio, _colA, _colB) =>
rA = color.r(_colA)
gA = color.g(_colA)
bA = color.b(_colA)
rB = color.r(_colB)
gB = color.g(_colB)
bB = color.b(_colB)
rr = rA + int((rB - rA) * _ratio)
rg = gA + int((gB - gA) * _ratio)
rb = bA + int((bB - bA) * _ratio)
color.rgb(rr, rg, rb, 0)
// === Color Scheme ===
bullMain = color.new(#5CF0D7, 0)
bearMain = color.new(#B32AC3, 0)
labelTextCol = color.white
borderCol = color.white
// === Fair Value (EMA Only) ===
fair = ta.ema(src, fairLen)
// === Z-Score Deviation
dev = src - fair
devMean = ta.sma(dev, zLen)
devStdev = ta.stdev(dev, zLen)
zScore = devStdev != 0 ? (dev - devMean) / devStdev : 0
// === Z-Bands
upperBand = fair + zThreshold * devStdev
lowerBand = fair - zThreshold * devStdev
// === Re-entry Logic
wasAbove = src[1] > upperBand[1]
wasBelow = src[1] < lowerBand[1]
backInsideFromAbove = wasAbove and src <= upperBand
backInsideFromBelow = wasBelow and src >= lowerBand
// === RSI EMA Slope Filter
rsi = ta.rsi(close, rsiLen)
rsiEma = ta.ema(rsi, rsiEmaLen)
rsiSlope = rsiEma - rsiEma[1]
slopeUp = rsiSlope > 0
slopeDown = rsiSlope < 0
// === Signal Memory (One per slope)
var bool buyFiredOnSlope = false
var bool sellFiredOnSlope = false
// Reset logic when slope flips
buyReset = ta.crossover(rsiSlope, 0)
sellReset = ta.crossunder(rsiSlope, 0)
if buyReset
buyFiredOnSlope := false
if sellReset
sellFiredOnSlope := false
// Final entry conditions
finalBuy = backInsideFromBelow and slopeUp and not buyFiredOnSlope and enableSignals
finalSell = backInsideFromAbove and slopeDown and not sellFiredOnSlope and enableSignals
if finalBuy
buyFiredOnSlope := true
if finalSell
sellFiredOnSlope := true
// === Plot Fair Value and Bands (All White)
pUpper = plot(upperBand, "Üst Band", color=borderCol, linewidth=1)
pLower = plot(lowerBand, "Alt Band", color=borderCol, linewidth=1)
pFair = plot(fair, "Adil EMA", color=borderCol, linewidth=2)
// === Elegant Signal Labels
//plotshape(finalBuy, title="Buy", location=location.belowbar, style=shape.labelup, text="𝓤𝓹", color=bullMain, textcolor=#000000, size=size.small)
//plotshape(finalSell, title="Sell", location=location.abovebar, style=shape.labeldown, text="𝓓𝓸𝔀𝓷", color=bearMain, textcolor=labelTextCol, size=size.small)
// === Barcolor with Smoothing
// === Gradient Fill: Top → Mid, Bottom → Mid
fill(pUpper, pFair, upperBand, fair,color.new(bearMain, 60), #00010400)
fill(pFair, pLower, fair, lowerBand, color.new(#000000, 100),color.new(bullMain, 60))
// === Bar Coloring Modes
// Reversal Memory (for "Reversal Solid" and "Reversal Fade")
var string lastSignal = ""
if finalBuy
lastSignal := "bull"
if finalSell
lastSignal := "bear"
// Reversal Fade Tracker
var int signalAge = 0
if finalBuy or finalSell
signalAge := 0
else
signalAge += 1
// info
var string lastTrend = ""
if close > upperBand
lastTrend := "bull"
else if close < lowerBand
lastTrend := "bear"
// === Bar Coloring Logic
var color barCol = na
// 1. Reversal Solid
if colorMode == "Reversal Solid"
barCol := lastSignal == "bull" ? color.new(bullMain, 0) : lastSignal == "bear" ? color.new(bearMain, 0) : na
if colorMode == "None"
barCol := na
// 2. Reversal Fade
if colorMode == "Reversal Fade"
fade = math.min(90, signalAge * 1)
barCol := lastSignal == "bull" ? color.new(bullMain, fade) : lastSignal == "bear" ? color.new(bearMain, fade) : na
// 4. Exceeding Bands Only (only when outside bands)
if colorMode == "Exceeding Bands"
barCol := close > upperBand ? color.new(bullMain, 0) : close < lowerBand ? color.new(bearMain, 0) : na
// 5. Classic Heat — correct: strongest color near bands, fade near fair
// 5. Classic Heat — fixed: most intense near boundaries, fades toward fair
// 6. Gradient Flow — RGB blend from bull to bear based on band distance
if colorMode == "Classic Heat"
bandRange = upperBand - lowerBand
ratioRaw = (close - lowerBand) / bandRange
ratioClamped = math.max(0.0, math.min(ratioRaw, 1.0))
barCol := f_colorGradient(ratioClamped, bullMain, bearMain)
barcolor(barCol)
// === Table Position Setting
enableTable = input.bool(true,'Enable Table')
tablePos = input.string("Top Right", "Table Position", options=["Top Left", "Top Right", "Bottom Left", "Bottom Right"])
pos = tablePos == "Top Left" ? position.top_left :
tablePos == "Top Right" ? position.top_right :
tablePos == "Bottom Left" ? position.bottom_left :
position.bottom_right
// === Scoring Logic
score_z = zScore < -zThreshold ? +1 : zScore > zThreshold ? -1 : 0
score_slope = rsiSlope > 0 ? +1 : rsiSlope < 0 ? -1 : 0
score_price = close > fair ? +1 : close < fair ? -1 : 0
score_trend = lastTrend == "bull" ? +1 : lastTrend == "bear" ? -1 : 0
score_reentry = finalBuy ? +1 : finalSell ? -1 : 0
// === Score Aggregation
totalScore = score_z + score_slope + score_price + score_trend + score_reentry
scoreCount = 5
avgScore = totalScore / scoreCount
finalSignal = avgScore > 0.1 ? "AL" : avgScore < -0.1 ? "SAT" : "Nötr"
finalColor = avgScore > 0.1 ? bullMain : avgScore < -0.1 ? bearMain : color.gray
// === Shared Style
bgcolor = color.new(#000000, 0)
textCol = color.white
// === Table Drawing
if bar_index % 2 == 0 and enableTable
var table scoreTable = table.new(pos, 2, 7,frame_width = 1, border_width=1, frame_color=color.white, border_color=color.white)
table.cell(scoreTable, 0, 0, "İnd", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 0, "Puan", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 0, 1, "Z-Score", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 1, str.tostring(score_z), bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 0, 2, "RSI", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 2, str.tostring(score_slope), bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 0, 3, "Fiyat", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 3, str.tostring(score_price), bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 0, 4, "Trend ", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 4, str.tostring(score_trend), bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 0, 5, "R Giriş", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 5, str.tostring(score_reentry),bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 0, 6, "Sonuç", bgcolor=bgcolor, text_color=textCol)
table.cell(scoreTable, 1, 6, finalSignal, bgcolor=bgcolor, text_color=finalColor)
table.cell_set_text_font_family(scoreTable,0,0,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,0,font.family_monospace)
table.cell_set_text_font_family(scoreTable,0,1,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,1,font.family_monospace)
table.cell_set_text_font_family(scoreTable,0,2,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,2,font.family_monospace)
table.cell_set_text_font_family(scoreTable,0,3,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,3,font.family_monospace)
table.cell_set_text_font_family(scoreTable,0,4,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,4,font.family_monospace)
table.cell_set_text_font_family(scoreTable,0,5,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,5,font.family_monospace)
table.cell_set_text_font_family(scoreTable,0,6,font.family_monospace)
table.cell_set_text_font_family(scoreTable,1,6,font.family_monospace)
/////////////////
src88 = input.source(close,"RSI Source",group = "Connors RSI")
lenrsi = input(24, "RSI Length",group = "Connors RSI")
lenupdown = input(20, "UpDown Length",group = "Connors RSI")
lenroc = input(75, "ROC Length",group = "Connors RSI")
z_score_length = input(14, "Z-Score Lookback",group = "Filtering")
threshold = input.float(1.5, "Z-Score Threshold", step=0.025,group = "Filtering")
trendingLongThreshold = input.float(65, "Trending Long Threshold" ,group = "Filtering")
trendingShortThreshold = input.float(35, "Trending Short Threshold",group = "Filtering")
revertingLongThreshold = input.float(70, title="Reverting Long Threshold",group = "Filtering")
revertingShortThreshold = input.float(30, title="Reverting Short Threshold",group = "Filtering")
// ─── CONNORS RSI ──────────────────────────────────────────────────────────
updown(s) =>
isEqual = s == s[1]
isGrowing = s > s[1]
ud = 0.0
ud := isEqual ? 0 : isGrowing ? (nz(ud[1]) <= 0 ? 1 : nz(ud[1])+1) : (nz(ud[1]) >= 0 ? -1 : nz(ud[1])-1)
ud
rsi88 = ta.rsi(src88, lenrsi)
updownrsi = ta.rsi(updown(src88), lenupdown)
percentrank = ta.percentrank(ta.roc(src88, 1), lenroc)
crsi = math.avg(rsi, updownrsi, percentrank)
// ─── Z-SCORING ──────────────────────────────────────────────────────────
mean = ta.sma(crsi, z_score_length)
stdDev = ta.stdev(crsi, z_score_length)
zScore88 = (crsi - mean) / stdDev
isTrending = math.abs(zScore88) > threshold
// ─── Signal Generation ────────────────────────────────────────────────
var int signal = 0
if barstate.isconfirmed
if isTrending
signal := crsi > trendingLongThreshold ? 1 : crsi < trendingShortThreshold ? -1 : signal[1]
else
signal := crsi > revertingLongThreshold ? 1 : crsi < revertingShortThreshold ? -1 : signal[1]
trendColor = signal == 1 ? #17dfad : signal == -1 ? #dd326b : color.gray
bgcolor(color.new(trendColor,75))
/////////////
//@version=6
src6 = close
ma5 = ta.sma(src6, 2)
ma8 = ta.sma(src6, 3)
ma13 = ta.sma(src6, 5)
buy_cond = ta.cross(ma5, ma13) and ma5 > ma13
sell_cond = ta.cross(ma5, ma13) and ma5 < ma8 and ma5 < ma13
plotarrow(buy_cond ? 1 : 0, colordown = color.rgb(0, 255, 8), title = 'BUY SIGNAL', maxheight = 50, minheight = 50)
plotarrow(sell_cond ? -1 : 0, colorup = color.rgb(255, 0, 0), title = 'SELL SIGNAL', maxheight = 50, minheight = 50)
Yer İmleri