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.
نص برمجي مفتوح المصدر

قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الكود في منشور تحكمه قواعد الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.

هل تريد استخدام هذا النص البرمجي على الرسم البياني؟
//@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)