 Library "distance_percentile"
Collection of types and functions that can be used for the calculation of the percentage of a distance from a barrier price using several methods. Methods supported are percentagewise (PERC), atr-based (ATR), local extrema ( LOC ), tick-based (TICKS) and risk reward ratio (RR)

getHigherDistPerc( dist , curr)
getHigherDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a downwards moving potential
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr, local extrema, risk reward percent and step count to be used if needed by the method
Returns: the distance percentage of the price

getLowerDistPerc( dist , curr)
getLowerDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with an upwards moving potential
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr, local extrema, risk reward percent and step count to be used if needed by the method
Returns: the distance percentage of the price

getLowerStopLossDistPerc( dist , stepTrail, curr)
getLowerStopLossDistPerc - Calculate the distance of the candidate long stop loss price from the barrier (percentagewise) with an upwards moving potential
Parameters:
dist: - The settings of the distance method
stepTrail: - The settings of the step trailing mode
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr, local extrema, risk reward percent and step count to be used if needed by the method
Returns: the distance percentage of the stop loss price

getHigherStopLossDistPerc( dist , stepTrail, curr)
getHigherStopLossDistPerc - Calculate the distance of the candidate short stop loss price from the barrier (percentagewise) with a downward moving potential
Parameters:
dist: - The settings of the distance method
stepTrail: - The settings of the step trailing mode
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr, local extrema, risk reward percent and step count to be used if needed by the method
Returns: the distance percentage of the stop loss price

getHigherTakeProfitDistPerc( dist , curr)
getHigherTakeProfitDistPerc - Calculate the distance of the candidate long take profit price from the barrier (percentagewise)
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr, local extrema, risk reward percent and step count to be used if needed by the method
Returns: the distance percentage of the take profit price

getLowerTakeProfitDistPerc( dist , curr)
getLowerTakeProfitDistPerc - Calculate the distance of the candidate short take profit price from the barrier (percentagewise)
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr, local extrema, risk reward percent and step count to be used if needed by the method
Returns: the distance percentage of the take profit price

locSettings
Fields:
marMethod
len
marMul

restrictSettings
Fields:
minDistEnabled
maxDistEnabled
minDistPerc
maxDistPerc

distSettings
Fields:
method
perc
atrMul
loc
ticks
rRRatio
restrict

currData
Fields:
barrier
atr
extrema
rRPerc
stepCount
Notas de Lançamento:
v2
Add support for fixed profit distance
Notas de Lançamento:
v3

getStepedDist(dist, step, count)
getStepedDist - Calculate the steped distance settings
Parameters:
dist: - The settings of the distance method
step: - The settings of the steped distance method
count: - The current step count
Returns: - The steped distance settings

getHigherOptimisticDistPerc(dist, curr, extrema)
getHigherOptimisticDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a downwards moving potential
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema
Returns: - The distance percentage of the price

getLowerOptimisticDistPerc(dist, curr, extrema)
getLowerOptimisticDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with an upwards moving potential
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema: - The current value of the local extrema
Returns: - The distance percentage of the price

getHigherPessimisticDistPerc(dist, curr, extrema)
getHigherPessimisticDistPerc - Calculate the distance of the candidate long take profit price from the barrier (percentagewise)
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema: - The current value of the local extrema
Returns: - The distance percentage of the take profit price

getLowerPessimisticDistPerc(dist, curr, extrema)
getLowerPessimisticDistPerc - Calculate the distance of the candidate short take profit price from the barrier (percentagewise)
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema: - The current value of the local extrema
Returns: - The distance percentage of the take profit price

Removed:
getHigherDistPerc(dist, curr)
getHigherDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a downwards moving potential

getLowerDistPerc(dist, curr)
getLowerDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with an upwards moving potential

getLowerStopLossDistPerc(dist, stepTrail, curr)
getLowerStopLossDistPerc - Calculate the distance of the candidate long stop loss price from the barrier (percentagewise) with an upwards moving potential

getHigherStopLossDistPerc(dist, stepTrail, curr)
getHigherStopLossDistPerc - Calculate the distance of the candidate short stop loss price from the barrier (percentagewise) with a downward moving potential

