The
The
indicator(title = 'Range Filter Buy and Sell 5min', shorttitle = 'The Real
GainsAlgo', overlay = true)
// Color variables
upColor = color.white
midColor = #90bff9
downColor = color.blue
// Source
src = input(defval = close, title = 'Source')
// Sampling Period
// Settings for 5min chart, BTCUSDC. For Other coin, change the paremeters
per = input.int(defval = 100, minval = 1, title = 'Sampling Period')
// Range Multiplier
mult = input.float(defval = 3.0, minval = 0.1, title = 'Range Multiplier')
// Range Filter
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(src, smrng)
// Filter Direction
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])
// Target Bands
hband = filt + smrng
lband = filt - smrng
// Colors
filtcolor = upward > 0 ? upColor : downward > 0 ? downColor : midColor
barcolor = src > filt and src > src[1] and upward > 0 ? upColor : src > filt and
src < src[1] and upward > 0 ? upColor : src < filt and src < src[1] and downward >
0 ? downColor : src < filt and src > src[1] and downward > 0 ? downColor : midColor
// Target
hbandplot = plot(hband, color = color.new(upColor, 70), title = 'High Target')
lbandplot = plot(lband, color = color.new(downColor, 70), title = 'Low Target')
// Fills
fill(hbandplot, filtplot, color = color.new(upColor, 90), title = 'High Target
Range')
fill(lbandplot, filtplot, color = color.new(downColor, 90), title = 'Low Target
Range')
// Bar Color
barcolor(barcolor)
// Break Outs
longCond = bool(na)
shortCond = bool(na)
longCond := src > filt and src > src[1] and upward > 0 or src > filt and src <
src[1] and upward > 0
shortCond := src < filt and src < src[1] and downward > 0 or src < filt and src >
src[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
longCondition = longCond and CondIni[1] == -1
shortCondition = shortCond and CondIni[1] == 1
//Alerts
plotshape(longCondition, title = 'Buy Signal', text = 'Buy+', textcolor =
color.white, style = shape.labelup, size = size.small, location =
location.belowbar, color = color.new(#aaaaaa, 20))
plotshape(shortCondition, title = 'Sell Signal', text = 'Sell+', textcolor =
color.white, style = shape.labeldown, size = size.small, location =
location.abovebar, color = color.new(downColor, 20))
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
check_impulse() =>
impulse_length = 34
impulse_strength = 9
hi = calc_smma(high, impulse_length)
lo = calc_smma(low, impulse_length)
mi = calc_zlema(hlc3, impulse_length)
md = mi > hi ? mi - hi : mi < lo ? mi - lo : 0
md_prev = mi[1] > hi[1] ? mi[1] - hi[1] : mi[1] < lo[1] ? mi[1] - lo[1] : 0
sb = ta.sma(md, impulse_strength)
sb_prev = ta.sma(md_prev, impulse_strength)
sh = md - sb
sh_prev = md_prev - sb_prev
get_trend_status() =>
impulse = catch_flat ? check_impulse() : true
ema1_current_candle = ta.ema(close, ema1_length)
ema1_previous_candle = ema1_current_candle[1]
round = ema1_current_candle > 1000 ? 0 : ema1_current_candle > 10 ? 1 :
ema1_current_candle > 0 ? 2 : ema1_current_candle > 0.1 ? 3 : 10
ema1_str = str.tostring(math.round(ema1_current_candle, round))
if trend_identification_approach == 'Direction of a single EMA'
ema1_previous_previous_candle = ema1_current_candle[2]
trend_current_candle = not impulse ? neutraltrend_indicator :
ema1_current_candle > ema1_previous_candle ? uptrend_indicator :
ema1_current_candle < ema1_previous_candle ? downtrend_indicator :
neutraltrend_indicator
trend_previous_candle = not impulse ? neutraltrend_indicator :
ema1_previous_candle > ema1_previous_previous_candle ? uptrend_indicator :
ema1_previous_candle < ema1_previous_previous_candle ? downtrend_indicator :
neutraltrend_indicator
[ema1_str, trend_current_candle, trend_previous_candle]
else
ema2_current_candle = ta.ema(close, ema2_length)
ema2_previous_candle = ema2_current_candle[1]
trend_current_candle = not impulse ? neutraltrend_indicator :
ema1_current_candle > ema2_current_candle ? uptrend_indicator : ema1_current_candle
< ema2_current_candle ? downtrend_indicator : neutraltrend_indicator
trend_previous_candle = not impulse ? neutraltrend_indicator :
ema1_previous_candle > ema2_previous_candle ? uptrend_indicator :
ema1_previous_candle < ema2_previous_candle ? downtrend_indicator :
neutraltrend_indicator
[ema1_str, trend_current_candle, trend_previous_candle]
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
if barstate.islast
if show_header
table.cell(t, 0, 0, 'Timeframe', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 0, 'Trend', text_color = text_color, text_size =
table_text_size)
if show_ema_value
table.cell(t, 2, 0, str.tostring(ema1_length) + ' EMA', text_color =
text_color, text_size = table_text_size)
if show_1m
table.cell(t, 0, 1, '1m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 1, trend_indicator_1m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 1, ema_1m, text_color = text_color, text_size =
table_text_size)
if show_2m
table.cell(t, 0, 2, '2m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 2, trend_indicator_2m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 2, ema_2m, text_color = text_color, text_size =
table_text_size)
if show_3m
table.cell(t, 0, 3, '3m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 3, trend_indicator_3m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 3, ema_3m, text_color = text_color, text_size =
table_text_size)
if show_5m
table.cell(t, 0, 4, '5m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 4, trend_indicator_5m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 4, ema_5m, text_color = text_color, text_size =
table_text_size)
if show_10m
table.cell(t, 0, 5, '10m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 5, trend_indicator_10m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 5, ema_10m, text_color = text_color, text_size =
table_text_size)
if show_15m
table.cell(t, 0, 6, '15m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 6, trend_indicator_15m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 6, ema_15m, text_color = text_color, text_size =
table_text_size)
if show_30m
table.cell(t, 0, 7, '30m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 7, trend_indicator_30m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 7, ema_30m, text_color = text_color, text_size =
table_text_size)
if show_45m
table.cell(t, 0, 8, '45m', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 8, trend_indicator_45m, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 8, ema_45m, text_color = text_color, text_size =
table_text_size)
if show_1h
table.cell(t, 0, 9, '1h', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 9, trend_indicator_1h, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 9, ema_1h, text_color = text_color, text_size =
table_text_size)
if show_2h
table.cell(t, 0, 10, '2h', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 10, trend_indicator_2h, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 10, ema_2h, text_color = text_color, text_size =
table_text_size)
if show_3h
table.cell(t, 0, 11, '3h', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 11, trend_indicator_3h, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 11, ema_3h, text_color = text_color, text_size =
table_text_size)
if show_4h
table.cell(t, 0, 12, '4h', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 12, trend_indicator_4h, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 12, ema_4h, text_color = text_color, text_size =
table_text_size)
if show_12h
table.cell(t, 0, 13, '12h', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 13, trend_indicator_12h, text_color = text_color,
text_size = table_text_size)
if show_ema_value
table.cell(t, 2, 13, ema_12h, text_color = text_color, text_size =
table_text_size)
if show_D
table.cell(t, 0, 14, 'D', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 14, trend_indicator_D, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 14, ema_D, text_color = text_color, text_size =
table_text_size)
if show_3D
table.cell(t, 0, 15, '3D', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 15, trend_indicator_3D, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 15, ema_3D, text_color = text_color, text_size =
table_text_size)
if show_W
table.cell(t, 0, 16, 'W', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 16, trend_indicator_W, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 16, ema_W, text_color = text_color, text_size =
table_text_size)
if show_M
table.cell(t, 0, 17, 'M', text_color = text_color, text_size =
table_text_size)
table.cell(t, 1, 17, trend_indicator_M, text_color = text_color, text_size
= table_text_size)
if show_ema_value
table.cell(t, 2, 17, ema_M, text_color = text_color, text_size =
table_text_size)
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
//text inputs
title = input.string('AG FX TRADING', 'Tittle', group = 'text')
subtitle = input.string('PATIENCE | DISCIPLINE | FEARLESS', 'Subtitle', group =
'text')
//symbol info
symInfoCheck = input.bool(title = 'Show Symbol Info', defval = true, group =
'watermark position')
symInfo = syminfo.ticker + ' | ' + timeframe.period + (timeframe.isminutes ? 'M' :
na)
date = str.tostring(dayofmonth(time_close)) + '/' + str.tostring(month(time_close))
+ '/' + str.tostring(year(time_close))
//text positioning
textVPosition = input.string('top', 'Vertical Position', options = ['top',
'middle', 'bottom'], group = 'watermark position')
textHPosition = input.string('center', 'Horizontal Position', options = ['left',
'center', 'right'], group = 'watermark position')
//symbol info positioning
symVPosition = input.string('bottom', 'Vertical Position', options = ['top',
'middle', 'bottom'], group = 'symbol position')
symHPosition = input.string('center', 'Horizontal Position', options = ['left',
'center', 'right'], group = 'symbol position')
//cell size
width = input.int(0, 'Width', minval = 0, maxval = 100, tooltip = 'The width of the
cell as a % of the indicator\'s visual space. Optional. By default, auto-adjusts
the width based on the text inside the cell. Value 0 has the same effect.', group =
'cell size')
height = input.int(0, 'Height', minval = 0, maxval = 100, tooltip = 'The height of
the cell as a % of the indicator\'s visual space. Optional. By default, auto-
adjusts the height based on the text inside of the cell. Value 0 has the same
effect.', group = 'cell size')
//title settings
c_title = input.color(color.new(color.black, 0), 'Title Color', group = 'title
settings')
s_title = input.string('large', 'Title Size', options = ['tiny', 'small', 'normal',
'large', 'huge', 'auto'], group = 'title settings')
a_title = input.string('center', 'Title Alignment', options = ['center', 'left',
'right'], group = 'title settings')
//subtitle settings
c_subtitle = input.color(color.new(color.black, 30), 'Subitle Color', group =
'subtitle settings')
s_subtitle = input.string('normal', 'Subtitle Size', options = ['tiny', 'small',
'normal', 'large', 'huge', 'auto'], group = 'subtitle settings')
a_subtitle = input.string('center', 'Subtitle Alignment', options = ['center',
'left', 'right'], group = 'subtitle settings')
//symbol settings
c_symInfo = input.color(color.new(color.black, 30), 'Subitle Color', group =
'symbol settings')
s_symInfo = input.string('normal', 'Subtitle Size', options = ['tiny', 'small',
'normal', 'large', 'huge', 'auto'], group = 'symbol settings')
a_symInfo = input.string('center', 'Subtitle Alignment', options = ['center',
'left', 'right'], group = 'symbol settings')
c_bg = input.color(color.new(color.blue, 100), 'Background', group = 'background')
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
// Inputs
ema8 = ta.vwma(close, 8)
ema13 = ta.vwma(close, 13)
ema21 = ta.vwma(close, 21)
ema34 = ta.vwma(close, 34)
emaup = ema8 > ema13 and ema13 > ema21 and ema21 > ema34
emadn = ema8 < ema13 and ema13 < ema21 and ema21 < ema34
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
import aybarsm/tac/3 as tac
import aybarsm/Tools/12 as tools
import aybarsm/ToolsMap/2 as tmap
// Inputs
bool showEntryBuy = input.bool(title = 'Buy: Entry', defval = true, group = 'Show
Signals', inline = 'signalsBuy')
bool showTpBuy = input.bool(title = 'Buy: TP', defval = true, group = 'Show
Signals', inline = 'signalsBuy')
bool showReBuy = input.bool(title = 'Buy: RE', defval = true, group = 'Show
Signals', inline = 'signalsBuy')
bool showExitBuy = input.bool(title = 'Buy: Exit', defval = false, group = 'Show
Signals', inline = 'signalsBuy')
bool showEntrySell = input.bool(title = 'Sell: Entry', defval = true, group = 'Show
Signals', inline = 'signalsSell')
bool showTpSell = input.bool(title = 'Sell: TP', defval = true, group = 'Show
Signals', inline = 'signalsSell')
bool showReSell = input.bool(title = 'Sell: RE', defval = true, group = 'Show
Signals', inline = 'signalsSell')
bool showExitSell = input.bool(title = 'Sell: Exit', defval = false, group = 'Show
Signals', inline = 'signalsSell')
float psarStart = input.float(title = 'Start', minval = 0.001, defval = 0.02, group
= 'PSAR', inline = 'psar')
float psarIncrement = input.float(title = 'Inc', minval = 0.001, defval = 0.02,
group = 'PSAR', inline = 'psar')
float psarMax = input.float(title = 'Max', minval = 0.0001, defval = 0.025, group =
'PSAR', inline = 'psar')
float minReProximity = input.float(defval = 0, minval = 0, step = 0.01, maxval =
99.99, title = 'Minimum Re-Entry Proximity Ratio', group = 'Signal Fine-Tuning',
tooltip = 'Minimum required proximity ratio to PSAR for re-entry signal')
bool showPsar = input.bool(title = 'PSAR', defval = false, group = 'Show
Informative', inline = 'informative')
bool showPsarLagging = input.bool(title = 'Lagging PSAR', defval = true, group =
'Show Informative', inline = 'informative')
bool showPosEntryPrice = input.bool(title = 'Pos Entry', defval = false, group =
'Show Informative', inline = 'informative')
// One-time Variables
var tools.PosInfo pos = na
var tools.Fractals fractals = tools.Fractals.new()
fractals := tools.processFractals(fractals, high, low, 2, 2)
// Initial definitions
chk.put('enterBuy', ta.crossover(high, psar_lagging))
chk.put('enterSell', ta.crossunder(low, psar_lagging))
pos := chk.get('enterBuy') or chk.get('enterSell') ?
tools.new_pos(chk.get('enterBuy') ? tools.PosState.buy : tools.PosState.sell,
psar_lagging) : pos
chk.put('posBuy', not na(pos) ? pos.state == tools.PosState.buy : false)
chk.put('posSell', not na(pos) ? pos.state == tools.PosState.sell : false)
chk.put('upBoEligible', close[1] > open[1] and close <= open)
chk.put('downBoEligible', close[1] < open[1] and close >= open)
if not na(pos)
lastTp := array.size(pos.tp) > 0 ? array.last(pos.tp) : na
lastRe := array.size(pos.re) > 0 ? array.last(pos.re) : na
plot(showPsar ? psar : na, title = 'PSAR', style = plot.style_line, color = psar <
low ? color.lime : color.red)
plot(showPsarLagging ? psar_lagging : na, title = 'Lagging PSAR', color =
psar_lagging < low ? color.yellow : color.fuchsia, style = plot.style_line)
plot(showPosEntryPrice and not na(pos) ? pos.price : na, title = 'PosEntryPrice',
color = color.white, style = plot.style_line)
plot(not na(pos) ? pos.price : na, title = 'AlertPosEntryValue', color =
color.white, style = plot.style_line, display = display.none)
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////