RicardoSantos

[RS]Temporal Median Price V1

EXPERIMENTAL: previous custom time window median price and current time window open price in a neat package :p
(JeanLouisHardy) added option for bar count system, also added a donchian average.
Remove from Favorite Scripts Add to Favorite Scripts
//@version=2
study(title='[RS]Temporal Median Price V1', shorttitle='TMP', overlay=true)
//  ||  Functions:
f_donchian(_window)=>avg(highest(_window), lowest(_window))
//  ||-----------------------------------------------------------------------------------------------------------------------------------------------------------||
USE_TF_OR_BAR = input(title='Use timeframe or bar count based system?', type=bool, defval=true)
//  ||  Timeframe based:
timewindow = input("3M")
topen = not USE_TF_OR_BAR ? na : security(tickerid, timewindow, open)
tmedian = not USE_TF_OR_BAR ? na : security(tickerid, timewindow, hl2[1])
plot(title='', series=tmedian, color=(tmedian != tmedian[1] ? na : black), linewidth=2)
plot(title='', series=topen, color=(topen != topen[1] ? na : black), linewidth=1)
//  ||  
window = input(title='Time window in bars:', defval=15)

counter = USE_TF_OR_BAR ? na : na(counter[1]) ? 0 : counter[1] >= window ? 0 : change(n) != 0 ? counter[1] + 1 : counter[1]

m_open = USE_TF_OR_BAR ? na : na(m_open[1]) ? open : counter == 0 ? sma(open, window) : m_open[1]
m_hl2 = USE_TF_OR_BAR ? na : na(m_hl2[1]) ? hl2 : counter == 0 ? sma(hl2[1], window) : m_hl2[1]
m_donchian = USE_TF_OR_BAR ? na : na(m_donchian[1]) ? hl2 : counter == 0 ? f_donchian(window) : m_donchian[1]
plot(title='', series=m_open, color=change(m_open)!=0?na:black)
plot(title='', series=m_hl2, color=change(m_hl2)!=0?na:blue)
plot(title='', series=m_donchian, color=change(m_donchian)!=0?na:red)
United States
United Kingdom
India
Deutschland
France
España
Italia
Polska
Türkiye
Россия
Brasil
Indonesia
Malaysia
Việt Nam
日本
한국
简体
繁體
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing My Support Tickets Priority Support Contact Support Ideas Published Followers Following Private Messages Chat Sign Out