getHigherTakeProfitDistPerc(dist, curr)
getHigherTakeProfitDistPerc - Calculate the distance of the candidate long take profit price from the barrier (percentagewise)

getLowerTakeProfitDistPerc(dist, curr)
getLowerTakeProfitDistPerc - Calculate the distance of the candidate short take profit price from the barrier (percentagewise)
Notas de Lançamento:
v4

getLongBiasedDistPerc(dist, curr, extrema)
getLongBiasedDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a long bias
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema
Returns: - The distance percentage of the price

getShortBiasedDistPerc(dist, curr, extrema)
getShortBiasedDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a short bias
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema: - The current value of the local extrema
Returns: - The distance percentage of the price

Removed:
getHigherOptimisticDistPerc(dist, curr, extrema)
getHigherOptimisticDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a downwards moving potential

getLowerOptimisticDistPerc(dist, curr, extrema)
getLowerOptimisticDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with an upwards moving potential

getHigherPessimisticDistPerc(dist, curr, extrema)
getHigherPessimisticDistPerc - Calculate the distance of the candidate long take profit price from the barrier (percentagewise)

getLowerPessimisticDistPerc(dist, curr, extrema)
getLowerPessimisticDistPerc - Calculate the distance of the candidate short take profit price from the barrier (percentagewise)
Notas de Lançamento:
v5
Use lowercase style for library naming

steped_dist(dist, step, count)
steped_dist - Calculate the steped distance settings
Parameters:
dist: - The settings of the distance method
step: - The settings of the steped distance method
count: - The current step count
Returns: - The steped distance settings

long_biased_dist_perc(dist, curr, extrema)
long_biased_dist_perc - Calculate the distance of the candidate price from the barrier (percentagewise) with a long bias
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema
Returns: - The distance percentage of the price

short_biased_dist_perc(dist, curr, extrema)
short_biased_dist_perc - Calculate the distance of the candidate price from the barrier (percentagewise) with a short bias
Parameters:
dist: - The settings of the distance method
curr: - The current values of the barier price that will be used as a reference for the distance percentage calculation and other runtime values of atr and risk reward percent to be used if needed by the method
extrema: - The current value of the local extrema
Returns: - The distance percentage of the price

Removed:
getStepedDist(dist, step, count)
getStepedDist - Calculate the steped distance settings

getLongBiasedDistPerc(dist, curr, extrema)
getLongBiasedDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a long bias

getShortBiasedDistPerc(dist, curr, extrema)
getShortBiasedDistPerc - Calculate the distance of the candidate price from the barrier (percentagewise) with a short bias
Notas de Lançamento:
v6
fix typo
stepped_dist(dist, step, count)
stepped_dist - Calculate the stepped distance settings
Parameters:
dist: - The settings of the distance method
step: - The settings of the stepped distance method
count: - The current step count
Returns: - The stepped distance settings

Removed:
steped_dist(dist, step, count)
steped_dist - Calculate the steped distance settings
Notas de Lançamento:
v7
Notas de Lançamento:
Notas de Lançamento:
v9
move extrema into the auxiliary data and make it optional
Notas de Lançamento:
v10
add a flag to the settings to indicate whether or not the extrema should be higher than the barrier or not
Notas de Lançamento:
v11
• More accurate (and complex) commission calculations for PROF method
• Add the ability to modify the commission percentage in the example
Notas de Lançamento:
v12
• Add PERC as a margin method
Notas de Lançamento:
v13
Add option to include entry fee in the PROF method calculations
Biblioteca do Pine

No verdadeiro espírito TradingView, o autor publicou este código de Pine como uma biblioteca de código aberto para que outros programadores de Pine de nossa comunidade possam reutilizá-lo. Um brinde ao autor! Você pode usar esta biblioteca em particular ou em outras publicações de código aberto, mas a reutilização deste código em uma publicação é regida pelas Regras da Casa.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.

Gostaria de usar essa biblioteca?

Copie a seguinte linha e cole-a em seu script.