Pro v3
Pro v3
// ============================[INPUTS]============================ //
// Signal Inputs
signalMode = input.string("All", "Signal Mode", options=["All", "Normal",
"Strong"], group="BUY/SELL", inline='1')
sigsensiviti = input.float(5, "Signal Sensitivity (1-15)", minval=1, maxval=15,
tooltip="Changes the signal display frequency", group="BUY/SELL", inline='j')
showCandleColors = input.bool(true, "Show Bar Colors", group="BUY/SELL",
inline='ee')
bullishColor = input.color(#01d7ee, '', group="BUY/SELL", inline='ee')
bearishColor = input.color(#cd0542, '', group="BUY/SELL", inline='ee')
maFilter = input.bool(false, "MA Filter", group="BUY/SELL", inline='rr')
maType = input.string("SMA", "", options=["SMA", "EMA", "WMA", "VWMA", "HMA"],
group="BUY/SELL", inline='rr')
maLength = input.int(200, "", minval=1, group="BUY/SELL", inline='rr')
// TP/SL Inputs
riskmanage = input.string("No", "TP/SL", options=["Yes", "No"], inline='1',
group="TP/SL")
riskmanage_bool = riskmanage == "Yes"
tpstrength = input.float(3, "Risk Management", tooltip="Multiplier for TP levels",
group="TP/SL", minval=0.1, step=0.1)
slColor = input.color(#d00010, "SL Color", group="TP/SL")
entryColor = input.color(#9598a1, "Entry Color", group="TP/SL")
tp1Color = input.color(#16a000, "TP-1 Color", group="TP/SL")
tp2Color = input.color(#16a000, "TP-2 Color", group="TP/SL")
tp3Color = input.color(#16a000, "TP-3 Color", group="TP/SL")
longtp = input.color(#16a000, "TP-3 Color", group="TP/SL")
shorttp = input.color(#16a000, "TP-3 Color", group="TP/SL")
useTP1 = true
multTP1 = tpstrength
useTP2 = true
multTP2 = tpstrength * 2
useTP3 = true
multTP3 = tpstrength * 3
// Colors for TP breakout labels
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR)[1])
pivotLow = fixnan(ta.pivotlow(barsL, barsR)[1])
source = close, period = 150
[s1, a1, i1] = lr_slope(source, period)
[upDev, dnDev] = lr_dev(source, period, s1, a1, i1)
// ============================[MOVING AVERAGE
FUNCTIONS]============================ //
hma(src, length) =>
ta.wma(2 * ta.wma(src, length / 2) - ta.wma(src, length),
math.round(math.sqrt(length)))
// Calculate MA
selectedMA = getMA(maType, close, maLength)
// ============================[CALCULATIONS]============================ //
factor = 11
signals_show = true
emaLength = 200
emaSource = close
ema = ta.ema(emaSource, emaLength)
sma1 = ta.sma(close, 8)
sma2 = ta.sma(close, 9)
sma3 = ta.sma(close, 13)
[supertrend, direction] = supertrend(open, sigsensiviti, factor)
// Apply MA Filter
bull = ta.crossover(close, supertrend) and close >= sma3 and not (close[1] > ema
and close > ema) and (not maFilter or close > selectedMA)
bear = ta.crossunder(close, supertrend) and close <= sma3 and not (not (close[1] >
ema and close > ema)) and (not maFilter or close < selectedMA)
Sbull = ta.crossover(close, supertrend) and close >= sma3 and (close[1] > ema and
close > ema) and (not maFilter or close > selectedMA)
Sbear = ta.crossunder(close, supertrend) and close <= sma3 and not (close[1] > ema
and close > ema) and (not maFilter or close < selectedMA)
if valid_bear or valid_Sbear
shortPositionActive := true
longPositionActive := false
longTp1Broken := false
longTp2Broken := false
longTp3Broken := false
shortTp1Broken := false
shortTp2Broken := false
shortTp3Broken := false
if pos == 0
longPositionActive := false
shortPositionActive := false
longTp1Broken := false
longTp2Broken := false
longTp3Broken := false
shortTp1Broken := false
shortTp2Broken := false
shortTp3Broken := false
// Calculate direction: Long (1) for bull/Sbull, Short (-1) for bear/Sbear
direction1 = signal_type == 1 or signal_type == 2 ? 1 : signal_type == 3 or
signal_type == 4 ? -1 : 0
// Define candle color for TP breakouts (green for first TP1, TP2, or TP3 breakout)
candleColor1 = longTp1Breakout or longTp2Breakout or longTp3Breakout or
shortTp1Breakout or shortTp2Breakout or shortTp3Breakout ? color.rgb(0, 255, 8) :
na
// Condition for TP1 breakout (price breaks above TP1 for long position)
// Populate Dashboard
if barstate.islast and enableDashboard
dashboard_cell(0, 0, "SMRT Algo", color.white)
dashboard_cell(1, 0, "Pro", color.white)
table.merge_cells(dashboard, 0, 0, 0, 0)
dashboard_cell(0, 1, "Current Position", color.white)
dashboard_cell(1, 1, currentPosition == na ? "No Signal" : currentPosition,
color.black), dashboard_cell_bg(1, 1, positionBgColor == na ? color.gray :
positionBgColor)
dashboard_cell(0, 2, "Current Trend", color.white)
dashboard_cell(1, 2, emaBull ? "Bullish" : "Bearish", color.black),
dashboard_cell_bg(1, 2, emaBull ? color.green : color.red)
dashboard_cell(0, 7, "1 Hour", color.white)
dashboard_cell(0, 8, "2 Hour", color.white)
dashboard_cell(0, 9, "4 Hour", color.white)
dashboard_cell(0, 10, "8 Hour", color.white)
dashboard_cell(0, 11, "Daily", color.white)
dashboard_cell(1, 7, TF60Bull ? "Bullish" : "Bearish", color.black),
dashboard_cell_bg(1, 7, TF60Bull ? color.green : color.red)
dashboard_cell(1, 8, TF120Bull ? "Bullish" : "Bearish", color.black),
dashboard_cell_bg(1, 8, TF120Bull ? color.green : color.red)
dashboard_cell(1, 9, TF240Bull ? "Bullish" : "Bearish", color.black),
dashboard_cell_bg(1, 9, TF240Bull ? color.green : color.red)
dashboard_cell(1, 10, TF720Bull ? "Bullish" : "Bearish", color.black),
dashboard_cell_bg(1, 10, TF720Bull ? color.green : color.red)
dashboard_cell(1, 11, TFDBull ? "Bullish" : "Bearish", color.black),
dashboard_cell_bg(1, 11, TFDBull ? color.green : color.red)
// TREND
// Functions
lineStyle1 = (styleOption == "Dotted ┈") ? line.style_dotted :
(styleOption == "Dashed ╌") ? line.style_dashed :
(styleOption == "Arrow Left ←") ? line.style_arrow_left :
(styleOption == "Arrow Right →") ? line.style_arrow_right :
(styleOption == "Arrows Both ↔") ? line.style_arrow_both :
line.style_solid
// تابع محاسبهMA
esma(source, length)=>
s = ta.sma(source, length)
e = ta.ema(source, length)
exp ? e : s
ن//
ا سا سف ع ا ل ب ود محا سب ه ر ن گ ا ب ر ب رReversal Bands
colorUpper1 = reversalBandsEnabled ? color.new(#787b86, 85) : na
colorUpper2 = reversalBandsEnabled ? color.new(#787b86, 75) : na
colorLower1 = reversalBandsEnabled ? color.new(#787b86, 85) : na
colorLower2 = reversalBandsEnabled ? color.new(#787b86, 75) : na
// فقط زمانی که( پر کردن فضای بین باندهاReversal Bands )فعال است
fill(u1, u2, color=colorUpper1)
fill(u2, u3, color=colorUpper2)
fill(l1, l2, color=colorLower1)
fill(l2, l3, color=colorLower2)
// EzAlgo SR
if useHLZones
highest_fill1 := line.new(bar_index - 311, highestph + zonePerc, bar_index,
highestph + zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
highest_fill2 := line.new(bar_index - 311, highestph - zonePerc, bar_index,
highestph - zonePerc, xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill1 := line.new(bar_index - 311, lowestpl + zonePerc , bar_index,
lowestpl + zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
lowest_fill2 := line.new(bar_index - 311, lowestpl - zonePerc , bar_index,
lowestpl - zonePerc , xloc.bar_index, expandSR ? extend.both : extend.right, na)
linefill.new(highest_fill1, highest_fill2, color.new(hi_col, 80))
linefill.new(lowest_fill1 , lowest_fill2 , color.new(lo_col, 80))
if ph or pl
for x = 0 to array.size(sr_lines) - 1
array.set(sr_levs, x, array.get(sr_levels, x))
for x = 0 to array.size(sr_lines) - 1
line.delete(array.get(sr_lines, x))
line.delete(array.get(sr_linesH, x))
line.delete(array.get(sr_linesL, x))
linefill.delete(array.get(sr_linesF, x))
if array.get(sr_levs, x) and enableSR
line_col = close >= array.get(sr_levs, x) ? colorSup : colorRes
if useZones
array.set(sr_linesH, x, line.new(bar_index - 355, array.get(sr_levs, x)
+ zonePerc, bar_index, array.get(sr_levs, x) + zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesL, x, line.new(bar_index - 355, array.get(sr_levs, x)
- zonePerc, bar_index, array.get(sr_levs, x) - zonePerc, xloc.bar_index, expandSR ?
extend.both : extend.right, na))
array.set(sr_linesF, x, linefill.new(array.get(sr_linesH, x),
array.get(sr_linesL, x), color.new(line_col, 80)))
// Function Definitions
simple_filter(float source, int length, bool duel_filter) =>
switch duel_filter
false => ta.wma(source, length)
true => ta.wma(ta.sma(source, length), length)
tr = candle_top - candle_bottom
atr = ta.sma(tr, atr_length)
if flag
sr_ma := source
current_range := atr * multiplier
top_range := sr_ma + current_range
bottom_range := sr_ma - current_range
///////////////////////////////////////////////////
//////// Zonas de Supply/Demand
//////////////////////////////////////////////////
G_POI = 'Supply/Demand'
POIATR = ta.atr(300)
ColorSupply = input.color(#9d0040, title = 'Supply', group = G_POI)
ColorSupplyOutline = input.color(color.new(color.white,100), title = 'Supply',
group = G_POI)
ColorDemand = input.color(color.rgb(0, 138, 153, 65), title = 'Demand', group =
G_POI)
ColorDemandOutline = input.color(color.new(color.white,100), title = 'Demand',
group = G_POI)
SwingLength = input.int(10, title = 'High/Low Swing Length', group = G_POI, minval
= 1, maxval = 50)
HistoryDemandKepp = input.int(21, title = 'History to maintain', minval = 5, maxval
= 50, group = G_POI)
BoxWidth = input.float(10, title = 'Supply/Demand Box Width', group = G_POI, minval
= 1, maxval = 10, step = 0.5)
ColorLabelPOI = input.color(#bdbdbd, title = 'POI', group = G_POI)
MaxExtention = input.bool(true, title = "Extend", group = G_POI)
atr_threshold = POIATR * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 90)
BoxExtendEndPointF(SupplyBoxCurrent)
BoxExtendEndPointF(DemandBoxCurrent)
// ورودیها
initial_stop = input.float(0.1, "Initial Stop", group='Trailing Stop Loss')
risk_increment = input.float(0.01, "Risk Increment", group='Trailing Stop Loss')
max_risk = input.float(0.03, "Max Risk", group='Trailing Stop Loss')
zone_width = input.float(0.3, "Zone Width", group='Trailing Stop Loss')
// ورودی برای روشن و خاموش کردنTrailing Stop
// محاسباتATR
atrs = ta.atr(100) * zone_width
// رسم نمودارSAR
p1 = plot(sarone_plot, "trail", color=color.new(close > sarone ? #00ff0a : #ff0014,
transp=75), style=plot.style_circles)
p3 = plot(sarzone_plot, "Zone Line", color=color.new(close > sarone ? #00ff0a :
#ff0014, transp=75), style=plot.style_circles)
// Constants
color CLEAR = color.rgb(0,0,0,100)
// Inputs
swingSize = input.int(45, 'Swing Length', group='Market Structure')
bosConfType = input.string('Candle Close', 'Confirmation', ['Candle Close',
'Wicks'], group='Market Structure')
// BOS Settings
bosColor = input.color(color.rgb(112, 114, 119), 'Color', group='Market Structure')
bosStyle = input.string('Dashed', 'Line Style', ['Solid', 'Dashed', 'Dotted'],
group='Market Structure')
bosWidth = input.int(1, 'Width', minval=1, group='Market Structure')
// Functions
lineStyle(x) =>
switch x
'Solid' => line.style_solid
'Dashed' => line.style_dashed
'Dotted' => line.style_dotted
// Calculations
bool hh = false
bool lh = false
bool hl = false
bool ll = false
//Variable to track the previous swing type, used later on to draw HH, LH, HL, LL
var int prevSwing = 0
if not na(pivHi)
if pivHi >= prevHigh
hh := true
prevSwing := 2
else
lh := true
prevSwing := 1
prevHigh := pivHi
highActive := true
prevHighIndex := bar_index - swingSize
if not na(pivLo)
if pivLo >= prevLow
hl := true
prevSwing := -1
else
ll := true
prevSwing := -2
prevLow := pivLo
lowActive := true
prevLowIndex := bar_index - swingSize
// Visual Output
//Swing level labels and BOS/CHoCH Lines (combined under Market Structure)
if marketStructure
//Swing Points
if hh
label.new(bar_index - swingSize, pivHi, 'HH', color=CLEAR,
style=label.style_label_down, textcolor=chart.fg_color, size = size.small)
if lh
label.new(bar_index - swingSize, pivHi, 'LH', color=CLEAR,
style=label.style_label_down, textcolor=chart.fg_color, size = size.small)
if hl
label.new(bar_index - swingSize, pivLo, 'HL', color=CLEAR,
style=label.style_label_up, textcolor=chart.fg_color, size = size.small)
if ll
label.new(bar_index - swingSize, pivLo, 'LL', color=CLEAR,
style=label.style_label_up, textcolor=chart.fg_color, size = size.small)
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 200, 200)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(close, smrng)
//
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])
// Chart Features
x11 = 22
x21 = 12
x3 = 20
x4 = 5
smoothrngX1(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrngX1 = ta.ema(avrng, wper) * m
smoothrngX1
smrngx1x = smoothrngX1(close, x11, x21)
smrngx1x2 = smoothrngX1(close, x3, x4)
rngfiltx1x1(x, r) =>
rngfiltx1x1 = x
rngfiltx1x1 := x > nz(rngfiltx1x1[1]) ? x - r < nz(rngfiltx1x1[1]) ?
nz(rngfiltx1x1[1]) : x - r : x + r > nz(rngfiltx1x1[1]) ? nz(rngfiltx1x1[1]) : x +
r
rngfiltx1x1
filtx1 = rngfiltx1x1(close, smrngx1x)
filtx12 = rngfiltx1x1(close, smrngx1x2)
//
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upwardx1 = 0.0
upwardx1 := filtx1 > filtx1[1] ? nz(upwardx1[1]) + 1 : filtx1 < filtx1[1] ? 0 :
nz(upwardx1[1])
downwardx1 = 0.0
downwardx1 := filtx1 < filtx1[1] ? nz(downwardx1[1]) + 1 : filtx1 > filtx1[1] ? 0 :
nz(downwardx1[1])
// Other initializations
avg_volume = ta.sma(volume, 20)
very_weak_multiplier = 0.5
weak_multiplier = 1
strong_multiplier = 1.5
// های
ورودی برای روشن یا خاموش کردن سیگنالDiamond
// محاسبهRSI
rsi = ta.rsi(close, rsiPeriod)
// Trend Cloud
tclength = 600
hullma = ta.wma(2*ta.wma(close, tclength/2)-ta.wma(close, tclength),
math.floor(math.sqrt(tclength)))
plot(LongTrendAverage ? hullma : na, 'Trend Cloud', linewidth=4, color=close[8] >
hullma ? color.new(#00b9cd, 10) : color.new(#ad0045, 10))
// Chart Features
x15 = 22
x25 = 9
x35 = 15
x45 = 5
//
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upwardx15 = 0.0
upwardx15 := filtx15 > filtx15[1] ? nz(upwardx15[1]) + 1 : filtx15 < filtx15[1] ? 0
: nz(upwardx15[1])
downwardx15 = 0.0
downwardx15 := filtx15 < filtx15[1] ? nz(downwardx15[1]) + 1 : filtx15 > filtx15[1]
? 0 : nz(downwardx15[1])
// Other initializations
avg_volume5 = ta.sma(volume, 20)
very_weak_multiplier5 = 0.5
weak_multiplier5 = 1
strong_multiplier5 = 1.5
length = input(50)
highlightMovements = true
src2 = close
lag = math.floor((length - 1) / 2)