MathOperatorLibrary "MathOperator"
Methods to handle operators.
method add(value_a, value_b)
Add value a to b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method subtract(value_a, value_b)
subtract value b from a.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method multiply(value_a, value_b)
multiply value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method divide(value_a, value_b)
divide value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method remainder(value_a, value_b)
remainder of a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: float.
method equal(value_a, value_b)
equality of value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method not_equal(value_a, value_b)
inequality of value a with b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method over(value_a, value_b)
value a is over b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method under(value_a, value_b)
value a is under b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method over_equal(value_a, value_b)
value a is over equal b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method under_equal(value_a, value_b)
value a is under equal b.
Namespace types: series float, simple float, input float, const float
Parameters:
value_a (float) : float, value a.
value_b (float) : float, value b.
Returns: bool.
method and_(value_a, value_b)
logical and of a with b
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method or_(value_a, value_b)
logical or of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method not_(value_a)
logical not of a.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
Returns: bool.
method xor_(value_a, value_b)
logical xor of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method xnor_(value_a, value_b)
logical xnor of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method nand_(value_a, value_b)
logical nand of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
method nor_(value_a, value_b)
logical nor of a with b.
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
value_a (bool) : bool, value a.
value_b (bool) : bool, value b.
Returns: bool.
Logic
TUF_LOGICThe TUF_LOGIC library incorporates three-valued logic (also known as trilean logic) into Pine Script, enabling the representation of states beyond the binary True and False to include an 'Uncertain' state. This addition is particularly apt for financial market contexts where information may not always be black or white, accommodating scenarios of partial or ambiguous data.
Key Features:
Trilean Data Type: Defines a tri type, facilitating the representation of True (1), Uncertain (0), and False (-1) states, thus accommodating a more nuanced approach to logical evaluation.
Validation and Conversion: Includes methods like validate, to ensure trilean variables conform to expected states, and to_bool, for converting trilean to boolean values, enhancing interoperability with binary logic systems.
Core Logical Operations: Extends traditional logical operators (AND, OR, NOT, XOR, EQUALITY) to work within the trilean domain, enabling complex conditionals that reflect real-world uncertainties.
Specialized Logical Operations:
Implication Operators: Features IMP_K (Kleene's), IMP_L (Łukasiewicz's), and IMP_RM3, offering varied approaches to logical implication within the trilean framework.
Possibility, Necessity, and Contingency Operators: Implements MA ("it is possible that..."), LA ("it is necessary that..."), and IA ("it is unknown/contingent that..."), derived from Tarski-Łukasiewicz's modal logic attempts, enriching the library with modal logic capabilities.
Unanimity Functions: The UNANIMOUS operator assesses complete agreement among trilean values, useful for scenarios requiring consensus or uniformity across multiple indicators or conditions.
This library is developed to support scenarios in financial trading and analysis where decisions might hinge on more than binary outcomes. By incorporating modal logic aspects and providing a framework for handling uncertainty through the MA, LA, and IA operations, TUF_LOGIC bridges the gap between classical binary logic and the realities of uncertain information, making it a valuable tool for developing sophisticated trading strategies and analytical models.
Library "TUF_LOGIC"
3VL Implementation (TUF stands for True, Uncertain, False.)
method validate(self)
Ensures a valid trilean variable. This works by clamping the variable to the range associated with the trilean type.
Namespace types: tri
Parameters:
self (tri)
Returns: Validated trilean object.
method to_bool(self)
Converts a trilean object into a boolean object. True -> True, Uncertain -> na, False -> False.
Namespace types: tri
Parameters:
self (tri)
Returns: A boolean variable.
method NOT(self)
Negates the trilean object. True -> False, Uncertain -> Uncertain, False -> True
Namespace types: tri
Parameters:
self (tri)
Returns: Negated trilean object.
method AND(self, comparator)
Logical AND operation for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The first trilean object.
comparator (tri) : The second trilean object to compare with.
Returns: `tri` Result of the AND operation as a trilean object.
method OR(self, comparator)
Logical OR operation for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The first trilean object.
comparator (tri) : The second trilean object to compare with.
Returns: `tri` Result of the OR operation as a trilean object.
method EQUALITY(self, comparator)
Logical EQUALITY operation for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The first trilean object.
comparator (tri) : The second trilean object to compare with.
Returns: `tri` Result of the EQUALITY operation as a trilean object, True if both are equal, False otherwise.
method XOR(self, comparator)
Logical XOR (Exclusive OR) operation for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The first trilean object.
comparator (tri) : The second trilean object to compare with.
Returns: `tri` Result of the XOR operation as a trilean object.
method IMP_K(self, comparator)
Material implication using Kleene's logic for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The antecedent trilean object.
comparator (tri) : The consequent trilean object.
Returns: `tri` Result of the implication operation as a trilean object.
method IMP_L(self, comparator)
Logical implication using Łukasiewicz's logic for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The antecedent trilean object.
comparator (tri) : The consequent trilean object.
Returns: `tri` Result of the implication operation as a trilean object.
method IMP_RM3(self, comparator)
Logical implication using RM3 logic for trilean objects.
Namespace types: tri
Parameters:
self (tri) : The antecedent trilean object.
comparator (tri) : The consequent trilean object.
Returns: `tri` Result of the RM3 implication as a trilean object.
method MA(self)
Evaluates to True if the trilean object is either True or Uncertain, False otherwise.
Namespace types: tri
Parameters:
self (tri) : The trilean object to evaluate.
Returns: `tri` Result of the operation as a trilean object.
method LA(self)
Evaluates to True if the trilean object is True, False otherwise.
Namespace types: tri
Parameters:
self (tri) : The trilean object to evaluate.
Returns: `tri` Result of the operation as a trilean object.
method IA(self)
Evaluates to True if the trilean object is Uncertain, False otherwise.
Namespace types: tri
Parameters:
self (tri) : The trilean object to evaluate.
Returns: `tri` Result of the operation as a trilean object.
UNANIMOUS(self, comparator)
Evaluates the unanimity between two trilean values.
Parameters:
self (tri) : The first trilean value.
comparator (tri) : The second trilean value.
Returns: `tri` Returns True if both values are True, False if both are False, and Uncertain otherwise.
method UNANIMOUS(self)
Evaluates the unanimity among an array of trilean values.
Namespace types: array
Parameters:
self (array) : The array of trilean values.
Returns: `tri` Returns True if all values are True, False if all are False, and Uncertain otherwise.
tri
Three Value Logic (T.U.F.), or trilean. Can be True (1), Uncertain (0), or False (-1).
Fields:
v (series int) : Value of the trilean variable. Can be True (1), Uncertain (0), or False (-1).
xor logical operatorLibrary "xor"
xor(a, b)
xor: Exclusive or, or exclusive disjunction is a logical operation that is true if and only if its arguments differ (one is true, the other is false).
Parameters:
a : first argument
b : second argument
Returns: returns xor (true only if a and b are true, but not both)
Example:
true xor true = false
true xor false = true
false xor true = true
false xor false = false