TradingView
LonesomeTheBlue
21 de Mar de 2020 14:11

Moving Average MTF Live [Experimental] 

Bitcoin / U.S. DollarGemini

Descrição

Hello Everyone,

While using "Security" function for Higher Time Frames (htf) you must accept "Repainting" issue or better you must use previous day data such "security(syminfo.tickerid, 'D', close, lookahead=barmerge.lookahead_on)" that's best normally (or barmerge.lookahead_off). But the problem is (as you can see) it uses previous day data, and this causes latency.

So how to draw LIVE and NON-REPAINTING HTF moving averages?
Until the last candle of higher time frame all is fine and no repaint issue. when it came to last candle of HTF and if we use real data, (because of we can not know the future) while price is changing it starts drawing on each candle of current period without correcting old ones (this is repaint issue). it needs to calculate number of curent time frame candles for higher time frame and must change all points in that period as you can see in the video below.

We have "50 lines" limitation in current Pine version. we hope to have unlimited lines in next versions.

This work is completely experimetal.

btw Thanks to all Pine Platform Developers, They are doing very good job!

Better to watch following video to see how they look like:


P.S. There is no check for Higher time frame, so you should set time frame for HTF accordingly in the options.

Enjoy!
Comentários
edward_Z
Very useful!
dpanday
Interesting..
ahmetk072
Thank you.
Please. Renko bar indicator. ♥
LonesomeTheBlue
@ahmetk072, you are welcome
kaptanylmz
Thank you. You are the man...
LonesomeTheBlue
@kaptanylmz, you are welcome
RambadamDingDong
Thank you LTB!
LonesomeTheBlue
@belaweb2, you are welcome! hope it's usefull for all.
randyfocht91
I came up with the idea of having 2 or more 200 SMA's on the screen as they are important...but for different time frames.
For instance, if you are trading on a 1 minute time frame, probably a 5 min 200 SMA would be helpful.
...and a 15 minute 200 SMA.
However, I could not find a way to do different time frames inside a single indicator or strategy.
Looks like you have done it!!!!
ProfitableTradingTools
Dear LonesomeTheBlue,

I am a big fan of yours and follow your amazing work for quite some time here, although I stopped using this platform because of the exact same reason that motivated you to writhe this script. When I saw this script I was quite happy because it seemed that it solves the deficiency of the "barmerge.lookahead_on" built in variable, which is in my opinion defective here in Tradingview.
I believe Im not the only one here noticing that it is simply incapable of plotting a live higher timeframe plot in realtime, like for example the MT4 charting software does.

I have some very basic pinescript knowledge, so I was able to make an RSI from your script, that plots a realtime RST HTF line, but the issue I am facing now is that it is only helpful from a visual perspective, I can't make it generate actual alerts.
The script:

//@version=4
study("RSI MTF Live Experiment", overlay = false)

src = input(defval=close)
RSIlength = input(defval=2, title="RSI length")
rsi = rsi(src, RSIlength)

tf = input(defval="5", type = input.resolution, title="Timeframe")

// get HTF RSIs
RSIht = security(syminfo.tickerid, tf, rsi, lookahead = true)
RSIcur = security(syminfo.tickerid, tf, rsi, lookahead = false)

// is this last bar?
islast = security(syminfo.tickerid, tf, barstate.islast, lookahead = true)

//if not last bar then draw non-repaint historical RSI
plot(islast ? na : RSIht, color = islast ? na : color.blue, linewidth = 2)

//calculate and keep the beginning of line
lastbar_index = 0
lastbar_index := change(time(tf)) != 0 ? 0 : nz(lastbar_index[1]) + 1

// draw real time higher time frame RSI
line RSI_LIVE = line.new(bar_index, RSIcur, bar_index - lastbar_index, RSIcur, color = color.blue, width = 2)

// delete old lines if it's not the last one in htf periof
if change(time(tf)) == 0
line.delete(RSI_LIVE[1])

// Highlight background when RSI_LIVE above upline or below lowline

//upline = input(50, minval=0, maxval=100, title="Upper Line Value?")
//lowline = input(50, minval=0, maxval=100, title="Lower Line Value?")
//sbh = input(true, title="Show Background Highlights")

//aboveLine = RSI_LIVE > upline ? 1 : 0
//belowLine = RSI_LIVE < lowline ? 1 : 0

//bgcolor(sbh and aboveLine ? color.green : na, transp=70)
//bgcolor(sbh and belowLine ? color.red : na, transp=70)

Do you perhaps know how the "RSI_LIVE" line variable in the script above could be converted into something that could be used for an actual alert?
Like for example, when the RSI_LIVE line crosses above 50, to color the background to green or give an actual buy alert?
Thank you for reading my comment.
Wishing you a great day!
Mais