PINE LIBRARY

distance_ratio

Updated
Library "distance_ratio"
Collection of types and functions that can be used for the calculation of the ratio [0, 1] of a distance
from a barrier price using several methods. Methods supported are percentagewise (PERC), atr-based (ATR), fixed
profit (PROF), tick-based (TICKS), risk reward ratio (RR) and local extrema (LOC).
This library is meant to replace my previously published "distance_percentile" library since it offers a more intuitive interface by using the method syntax.
Release Notes
v2
Use method syntax for "long_biased_dist_ratio" and "short_biased_dist_ratio".
For types use PascalCase instead of camelCase to work around some compiler errors as Stratfather suggested.
Release Notes
v3
Some optimizations in the PROF method calculations
Release Notes
v4
  • Add Standard Deviation method for distance and LOC margin
  • More accurate PROF calculation formula with commission fees
Release Notes
v5
Add step logic to stdev method by adding multipliers
Release Notes
v6
Simplify exit commission fee calculation
Release Notes
v7
Add initial entry fees in the PROF calculation
Release Notes
v8
(minor) without base quantity
Release Notes
v9
Use barrier as the entry price for the stepped fixed profit calculations that are also scaled with the price movement when there are consecutive price targets
Release Notes
v10

  • Added price and ticks methods
  • Added separate restrict methods
  • Simplified the object types
  • Removed the bias logic in the LOC method
Release Notes
v11
  • Tick related methods not return an integer
  • If there is a not defined value during calculations return an error if fatal or zero otherwise
  • Remove restrict argument from "pure" ratio, price ticks calls
Release Notes
v12
Update some documentation and fixed a typo in the error message
Release Notes
v13
  • Updated documentation
  • Use force_overlay for the example plots
Release Notes
v14
  • Use enum where possible
calculationdistanceMATHpercentage

Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House rules.


📧 Contact info
Telegram: @jason5480

🔗 Addresses
₿ - bc1qxh3jeld7ke70fx3r5q243d96jsx0etth6x8fa7

* Please contact me before any donation ☕

Disclaimer