TradingView
JayRogers
18 de Mar de 2021 13:24

Example - HTF Values Without 'Security()' 

Euro Fx/U.S. DollarFXCM

Descrição

This is an example of how to reference higher timeframe data without the
need for a 'security()' call.

I have attempted to create the function example:
f_insecurity()

with the purpose of wrapping up and pumping out all common relevent HTF
price data that's needed for your everyday indicators in a reliable fashion.

Notas de Lançamento

  • Updated to remove potential repainting confusion with:
    security()
  • Added ability to toggle the security() comparison overlay on and off.


..apologies for any confusion regarding the previous repainting option, it was intended for debugging purposes only at the time of writing.

Cheers - Jay.

Notas de Lançamento

  • Cleaned up self-referencing ternary operations - there was no need to reference 'previous' values of self, just 'active' self.
  • Added 'nz()' conversion checks where they might be necessary.
  • Removed redundant bar-counting mechanic.
  • Cleaned up some of the code comments.
Comentários
theheirophant
Well done mate, its great to see you back in action
JayRogers
@theheirophant, Just re-learning pinescript V4, and trying to spread a little love in the process :)
ckppmarathe
How to get volume data of HTF?

how to calculate ATR of HTF using this function?
Nuno_R
Very useful Thank you.

is it possible to reference higher timeframe data such as stochastic... with this function?
JayRogers
@Nuno_R, Unfortunately no, this function is only directly useful to ascertain HTF OHLC data. However, you could create an array to store each new value in order, and then use a custom function to calculate stoch etc. with results. I will bear this in mind for creating an update or extension to the script in the future.
Nuno_R
@JayRogers, thank you
It will be great to have an update or extension to the script
Nuno_R
@JayRogers, is it possible to add this in your function for the stochastic ?

// Stochastic
mySto := 100 * (_priorClose - lowest(_priorLow, 20)) / (highest(_priorHigh, 20) - lowest(_priorLow, 20))
k := sma(mySto, 3)
JayRogers
@Nuno_R, I will not add it to the function directly, but it could be included as a sample use-case when i get around to updating it with array functionality.
Nuno_R
@JayRogers,

is it possible to use the function in a screener?
JayRogers
@Nuno_R, Yes, but you would have to pull the initial lower timeframe OHLC data using `security` to feed into the `f_insecurity` function, which is fine i guess? Kinda defeats the purpose a little bit? XD
Mais