nazomobile

libHTF[without request.security()]

nazomobile Aktualisiert   
Library "libHTF"
libHTF: use HTF values without request.security()
This library enables to use HTF candles without request.security().

Basic data structure
Using <array> to access values in the same manner as series variable.
The last member of HTF array is always latest current TF's data.
If new bar in HTF(same as last bar closes), new member is pushed to HTF array.
2nd from the last member of HTF array is latest fixed(closed) bar.

HTF: How to use
1. set TF
tf_higher() function selects higher TF. TF steps are ("1","5","15","60","240","D","W","M","3M","6M","Y").
example:
tfChart = timeframe.period
htf1 = tf_higher(tfChart)

2. set HTF matrix
htf_candle() function returns 1 bool and 1 matrix.
bool is a flag for start of new candle in HTF context.
matrix is HTF candle data(0:open,1:time_open,2:close,3:time_close,4:high,5:time:high,6:low,7:time_low).
example:
[b_new_bar1,m1]=htf_candle(htf1)

3. how to access HTF candle data
you can get values using <matrix>.lastx() method.
please be careful, return value is always float evenif it is "time". you need to cast to int time value when using for xloc.bartime.
example:
htf1open=m1.lastx("open")
htf1close=m1.lastx("close")
//if you need to use histrical value.
lastopen=open[1]
lasthtf1open=m1.lastx("open",1)

4. how to store Data of HTF context
you have to use array to store data of HTF context.
array.htf_push() method handles the last member of array. if new_bar in HTF, it push new member. otherwise it set value to the last member.
example:
array a_close=array.new<float>(1,na)
a_close.htf_push(b_new_bar1,m1.lastx("close"))

HTFsrc: How to use
1. how to setup src.
set_src() function is set current tf's src from string(open/high/low/close/hl2/hlc3/ohlc4/hlcc4).
set_htfsrc() function returns src array of HTF candle.

example:
_src="ohlc4"
src=set_src(_src)
htf1src=set_htfsrc(_src,b_new_bar1,m1)
(if you need to use HTF src in series float)
s_htf1src=htf1src.lastx()

HighLow: How to use
1. set HTF arrays
highlow() and htfhighlow() function calculates high/low and return high/low prices and time.
the functions return 1 int and 8arrays.
int is a flag for new high(1) or new low(-1).
arrays are high/low and return high/low data. float for price, int for time.
example
[i_renew,a_high,a_time_high,a_return_high,a_time_return_high,a_low,a_time_low,a_return_low,a_time_return_low] =
highlow()
[i_renew1,a_high1,a_time_high1,a_return_high1,a_time_return_high1,a_low1,a_time_low1,a_return_low1,a_time_return_low1] =
htfhighlow(m1)

2. how to access HighLow data
you can get values using <array>.lastx() method.
example:
if i_renew==1
myhigh=a_high.lastx()
//if you need to use histrical value.
myhigh=a_high.lastx(1)

other functions
functions for HTF candle matrix or HTF src array in this script are
htf_sma()/htf_ema()/htf_rma()
htf_rsi()/htf_rci()/htf_dmi()


method lastx(arrayid, lastindex)
  method like array.last. it returns lastindex from the last member, if parameter is set.
  Namespace types: float
  Parameters:
    arrayid (float)
    lastindex (int): (int) default value is "0"(the last member). if you need to access historical value, increment it(same manner as series vars).
  Returns: float value of lastindex from the last member of the array. returns na, if fail.

method lastx(arrayid, lastindex)
  method like array.last. it returns lastindex from the last member, if parameter is set.
  Namespace types: int
  Parameters:
    arrayid (int)
    lastindex (int): (int) default value is "0"(the last member). if you need to access historical value, increment it(same manner as series vars).
  Returns: int value of lastindex from the last member of the array. returns na, if fail.

method lastx(m, _type, lastindex)
  method for handling htf matrix.
  Namespace types: matrix<float>
  Parameters:
    m (matrix<float>): (matrix<float>) matrix for htf candle.
    _type (string): (string) value type of htf candle:
    lastindex (int): (int) default value is "0"(the last member).
  Returns: (float) value of htf candle. (caution: need to cast float to int to use time values!)

method set_last(arrayid, val)
  method to set a value of the last member of the array. it sets value to the last member.
  Namespace types: float
  Parameters:
    arrayid (float)
    val (float): (float) value to set.
  Returns: nothing

method htf_push(arrayid, b, val)
  method to push new member to htf context. if new bar in htf, it works as push. else it works as set_last.
  Namespace types: float
  Parameters:
    arrayid (float)
    b (bool): (bool) true:push,false:set_last
    val (float): (float) _f the value to set.
  Returns: nothing

method tf_higher(tf)
  method to set higher tf from tf string. TF steps are .
  Namespace types: series string, simple string, input string, const string
  Parameters:
    tf (string): (string) tf string
  Returns: (string) string of higher tf.

htf_candle(_tf, _TZ)
  build htf candles
  Parameters:
    _tf (string): (string) tf string.
    _TZ (string): of timezone. default value is "GMT+3".
  Returns: bool for new bar@htf and matrix for snapshot of htf candle

set_src(_src_type)
  set src.
  Parameters:
    _src_type (string): (string) type of source:
  Returns: (series float) src value

set_htfsrc(_src_type, _nb, _m)
  set htf src.
  Parameters:
    _src_type (string): (string) type of source:
    _nb (bool): (bool) flag of new bar
    _m (matrix<float>): (matrix<float>) matrix for htf candle.
  Returns: (array<float>) array of src value

is_up()

last_is_up()

peak_bottom(_latest, _last)
  Parameters:
    _latest (bool)
    _last (bool)

htf_is_up(_m)
  Parameters:
    _m (matrix<float>)

htf_last_is_up(_m)
  Parameters:
    _m (matrix<float>)

highlow(_b_bartime_price)
  Parameters:
    _b_bartime_price (bool)

htfhighlow(_m, _b_bartime_price)
  Parameters:
    _m (matrix<float>)
    _b_bartime_price (bool)

htf_sma(_a_src, _len)
  Parameters:
    _a_src (float)
    _len (int)

htf_rma(_a_src, _new_bar, _len)
  Parameters:
    _a_src (float)
    _new_bar (bool)
    _len (int)

htf_ema(_a_src, _new_bar, _len)
  Parameters:
    _a_src (float)
    _new_bar (bool)
    _len (int)

htf_rsi(_a_src, _new_bar, _len)
  Parameters:
    _a_src (float)
    _new_bar (bool)
    _len (int)

rci(_src, _len)
  Parameters:
    _src (float)
    _len (int)

htf_rci(_a_src, _len)
  Parameters:
    _a_src (float)
    _len (int)

htf_dmi(_m, _new_bar, _len, _ma_type)
  Parameters:
    _m (matrix<float>)
    _new_bar (bool)
    _len (int)
    _ma_type (string)
Versionshinweise:
Bug fix:
  • bar closing process of htf_candle()
  • typo in highlow() and htfhighlow() sample
Versionshinweise:
Bug fix
  • Incorrect usage of ta.change().
Pine Bibliothek

In echter TradingView-Manier hat der Autor diesen Pine-Code als Open-Source-Bibliothek veröffentlicht, so dass andere Pine-Programmierer aus unserer Community ihn weiterverwenden können. Ein Hoch auf den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Publikationen verwenden, aber die Wiederverwendung dieses Codes in einer Publikation unterliegt den Hausregeln.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie diese Bibliothek nutzen?

Kopieren Sie die folgende Zeile und fügen Sie sie in Ihr Skript ein.