PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © paaax
//@version=5
indicator('[PX] MTF Overview', overlay = true)
// { Functions
f_getPosition(_pos) =>
ret = position.bottom_center
if _pos == 'Top Center'
ret := position.top_center
ret
if _pos == 'Top Right'
ret := position.top_right
ret
if _pos == 'Middle Left'
ret := position.middle_left
ret
if _pos == 'Middle Center'
ret := position.middle_center
ret
if _pos == 'Middle Right'
ret := position.middle_right
ret
if _pos == 'Bottom Left'
ret := position.bottom_left
ret
if _pos == 'Bottom Center'
ret := position.bottom_center
ret
if _pos == 'Bottom Right'
ret := position.bottom_right
ret
ret
f_normalize(_src, _min, _max) => //@PineCoders
var _historicMin = 10e10
var _historicMax = -10e10
_historicMin := math.min(nz(_src, _historicMin), _historicMin)
_historicMax := math.max(nz(_src, _historicMax), _historicMax)
_min + (_max - _min) * (_src - _historicMin) / math.max(_historicMax - _historicMin, 10e-10)
f_security(_sym, _res, _src, _rep) => //@PineCoders
request.security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
//} Functions
// { Inputs
bool i_repaint = input.bool(false, 'Repaint', group='MTF')
string i_timeframe1 = input.timeframe('60', 'Timeframe 1', group='MTF')
string i_timeframe2 = input.timeframe('15', 'Timeframe 2', group='MTF')
string i_timeframe3 = input.timeframe('5', 'Timeframe 3', group='MTF')
string i_pos = input.string(defval='Bottom Center', title='Table Position', options=['Top Left', 'Top Center', 'Top Right', 'Middle Left', 'Middle Center', 'Middle Right', 'Bottom Left', 'Bottom Center', 'Bottom Right'], group='Layout')
color i_col = input.color(defval=color.white, title='Label Color', group='Layout')
int i_rsiLen = input.int(14, 'RSI Length', group='Momentum')
int i_atrLen = input.int(14, 'ATR Length', group='Volatility')
float i_start = input.float(0, 'PSAR', group='Trend', inline='1')
float i_increment = input.float(0.01, '', group='Trend', inline='1')
float i_maximum = input.float(0.1, '', group='Trend', inline='1')
// } Inputs
// { Calculations
rsi = ta.rsi(close, i_rsiLen)
natr = f_normalize(ta.atr(i_atrLen), 0, 100)
out = ta.sar(i_start, i_increment, i_maximum)
// } Calculations
rsi1 = f_security(syminfo.tickerid, i_timeframe1, rsi, i_repaint)
prevRsi1 = f_security(syminfo.tickerid, i_timeframe1, rsi[1], i_repaint)
rsi2 = f_security(syminfo.tickerid, i_timeframe2, rsi, i_repaint)
prevRsi2 = f_security(syminfo.tickerid, i_timeframe2, rsi[1], i_repaint)
rsi3 = f_security(syminfo.tickerid, i_timeframe3, rsi, i_repaint)
prevRsi3 = f_security(syminfo.tickerid, i_timeframe3, rsi[1], i_repaint)
atr1 = f_security(syminfo.tickerid, i_timeframe1, natr, i_repaint)
prevAtr1 = f_security(syminfo.tickerid, i_timeframe1, natr[1], i_repaint)
atr2 = f_security(syminfo.tickerid, i_timeframe2, natr, i_repaint)
prevAtr2 = f_security(syminfo.tickerid, i_timeframe2, natr[1], i_repaint)
atr3 = f_security(syminfo.tickerid, i_timeframe3, natr, i_repaint)
prevAtr3 = f_security(syminfo.tickerid, i_timeframe3, natr[1], i_repaint)
trend1 = f_security(syminfo.tickerid, i_timeframe1, out, i_repaint)
prevTrend1 = f_security(syminfo.tickerid, i_timeframe1, out[1], i_repaint)
trend2 = f_security(syminfo.tickerid, i_timeframe2, out, i_repaint)
prevTrend2 = f_security(syminfo.tickerid, i_timeframe2, out[1], i_repaint)
trend3 = f_security(syminfo.tickerid, i_timeframe3, out, i_repaint)
prevTrend3 = f_security(syminfo.tickerid, i_timeframe3, out[1], i_repaint)
//} MTF
// { Table
var overview = table.new(position=f_getPosition(i_pos), columns=4, rows=6, bgcolor=color.new(color.black, 100), border_width=1)
if barstate.islast
// Labels
table.cell(overview, 1, 0, i_timeframe1, text_color=color.new(i_col, 0))
table.cell(overview, 2, 0, i_timeframe2, text_color=color.new(i_col, 0))
table.cell(overview, 3, 0, i_timeframe3, text_color=color.new(i_col, 0))
// Momentum
table.cell(overview, 0, 2, 'Momentum', text_color=color.new(i_col, 0))
table.cell(overview, 1, 2, str.format('{0,number,#.##}', rsi1), text_color=rsi1 > prevRsi1 ? color.new(color.lime, 0) : color.new(color.red, 0))
table.cell(overview, 2, 2, str.format('{0,number,#.##}', rsi2), text_color=rsi2 > prevRsi2 ? color.new(color.lime, 0) : color.new(color.red, 0))
table.cell(overview, 3, 2, str.format('{0,number,#.##}', rsi3), text_color=rsi3 > prevRsi3 ? color.new(color.lime, 0) : color.new(color.red, 0))
// Volatility
table.cell(overview, 0, 3, 'Volatility', text_color=color.new(i_col, 0))
table.cell(overview, 1, 3, str.format('{0,number,#.##}', atr1) + '%', text_color=atr1 > prevAtr1 ? color.new(color.lime, 0) : color.new(color.red, 0))
table.cell(overview, 2, 3, str.format('{0,number,#.##}', atr2) + '%', text_color=atr2 > prevAtr2 ? color.new(color.lime, 0) : color.new(color.red, 0))
table.cell(overview, 3, 3, str.format('{0,number,#.##}', atr3) + '%', text_color=atr3 > prevAtr3 ? color.new(color.lime, 0) : color.new(color.red, 0))
// Trend
table.cell(overview, 0, 4, 'Trend', text_color=color.new(i_col, 0))
table.cell(overview, 1, 4, trend1 > prevTrend1 ? 'AL' : 'SAT', text_color=trend1 > prevTrend1 ? color.new(color.lime, 0) : color.new(color.red, 0))
table.cell(overview, 2, 4, trend2 > prevTrend2 ? 'AL' : 'SAT', text_color=trend2 > prevTrend2 ? color.new(color.lime, 0) : color.new(color.red, 0))
table.cell(overview, 3, 4, trend3 > prevTrend3 ? 'AL' : 'SAT', text_color=trend3 > prevTrend3 ? color.new(color.lime, 0) : color.new(color.red, 0))
//} Table
Yer İmleri