OHLC📕 LIBRARY OHLC
🔷 Introduction
This library is a custom library designed to work with real-time bars. It allows to easily calculate OHLC values for any source.
Personally, I use this library to accurately display the highest and lowest values on visual indicators such as my progress bars.
🔷 How to Use
◼ 1. Import the OHLC library into your TradingView script:
import cryptolinx/OHLC/1
- or -
Instead of the library namespace, you can define a custom namespace as alias.
import cryptolinx/OHLC/1 as src
◼ 2. Create a new OHLC source using the `new()` function.
varip mySrc = OHLC.new() // It is required to use the `varip` keyword to init your ``
- or -
If you has set up an alias before.
varip mySrc = src.new()
===
In that case, your `` needs to be `na`, define your object like that
varip mySrc = na
◼ 3. Call the `hydrateOHLC()` method on your OHLC source to update its values:
Basic
float rsi = ta.rsi(close, 14)
mySrc.hydrateOHLC(rsi)
- or -
Inline
rsi = ta.rsi(close, 14).hydrateOHLC(mySrc)
◼ 4. The data is accessible under their corresponding names.
mySrc.open
mySrc.high
mySrc.low
mySrc.close
🔷 Note: This library only works with real-time bars and will not work with historical bars.
Inputs
f_maSelectLibrary "f_maSelect"
Easy to use drop-in facade function to lots of different moving average calculations, including some that are not natively available in PineScript v5 such as Zero-Lag EMA. Simply call f_maSelect(series float serie, simple string ma_type="sma", ma_length=14) instead of a ta.*ma() call and you get access to all MAs offered by PineScript and more.
zema(src, len)
Zero-lag EMA (ZLMA)
Parameters:
src : Input series
len : Lookback period
Returns: Series smoothed with ZLMA
approximate_sma(x, ma_length)
Approximate Standard Moving Average, which substracts the average instead of popping the oldest element, hence losing the base frequency and is why it is approximative. For some reason, this appears to give the same results as a standard RMA
Parameters:
x : Input series.
ma_length : Lookback period.
Returns: Approximate SMA series.
f_maSelect(serie, ma_type, ma_length)
Generalized moving average selector
Parameters:
serie : Input series
ma_type : String describing which moving average to use
ma_length : Lookback period
Returns: Serie smoothed with the selected moving average.
generalized_dev(src, length, avg, lmode)
Generalized deviation calculation: Whereas other Bollinger Bands often just change the basis but not the stdev calculation, the correct way to change the basis is to also change it inside the stdev calculation.
Parameters:
src : Series to use (default: close)
length : Lookback period
avg : Average basis to use to calculate the standard deviation
lmode : L1 or L2 regularization? (ie, lmode=1 uses abs() to cutoff negative values hence it calculates the Mean Absolute Deviation as does the ta.dev(), lmode=2 uses sum of squares hence it calculates the true Standard Deviation as the ta.stdev() function does). See also the research works of everget:
Returns: stdev Standard deviation series
generalized_dev_discount(src, length, avg, lmode, temporal_discount)
Standard deviation calculation but with different probabilities assigned to each bar, with newer bars having more weights en.wikipedia.org
Parameters:
src : Series to use (default: close)
length : Lookback period
avg : Average basis to use to calculate the standard deviation
lmode : L1 or L2 regularization? (ie, lmode=1 uses abs() to cutoff negative values hence it calculates the Mean Absolute Deviation as does the ta.dev(), lmode=2 uses sum of squares hence it calculates the true Standard Deviation as the ta.stdev() function does). See also the research works of everget:
temporal_discount : Probabilistic gamma factor to discount old values in favor of new ones, higher value = more weight to newer bars
Returns: stdev Standard deviation series
median_absdev(src, length, median)
Median Absolute Deviation
Parameters:
src : Input series
length : Lookback period
median : Median already calculated on the input series
Returns: mad, the median absolute deviation value
composite_ticker_cleanerLibrary "composite_ticker_cleaner"
Extract a clean symbol from a composite ticker. E.g., (BINANCE:BTCUSD+KRAKEN:BTCUSD)/2 as input will return BTCUSD or BINANCE:BTCUSD
composite_ticker_cleaner_extract_first(symbol, keepexchange)
Extract the first symbol out of the supplied string (usually ticker.standard(syminfo.tickerid) )
Parameters:
symbol : string input string to search in
keepexchange : bool (optional) Keep exchange in the returned ticker? By default, we only return the symbol without the exchange.
Returns: first occurrence of a symbol
composite_ticker_cleaner_extract_first(keepexchange)
Extract the first symbol out of the current tickerid (as provided by ticker.standard(syminfo.tickerid) )
Parameters:
keepexchange : bool (optional) Keep exchange in the returned ticker? By default, we only return the symbol without the exchange.
Returns: first occurrence of a symbol in the current tickerid
This is inspired by the work I did on this indicator:
I needed a similar functionality in another script, so instead of duplicating code, I thought generalizing the process in a library could be helpful for me and others, and will be easier to maintain and upgrade with new features if I need to.
string_utilsLibrary "string_utils"
Collection of string utilities that can be used to replace sub-strings in a string and string functions
that are not part of the standard library.
This a more simple replacement of my previous string_variables library since it uses types for better
performance due to data locality and methods that give a more intuitive API.
SessionInBoxesProLibrary "SessionInBoxesPro"
get_time_by_bar(bar_count)
Parameters:
bar_count
get_positions_func(sessiontime_, duration_)
Parameters:
sessiontime_
duration_
get_period(_session, _start, _lookback)
Parameters:
_session
_start
_lookback
is_start(_session)
Parameters:
_session
is_end(_session)
Parameters:
_session
draw_progress(_show, _session, _is_started, _is_ended, _color, _bottom, _delete_history)
Parameters:
_show
_session
_is_started
_is_ended
_color
_bottom
_delete_history
draw_label(_show, _session, _is_started, _color, _top, _bottom, _text, _delete_history, i_label_chg, i_label_size, i_label_position, i_tz, i_label_format_day)
Parameters:
_show
_session
_is_started
_color
_top
_bottom
_text
_delete_history
i_label_chg
i_label_size
i_label_position
i_tz
i_label_format_day
draw_fib(_show, _session, _is_started, _color, _top, _bottom, _level, _width, _style, _is_extend, _delete_history)
Parameters:
_show
_session
_is_started
_color
_top
_bottom
_level
_width
_style
_is_extend
_delete_history
get_op_stricts(_session, _is_started, top, bottom, i_o_minutes)
Parameters:
_session
_is_started
top
bottom
i_o_minutes
draw_op(_show, _session, _is_started, _color, top, bottom, _is_extend, _delete_history, i_o_minutes, i_o_opacity)
Parameters:
_show
_session
_is_started
_color
top
bottom
_is_extend
_delete_history
i_o_minutes
i_o_opacity
get_pm_stricts(_show, _show_pm, tf, ctf, _is_started)
Parameters:
_show
_show_pm
tf
ctf
_is_started
draw_pm(_show, _show_pm, tf, ctf, _is_started, _is_ended, _delete_history, _color)
Parameters:
_show
_show_pm
tf
ctf
_is_started
_is_ended
_delete_history
_color
draw_market(_show, _session, _is_started, _color, btr, _top, _bottom, _extend, _is_extend, _delete_history, i_sess_border_style, i_sess_border_width, i_sess_bgopacity)
Parameters:
_show
_session
_is_started
_color
btr
_top
_bottom
_extend
_is_extend
_delete_history
i_sess_border_style
i_sess_border_width
i_sess_bgopacity
draw(_show, _show_pm, pm_tf, ctf, _session, _color, btr, _label, _extend, _show_fib, _show_op, i_label_chg, i_label_size, i_label_position, i_o_minutes, i_o_opacity, i_sess_border_style, i_sess_border_width, i_sess_bgopacity, i_show_history, i_show_closed, i_label_show, i_f_linewidth, i_f_linestyle, top, bottom, i_tz, i_label_format_day)
Parameters:
_show
_show_pm
pm_tf
ctf
_session
_color
btr
_label
_extend
_show_fib
_show_op
i_label_chg
i_label_size
i_label_position
i_o_minutes
i_o_opacity
i_sess_border_style
i_sess_border_width
i_sess_bgopacity
i_show_history
i_show_closed
i_label_show
i_f_linewidth
i_f_linestyle
top
bottom
i_tz
i_label_format_day
UtilitiesLibrary "Utilities"
My utility functions library.
toPips(_v)
Convert price to pips.
Parameters:
_v : Price
Returns: Pips
toPrice(_p)
Convert pips to price.
Parameters:
_p
Returns: Price
price_range(_a, _b)
The difference will be returned.
Parameters:
_a
_b : @return Price as positive number
get_day(_n, _lang)
Get the day of the week
Parameters:
_n : Number of day of week
_lang : en or ja
source(_name)
TODO: add function description here
Parameters:
_name
Returns: TODO: add what function returns
clear_lines(_arr, _min)
Deletes the lines included in the array.
Parameters:
_arr : Array of lines
_min : Deletes the lines included in the array.
clear_labels(_arr, _min)
Deletes the labels included in the array.
Parameters:
_arr : Array of labels
_min : Deletes the labels included in the array.
clear_boxes(_arr, _min)
Deletes the boxes included in the array.
Parameters:
_arr : Array of boxes
_min : Deletes the boxes included in the array.
TurntLibraryLibrary "TurntLibrary"
Collection of functions created for simplification/easy referencing. Includes variations of moving averages, length value oscillators, and a few other simple functions based upon HH/LL values.
ma(source, length, type)
Apply a moving average to a float value
Parameters:
source : Value to be used
length : Number of bars to include in calculation
type : Moving average type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Smoothed value of initial float value
curve(src, len, lb1, lb2)
Exaggerates curves of a float value designed for use as an exit signal.
Parameters:
src : Initial value to curve
len : Number of bars to include in calculation
lb1 : (Default = 1) First lookback length
lb2 : (Default = 2) Second lookback length
Returns: Curved Average
fragma(src, len, space, str)
Average of a moving average and the previous value of the moving average
Parameters:
src : Initial float value to use
len : Number of bars to include in calculation
space : Lookback integer for second half of average
str : Moving average type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Fragmented Average
maxmin(x, y)
Difference of 2 float values, subtracting the lowest from the highest
Parameters:
x : Value 1
y : Value 2
Returns: The +Difference between 2 float values
oscLen(val, type)
Variable Length using a oscillator value and a corresponding slope shape ("Incline",Decline","Peak","Trough")
Parameters:
val : Oscillator Value to use
type : Slope of length curve ("Incline",Decline","Peak","Trough")
Returns: Variable Length Integer
hlAverage(val, smooth, max, min, type, include)
Average of HH,LL with variable lengths based on the slope shape ("Incline","Decline","Trough") value relative to highest and lowest
Parameters:
val : Source Value to use
smooth
max
min
type
include : Add "val" to the averaging process, instead of more weight to highest or lowest value
Returns: Variable Length Average of Highest Lowest "val"
pct(val)
Convert a positive float / price to a percentage of it's highest value on record
Parameters:
val : Value To convert to a percentage of it's highest value ever
Returns: Percentage
hlrange(x, len)
Difference between Highest High and Lowest Low of float value
Parameters:
x : Value to use in calculation
len : Number of bars to include in calculation
Returns: Difference
midpoint(x, len, smooth)
The average value of the float's Highest High and Lowest Low in a number of bars
Parameters:
x : Value to use in calculation
len
smooth : (Default=na) Optional smoothing type to use ("SMA","EMA","RMA","WMA","VWAP","SWMA","LRC")
Returns: Midpoint
WelcomeUDT█ OVERVIEW
This is a simplest example of user-defined types (UDT) or objects , which simplify as alternative to hello world.
█ CREDITS
Tradingview
█ USAGE
These are the types used during initializations, commonly variables.
export type Settings
int bar
float price
string phrase
...
Example of library function to print out label.
export printLabel(Settings setup) =>
if setup.variable
var label lab = na
label.delete(lab)
lab := label.new(setup.bar, setup.price, setup.phrase, color = setup.bg)
else
label.new(setup.bar, setup.price, setup.phrase, color = setup.bg)
Usage of types
Settings setup = Settings.new(bar_index , priceInput, phraseInput, colorInput, variableInput)
Alternative way to write types
Settings setup = Settings.new(
bar = bar_index ,
price = priceInput,
phrase = phraseInput,
variable = variableInput)
Usage of types into custom function / library function.
printLabel(setup)
printLabel(Settings)
Print out label
Parameters:
Settings : types
Returns: Label object
Settings
Initialize type values
Fields:
bar : X position for label
price : Y position for label
phrase : Text for label
bg : Color for label
variable : Boolean for enable new line and delete line
ReduceSecurityCallsLibrary "ReduceSecurityCalls"
This library allows you to reduce the number of request.security calls to 1 per symbol per timeframe. Script provides example how to use it with request.security and possible optimisation applied to htf data call.
This data can be used to calculate everything you need and more than that (for example you can calculate 4 emas with one function call on mat_out).
ParseSource(mat_outs, o)
Should be used inside request.security call. Optimise your calls using timeframe.change when htf data parsing! Supports up to 5 expressions (results of expressions must be float or int)
Parameters:
mat_outs : Matrix to be used as outputs, first value is newest
o : Please use parametres in the order they specified (o should be 1st, h should be 2nd etc..)
Returns: outs array, due to weird limitations do not try this :matrix_out = matrix.copy(ParseSource)
Encoder DecoderLibrary "EncoderDecoder"
Simple example how to encode some values into float number and then decode it back to original values
f_calctype()
Encode parameter
Returns: encoded value
f_calctype()
Decode parameter
Returns: decoded value
f_srctype()
Encode parameter
Returns: encoded value
f_srctype()
Decode parameter
Returns: decoded value
f_encode(calc_type, src_type, tf, length)
Encodes 4 paramters into float number
Parameters:
calc_type : 1st paramter to encode (its values defined in f_calctype functions) max number of values that can be encoded = 100
src_type : 2nd paramter to encode (its values defined in f_src_type functions) max number of values that can be encoded = 100
tf : 3rd paramter to encode (may be int number with format.price precision length!)
length : 4th paramter to encode (may be any int number)
Returns: float number
f_decode()
Decodes 4 paramters into tuple
Returns: tuple
intoLibrary "into"
convert literals by type,
Same-types left in for bulk reasons.
TODO: Expand Types
b(string)
Convert string to bool.
Parameters:
string : val A string value.
Returns: Bool.
b(bool)
Pass Bool/bool
Parameters:
bool :
Returns: Bool.
b(float)
Convert Float (True if exists and not 0)
Parameters:
float : val A float value.
Returns: Bool.
b(int)
Convert integer (True if exists and not 0)
Parameters:
int : val An integer value.
Returns: Bool.
f(bool)
Convert bool to float.
Parameters:
bool : val A boolean value.
Returns: Float.
f(string, int)
Convert with decimal
Parameters:
string : val A string value.
int : decimals Decimal places. def = 6
Returns: Float.
f(float, int)
Convert float bypass with decimals
Parameters:
float : val A float value.
int : decimals Decimal places. def = 6
Returns: Float.
f(int)
Convert integer to float.
Parameters:
int : val An integer value.
Returns: Float.
i(bool)
Convert bool to int.
Parameters:
bool : val A boolean value.
Returns: Int.
i(string)
Convert string number to int.
Parameters:
string : val A string value.
Returns: Int.
i(float)
Convert float to int.
Parameters:
float : val A float value.
Returns: Int.
i(int)
Convert int to int.
Parameters:
int : val An int value.
Returns: Int.
s(bool)
Convert bool value to string.
Parameters:
bool : val A boolean value.
Returns: String.
s(str)
bypass string
Parameters:
str : val A string value.
Returns: String.
s(float)
Convert float value to string.
Parameters:
float : val A float value.
Returns: String.
s(int)
Convert int value to string.
Parameters:
int : val An integer value.
Returns: String.
s(val)
Array Convert Each Item
Parameters:
val : Array Input (Str,Bool,Int,Float)
Returns: String.
s(val)
Array Convert Each Item
Parameters:
val : Array Input (Str,Bool,Int,Float)
Returns: String.
s(val)
Array Convert Each Item
Parameters:
val : Array Input (Str,Bool,Int,Float)
Returns: String.
s(val)
Array Convert Each Item
Parameters:
val : Array Input (Str,Bool,Int,Float)
Returns: String.
String to NumberA library that exposes a method to translate strings to numbers. Adapted from MichelT 's String to Number indicator.
EconomicCalendarLibrary "EconomicCalendar"
This library is a data provider for important dates and times from the Economic Calendar.
events()
Returns the list of dates supported by this library as a string array.
Returns: array : Names of events supported by this library
fomcMeetings()
Gets the FOMC Meeting Dates. The FOMC meets eight times a year to determine the course of monetary policy. The FOMC announces its decision on the federal funds rate at the conclusion of each meeting and also issues a statement that provides information on the economic outlook and the Committee's assessment of the risks to the outlook.
Returns: array : FOMC Meeting Dates as timestamps
fomcMinutes()
Gets the FOMC Meeting Minutes Dates. The FOMC Minutes are released three weeks after each FOMC meeting. The Minutes provide information on the Committee's deliberations and decisions at the meeting.
Returns: array : FOMC Meeting Minutes Dates as timestamps
ppiReleases()
Gets the Producer Price Index (PPI) Dates. The Producer Price Index (PPI) measures the average change over time in the selling prices received by domestic producers for their output. The PPI is a leading indicator of CPI, and CPI is a leading indicator of inflation.
Returns: array : PPI Dates as timestamps
cpiReleases()
Gets the Consumer Price Index (CPI) Rekease Dates. The Consumer Price Index (CPI) measures changes in the price level of a market basket of consumer goods and services purchased by households. The CPI is a leading indicator of inflation.
Returns: array : CPI Dates as timestamps
csiReleases()
Gets the CSI release dates. The Consumer Sentiment Index (CSI) is a survey of consumer attitudes about the economy and their personal finances. The CSI is a leading indicator of consumer spending.
Returns: array : CSI Dates as timestamps
cciReleases()
Gets the CCI release dates. The Conference Board's Consumer Confidence Index (CCI) is a survey of consumer attitudes about the economy and their personal finances. The CCI is a leading indicator of consumer spending.
Returns: array : CCI Dates as timestamps
nfpReleases()
Gets the NFP release dates. Nonfarm payrolls is an employment report released monthly by the Bureau of Labor Statistics (BLS) that measures the change in the number of employed people in the United States.
Returns: array : NFP Dates as timestamps
LibBacktestingDayRangeLibrary "LibBacktestingDayRange"
TODO: add library description here
import Nut_Satit/CalulateWinLoss/version as backtest
rangdate(startDate, finishDate)
TODO: add function description here
Parameters:
startDate : TODO: add parameter startDate description here
finishDate : TODO: add parameter finishDate description here
Returns: TODO: add what function returns
time_cond : TODO: insert variable and buy or sell condition
catchChecksLibrary "catchChecks"
Type Check for Function Builders to allow Single item to be
passed in, and determine what to do with the item, ie: need an x value?
function that allows label, line, box, float, or even a string..
check item type? string ? 'str.tonumber(_item)' can be in the same
switch as a 'line.get_price(_item, bar_index)' both outputting float
or for pulling a value from simple, array, or matrix, one function
that can switch between them. reduce overhead of many functions.
there are many ways to use this tool, the simplest may be
string/floats on one switch or grabbing colors from line/fill/label
please Share any great recipes you come up with!
typeIs(_temp, _doMeth)
Input anything..
Determine what it is.
Parameters:
_temp : (any) Matrix, Array, or Simple Item
_doMeth : (bool) True for M/A/S , false for int/float/string.. etc..
Returns: (string) Type of item checked. ('bool' .. or 'array'.. etc..)
CyclicRsiLib█ OVERVIEW
This library is complementary for Cyclic RSI High Low With Noise Filter.
█ CREDITS
LoneSomeTheBlue
WhenToTrade
AlertFrequency()
: AlertFrequency
Parameters:
: : _string
Returns: : _freq
CyclicRSI()
: CyclicRSI
Parameters:
: : _source, _length, _expression
Returns: : osc
Credits to WhenToTrade
AddToZigzag()
: AddToZigzag
Parameters:
: : _id, value, max_array_size
Returns: : array.unshift, array.pop
Credits to LonesomeTheBlue
UpdateZigzag()
: UpdateZigzag
Parameters:
: : _id, value, max_array_size, dir
Returns: : AddToZigzag, array.set
Credits to LonesomeTheBlue
BoolZigzag()
: BoolZigzag
Parameters:
: : ph, pl, dirchanged, _id, dir
Returns: : AddToZigzag, UpdateZigzag
Credits to LonesomeTheBlue
NoiseSwitch()
: NoiseSwitch
Parameters:
: : _string, _id
Returns: : FilterNoise
LineGray()
: LineGray
Parameters:
: : _id
Returns: : LineGray
LabelDir()
: LabelDir
Parameters:
: : _id, _string, _color, _float
Returns: : LabelDir
TernaryLabel()
: TernaryLabel
Parameters:
: : _dir, _bool1, _bool2, _string1, _string2
Returns: : str_label
TernaryColor()
: TernaryColor
Parameters:
: : _dir, _bool1, _bool2
Returns: : col_label
srcCalcLibrary "srcCalc"
Provides functions for converting input strings 'open','high','low','close','hl2','hlc3','ohlc4','hlcc4' to corresponding source values.
get_src(src)
Converts string to source float value
Parameters:
src : String to use (`close` is used if no argument is supplied).
Returns: Returns the float value of the string
PriceTimeInteractive█ OVERVIEW
This library was intended to Get price of given time.input
█ CREDITS
Credits to TradingView for CAGR Custom Range.
█ FUNCTIONS
ohlc_time()
: Get OHLC price of given time.input
Parameters:
: : Time (t) must be using time.input
Returns: : OHLC
hlc_time()
: Get HLC price of given time.input
Parameters:
: : Time (t) must be using time.input
Returns: : HLC
hl_time()
: Get HL price of given time.input
Parameters:
: : Time (t) must be using time.input
Returns: : HL
"Swap" - Bool/Position/Value : Array / Matrix / Var AutoswapLibrary "swap"
Side / Boundary Based All Types Swapper
- three automagical types for Arrays, Matrixes, and Variables
-- no signal : Long/ Short position autoswap
-- true / false : Boolean based side choice
-- Src / Thresh : if source is above or below the threshold
- two operating modes for variables, Holding mode only for arrays/matrixes
-- with two items, will automatically change between the two caveat is it does not delete table/box/line(fill VAR items automatically)
-- with three items, a neutral is available for NA input or neutral
- one function name for all of them. One import name that's easy to type/remember
-- make life easy for your conditional items.
side(source, thresh, _a, _b, _c)
side Change outputs based on position or a crossing level
Parameters:
source : (float) OPTIONAL value input
thresh : (float) OPTIONAL boundary line to cross
_a : (any) if Long/True/Above
_b : (any) if Short/False/Below
_c : (any) OPTIONAL NOT FOR MTX OR ARR... Neutral Item, if var/varip on a/b it will leave behind, ie, a table or box or line will not erase , if it's a varip you're sending in.
Returns: first, second, or third items based on input conditions
Please notify if bugs found.
Thanks.
external_input_utilsLibrary "external_input_utils"
Collection of external input utilities for conversion and other hacky functions
str_to_src(value) str_to_src - Convert the string value to the coresponding source series. It can be used to limit the "input.source" choices provided to the end user.
The most interesting part is that it can be used to overcome the "one input.source call limitation" for external inputs to your script
Parameters:
value : - The string equivalent to the source to be converted
Returns: series of the coresponding source
eval_cond(input, operator, value, defval) eval_cond - Evaluate the condition given an operator
Parameters:
input : - The input to be compared with. It can be an external input or a regular one
operator : - The string operator that describe the coparison operation
value : - The value to compare with the input. This can be a serries or a constant
defval : - The boolean value to return when 'noop' is selected
Returns: series of bool the result of the operation evaluation
Price Displacement - Candlestick (OHLC) CalculationsA Magical little helper friend for Candle Math.
When composing scripts, it is often necessary to manipulate the math around the OHLC. At times, you want a scalar (absolute) value others you want a vector (+/-). Sometimes you want the open - close and sometimes you want just the positive number of the body size. You might want it in ticks or you might want it in points or you might want in percentages. And every time you try to put it together you waste precious time and brain power trying to think about how to properly structure what you're looking for. Not to mention it's normally not that aesthetically pleasing to look at in the code.
So, this fixes all of that.
Using this library. A function like 'pd.pt(_exp)' can call any kind of candlestick math you need. The function returns the candlestick math you define using particular expressions.
Candle Math Functions Include:
Points:
pt(_exp) Absolute Point Displacement. Point quantity of given size parameters according to _exp.
vpt(_exp) Vector Point Displacement. Point quantity of given size parameters according to _exp.
Ticks:
tick(_exp) Absolute Tick Displacement. Tick quantity of given size parameters according to _exp.
vtick(_exp) Vector Tick Displacement. Tick quantity of given size parameters according to _exp.
Percentages:
pct(_exp, _prec) Absolute Percent Displacement. (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
vpct(_exp, _prec) Vector Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Expressions You Can Use with Formulas:
The expressions are simple (simple strings that is) and I did my best to make them sensible, generally using just the ohlc abreviations. I also included uw, lw, bd, and rg for when you're just trying to pull a candle component out. That way you don't have to think about which of the ohlc you're trying to get just use pd.tick("uw") and now the variable is assigned the length of the upper wick, absolute value, in ticks. If you wanted the vector in pts its pd.vpt("uw"). It also makes changing things easy too as I write it out.
Expression List:
Combinations
"oh" = open - high
"ol" = open - low
"oc" = open - close
"ho" = high - open
"hl" = high - low
"hc" = high - close
"lo" = low - open
"lh" = low - high
"lc" = low - close
"co" = close - open
"ch" = close - high
"cl" = close - low
Candle Components
"uw" = Upper Wick
"bd" = Body
"lw" = Lower Wick
"rg" = Range
Pct() Only
"scp" = Scalar Close Position
"sop" = Scalar Open Position
"vcp" = Vector Close Position
"vop" = Vector Open Position
The attributes are going to be available in the pop up dialogue when you mouse over the function, so you don't really have to remember them. I tried to make that look as efficient as possible. You'll notice it follows the OHLC pattern. Thus, "oh" precedes "ho" (heyo) because "O" would be first in the OHLC. Its a way to help find the expression you're looking for quickly. Like looking through an alphabetized list for traders.
There is a copy/paste console friendly helper list in the script itself.
Additional Notes on the Pct() Only functions:
This is the original reason I started writing this. These concepts place a rating/value on the bar based on candle attributes in one number. These formulas put a open or close value in a percentile of the bar relative to another aspect of the bar.
Scalar - Non-directional. Absolute Value.
Scalar Position: The position of the price attribute relative to the scale of the bar range (high - low)
Example: high = 100. low = 0. close = 25.
(A) Measure price distance C-L. How high above the low did the candle close (e.g. close - low = 25)
(B) Divide by bar range (high - low). 25 / (100 - 0) = .25
Explaination: The candle closed at the 25th percentile of the bar range given the bar range low = 0 and bar range high = 100.
Formula: scp = (close - low) / (high - low)
Vector = Directional.
Vector Position: The position of the price attribute relative to the scale of the bar midpoint (Vector Position at hl2 = 0)
Example: high = 100. low = 0. close = 25.
(A) Measure Price distance C-L: How high above the low did the candle close (e.g. close - low = 25)
(B) Measure Price distance H-C: How far below the high did the candle close (e.g. high - close = 75)
(C) Take Difference: A - B = C = -50
(D) Divide by bar range (high - low). -50 / (100 - 0) = -0.50
Explaination: Candle close at the midpoint between hl2 and the low.
Formula: vcp = { / (high - low) }
Thank you for checking this out. I hope no one else has already done this (because it took half the day) and I hope you find value in it. Be well. Trade well.
Library "PD"
Price Displacement
pt(_exp) Absolute Point Displacement. Point quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Point size of given expression as an absolute value.
vpt(_exp) Vector Point Displacement. Point quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Point size of given expression as a vector.
tick(_exp) Absolute Tick Displacement. Tick quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Tick size of given expression as an absolute value.
vtick(_exp) Vector Tick Displacement. Tick quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Tick size of given expression as a vector.
pct(_exp, _prec) Absolute Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Parameters:
_exp : (string) Expression
_prec : (int) Overload - Place value precision definition
Returns: Percent size of given expression as decimal.
vpct(_exp, _prec) Vector Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Parameters:
_exp : (string) Expression
_prec : (int) Overload - Place value precision definition
Returns: Percent size of given expression as decimal.
honest personal libraryLibrary "honestpersonallibrary"
thestratnumber() this will return the number 1,2 or 3 using the logic from Rob Smiths #thestrat which uses these type of bars for setups
getBodySize() Gets the current candle's body size (in POINTS, divide by 10 to get pips)
Returns: The current candle's body size in POINTS
getTopWickSize() Gets the current candle's top wick size (in POINTS, divide by 10 to get pips)
Returns: The current candle's top wick size in POINTS
getBottomWickSize() Gets the current candle's bottom wick size (in POINTS, divide by 10 to get pips)
Returns: The current candle's bottom wick size in POINTS
getBodyPercent() Gets the current candle's body size as a percentage of its entire size including its wicks
Returns: The current candle's body size percentage
strictBearPinBar(float, float) This it to find pinbars with a very long wick compared to the body that are bearish
Parameters:
float : minTopMulitplier (default=4) The minimum number of times that the top wick has to be bigger than the candle body size
float : maxBottomMultiplier (default=2) The maximum number of times that the bottom wick can be bigger than the candle body size
Returns: a bool function true if current candle is withing the parameters
strictBullPinBar(float, float) This it to find pinbars with a very long wick compared to the body that are bearish
Parameters:
float : minTopMulitplier (default=4) The minimum number of times that the top wick has to be bigger than the candle body size
float : maxBottomMultiplier (default=2) The maximum number of times that the bottom wick can be bigger than the candle body size
Returns: a bool function true if current candle is withing the parameters
Cayoshi_LibraryLibrary "Cayoshi_Library"
fungtion show win loss and Netprofit Show
Library สำหรับเรียกใช้
1.Win_Loss_Show() การแสดง แพ้ ชนะ
2.NetProfit_Show() การแสดงผล Backtest
3.Count_Bar_Back_Test() กำหนดระยะเวลา หรือ แท่งบาร์ในการ Backtest