Flare🔶   METHODS
    • Pine Script™ introduces methods ( 1 ,  2 )! Much kuddos for the developers, Tradingview, and all who has worked on it!
    • This educational script will show the simplified way of writing built-in methods, not to create a new method.
🔹   Simplified way of writing built-in methods:
        ·  Instead of:
  
newArray = array.new()
array.unshift(newArray, 1)
lin = line.new(na, na, na, na)
line.set_xy1(lin, bar_index     , close)
line.set_xy2(lin, bar_index + 10, close)
label newLabel = label.new(bar_index, high)
if barstate.islast
    label.delete(newLabel)
 
        ·  We now can write it like this:
  
newArray = array.new()
newArray.unshift(1)
lin = line.new(na, na, na, na)
lin.set_xy1(bar_index     , close)
lin.set_xy2(bar_index + 10, close)
label newLabel = label.new(bar_index, high)
if barstate.islast
    newLabel.delete()
 
                                                                  ——————————————————————————————————————————————————————————
        ·  When using   sometimes  brackets  are necessary:
  
label lab = label.new(bar_index, high)
if barstate.islast
    label.set_color(lab, color.red)
    label.delete(lab )
 
        ·  ->
  
label lab = label.new(bar_index, high)
if barstate.islast
    lab.set_color(color.red)
    (lab ).delete() // lab .delete() doesn't compile at the moment
 
                                                                  ——————————————————————————————————————————————————————————
🔶   OVERVIEW OF SCRIPT
    • The basic principles are:
        ·  Find 1 point ( close )  x bars back  from current bar ( settings:  'x close back').
  
        ·  Create a 'Flare' shaped object from that point to current bar or further (dependable of "Width of Flare").
        ·  Calculate where current close is located versus the Flare lines.
        ·  On that bases, change colour and draw plotshapes.
              ·  Below bar if current close is located in the upper part of the Flare
              ·  Above bar if current close is located in the lower part of the Flare
              ·  Above & Below if  located in the middle part of the Flare
                 ->  Above & Below colours has 3 different colours (adjustable), dependable on the position
🔶   EXAMPLES
        ·  Neutral zone:
        ·  Light Bullish zone:
  
        ·  Bullish zone:
  
        ·  Very Bullish / Overbought zone:
  
        ·  Light Bearish zone:
  
        ·  Bearish zone:
  
        ·  Very Bearish / Oversold zone:
  
🔶   TECHNIQUES
🔹   I. Make a User Defined Type (UDT) Flare, with:
        ·  5x linefill  - array of linefill 
        ·  int iDir, which captures the direction (current location of close in Flare)
        ·  color cCol, this is a colour variable in relation to the direction.
🔹   II. Different functions will add a new Flare object, and update the values on each bar.
        ·  Explanation of each function can be found in the script.
🔶   EXTRA's
        ·  The  input.color()  is located in the function  set_flare_B(flare obj)  
        ·  Best to put the  inputs  at the beginning of the script, I included this alternative just to show it is possible (but mostly not ideal)
        ·  Background colour (settings: Bgcolor) can be enabled for better visibility of colours
Methods
arraymethodsLibrary   "arraymethods" 
Supplementary array methods.
 delete(arr, index) 
  remove int object from array of integers at specific index
  Parameters:
     arr : int array
     index : index at which int object need to be removed
  Returns: void
 delete(arr, index) 
  remove float object from array of float at specific index
  Parameters:
     arr : float array
     index : index at which float object need to be removed
  Returns: float
 delete(arr, index) 
  remove bool object from array of bool at specific index
  Parameters:
     arr : bool array
     index : index at which bool object need to be removed
  Returns: bool
 delete(arr, index) 
  remove string object from array of string at specific index
  Parameters:
     arr : string array
     index : index at which string object need to be removed
  Returns: string
 delete(arr, index) 
  remove color object from array of color at specific index
  Parameters:
     arr : color array
     index : index at which color object need to be removed
  Returns: color
 delete(arr, index) 
  remove line object from array of lines at specific index and deletes the line
  Parameters:
     arr : line array
     index : index at which line object need to be removed and deleted
  Returns: void
 delete(arr, index) 
  remove label object from array of labels at specific index and deletes the label
  Parameters:
     arr : label array
     index : index at which label object need to be removed and deleted
  Returns: void
 delete(arr, index) 
  remove box object from array of boxes at specific index and deletes the box
  Parameters:
     arr : box array
     index : index at which box object need to be removed and deleted
  Returns: void
 delete(arr, index) 
  remove table object from array of tables at specific index and deletes the table
  Parameters:
     arr : table array
     index : index at which table object need to be removed and deleted
  Returns: void
 delete(arr, index) 
  remove linefill object from array of linefills at specific index and deletes the linefill
  Parameters:
     arr : linefill array
     index : index at which linefill object need to be removed and deleted
  Returns: void
 popr(arr) 
  remove last int object from array
  Parameters:
     arr : int array
  Returns: int
 popr(arr) 
  remove last float object from array
  Parameters:
     arr : float array
  Returns: float
 popr(arr) 
  remove last bool object from array
  Parameters:
     arr : bool array
  Returns: bool
 popr(arr) 
  remove last string object from array
  Parameters:
     arr : string array
  Returns: string
 popr(arr) 
  remove last color object from array
  Parameters:
     arr : color array
  Returns: color
 popr(arr) 
  remove and delete last line object from array
  Parameters:
     arr : line array
  Returns: void
 popr(arr) 
  remove and delete last label object from array
  Parameters:
     arr : label array
  Returns: void
 popr(arr) 
  remove and delete last box object from array
  Parameters:
     arr : box array
  Returns: void
 popr(arr) 
  remove and delete last table object from array
  Parameters:
     arr : table array
  Returns: void
 popr(arr) 
  remove and delete last linefill object from array
  Parameters:
     arr : linefill array
  Returns: void
 shiftr(arr) 
  remove first int object from array
  Parameters:
     arr : int array
  Returns: int
 shiftr(arr) 
  remove first float object from array
  Parameters:
     arr : float array
  Returns: float
 shiftr(arr) 
  remove first bool object from array
  Parameters:
     arr : bool array
  Returns: bool
 shiftr(arr) 
  remove first string object from array
  Parameters:
     arr : string array
  Returns: string
 shiftr(arr) 
  remove first color object from array
  Parameters:
     arr : color array
  Returns: color
 shiftr(arr) 
  remove and delete first line object from array
  Parameters:
     arr : line array
  Returns: void
 shiftr(arr) 
  remove and delete first label object from array
  Parameters:
     arr : label array
  Returns: void
 shiftr(arr) 
  remove and delete first box object from array
  Parameters:
     arr : box array
  Returns: void
 shiftr(arr) 
  remove and delete first table object from array
  Parameters:
     arr : table array
  Returns: void
 shiftr(arr) 
  remove and delete first linefill object from array
  Parameters:
     arr : linefill array
  Returns: void
 push(arr, val, maxItems) 
  add int to the end of an array with max items cap. Objects are removed from start to maintain max items cap
  Parameters:
     arr : int array
     val : int object to be pushed
     maxItems : max number of items array can hold
  Returns: int 
 push(arr, val, maxItems) 
  add float to the end of an array with max items cap. Objects are removed from start to maintain max items cap
  Parameters:
     arr : float array
     val : float object to be pushed
     maxItems : max number of items array can hold
  Returns: float 
 push(arr, val, maxItems) 
  add bool to the end of an array with max items cap. Objects are removed from start to maintain max items cap
  Parameters:
     arr : bool array
     val : bool object to be pushed
     maxItems : max number of items array can hold
  Returns: bool 
 push(arr, val, maxItems) 
  add string to the end of an array with max items cap. Objects are removed from start to maintain max items cap
  Parameters:
     arr : string array
     val : string object to be pushed
     maxItems : max number of items array can hold
  Returns: string 
 push(arr, val, maxItems) 
  add color to the end of an array with max items cap. Objects are removed from start to maintain max items cap
  Parameters:
     arr : color array
     val : color object to be pushed
     maxItems : max number of items array can hold
  Returns: color 
 push(arr, val, maxItems) 
  add line to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
  Parameters:
     arr : line array
     val : line object to be pushed
     maxItems : max number of items array can hold
  Returns: line 
 push(arr, val, maxItems) 
  add label to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
  Parameters:
     arr : label array
     val : label object to be pushed
     maxItems : max number of items array can hold
  Returns: label 
 push(arr, val, maxItems) 
  add box to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
  Parameters:
     arr : box array
     val : box object to be pushed
     maxItems : max number of items array can hold
  Returns: box 
 push(arr, val, maxItems) 
  add table to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
  Parameters:
     arr : table array
     val : table object to be pushed
     maxItems : max number of items array can hold
  Returns: table 
 push(arr, val, maxItems) 
  add linefill to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
  Parameters:
     arr : linefill array
     val : linefill object to be pushed
     maxItems : max number of items array can hold
  Returns: linefill 
 unshift(arr, val, maxItems) 
  add int to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
  Parameters:
     arr : int array
     val : int object to be unshift
     maxItems : max number of items array can hold
  Returns: int 
 unshift(arr, val, maxItems) 
  add float to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
  Parameters:
     arr : float array
     val : float object to be unshift
     maxItems : max number of items array can hold
  Returns: float 
 unshift(arr, val, maxItems) 
  add bool to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
  Parameters:
     arr : bool array
     val : bool object to be unshift
     maxItems : max number of items array can hold
  Returns: bool 
 unshift(arr, val, maxItems) 
  add string to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
  Parameters:
     arr : string array
     val : string object to be unshift
     maxItems : max number of items array can hold
  Returns: string 
 unshift(arr, val, maxItems) 
  add color to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
  Parameters:
     arr : color array
     val : color object to be unshift
     maxItems : max number of items array can hold
  Returns: color 
 unshift(arr, val, maxItems) 
  add line to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
  Parameters:
     arr : line array
     val : line object to be unshift
     maxItems : max number of items array can hold
  Returns: line 
 unshift(arr, val, maxItems) 
  add label to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
  Parameters:
     arr : label array
     val : label object to be unshift
     maxItems : max number of items array can hold
  Returns: label 
 unshift(arr, val, maxItems) 
  add box to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
  Parameters:
     arr : box array
     val : box object to be unshift
     maxItems : max number of items array can hold
  Returns: box 
 unshift(arr, val, maxItems) 
  add table to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
  Parameters:
     arr : table array
     val : table object to be unshift
     maxItems : max number of items array can hold
  Returns: table 
 unshift(arr, val, maxItems) 
  add linefill to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
  Parameters:
     arr : linefill array
     val : linefill object to be unshift
     maxItems : max number of items array can hold
  Returns: linefill 
 flush(arr) 
  remove all int objects in an array
  Parameters:
     arr : int array
  Returns: int 
 flush(arr) 
  remove all float objects in an array
  Parameters:
     arr : float array
  Returns: float 
 flush(arr) 
  remove all bool objects in an array
  Parameters:
     arr : bool array
  Returns: bool 
 flush(arr) 
  remove all string objects in an array
  Parameters:
     arr : string array
  Returns: string 
 flush(arr) 
  remove all color objects in an array
  Parameters:
     arr : color array
  Returns: color 
 flush(arr) 
  remove and delete all line objects in an array
  Parameters:
     arr : line array
  Returns: line 
 flush(arr) 
  remove and delete all label objects in an array
  Parameters:
     arr : label array
  Returns: label 
 flush(arr) 
  remove and delete all box objects in an array
  Parameters:
     arr : box array
  Returns: box 
 flush(arr) 
  remove and delete all table objects in an array
  Parameters:
     arr : table array
  Returns: table 
 flush(arr) 
  remove and delete all linefill objects in an array
  Parameters:
     arr : linefill array
  Returns: linefill
keyed value types with pseudo-dict - Methods Library   "key_vals" 
a set of primitive single-type key/value items, and pseudo-dictionaries
The dictionaries are single arrays of items, each item has a key and value.
The library is 100% methods. add, remove, get and set items by key. 
It provides methods to get all the keys, values or items in the dict as arrays.
For those familiar with python, it's similar, but typified.. and the brackets are round.
example syntax.. using floats, the same functions exist for Int, Bool and String
 new float_item 
new (‘demo’, 1.0 )
 set the key of a float_item 
float_item.key (‘demo’)
 get the key of a float_item 
float_item.key ()
 set the value of a float_item 
float_item.val (1.5)
 get the value of a float_item 
float_item.val ()
 get the number of items in a dict 
float_dict.count ()
 set an item to a dict by key ( add / update) 
float_dict.set   ( ‘demo’, 2.0 )
 remove an item from a dict by key (changes index, but this is about keys, not ids) 
float_dict.remove   ( ‘demo’ )
 get an item from a dict array 
array.get   (1 )
 get an item from a dict by key 
float_dict.get   ( ‘demo’ )
 get an item from a dict by id (remember, ids change if removed by key) mainlyy an internal function 
float_dict.get   ( 1)
 return all keys as string 
float_dict.get_keys()
 return all values as float 
float_dict.get_values()
 return all items as float 
float_dict.get_items()
 create a new float dict in the multi dict and return the index of it 
multi_dict.add_float_dict()
 get the float dict at index 0 from the multi dict 
multi_dict.get_float_dict( 0)
 set an item in a float dict in a multi dict 
multi_dict.set_float( ‘demo’, 2.0 )
 get an item from a float dict in a multi dict 
multi_dict.get_float( ‘demo’ )
 float_item 
  float_item
  Fields:
     key : (string) 
     val : (float) 
     next : (float_item)
 float_dict 
  float_dict
  Fields:
     content 
 int_item 
  int_item
  Fields:
     key : (string) 
     val : (int) 
     next : (int_item)
 int_dict 
  int_dict
  Fields:
     content 
 string_item 
  string_item
  Fields:
     key : (string) 
     val : (string) 
     next : (string_item)
 string_dict 
  string_dict
  Fields:
     content 
 bool_item 
  bool_item
  Fields:
     key : (string) 
     val : (bool) 
     next : (bool_item)
 bool_dict 
  bool_dict
  Fields:
     content 
 multi_dict 
  multi_dict
  Fields:
     f_dicts 
     f_registry 
     i_dicts 
     i_registry 
     s_dicts 
     s_registry 
     b_dicts 
     b_registry 
 new(key, val) 
  new
  Parameters:
     key : string
     val : float
 new(key, val) 
  Parameters:
     key 
     val 
 new(key, val) 
  Parameters:
     key 
     val 
 new(key, val) 
  Parameters:
     key 
     val 
 key(this, key) 
  key
  Parameters:
     this : float_item
     key : string
 key(this) 
  key
  Parameters:
     this : float_item
 key(this, key) 
  Parameters:
     this 
     key 
 key(this) 
  Parameters:
     this 
 key(this, key) 
  Parameters:
     this 
     key 
 key(this) 
  Parameters:
     this 
 key(this, key) 
  Parameters:
     this 
     key 
 key(this) 
  Parameters:
     this 
 val(this) 
  val
  Parameters:
     this : float_item
 val(this, val) 
  val
  Parameters:
     this : float_item
     val : float
 val(this) 
  Parameters:
     this 
 val(this, val) 
  Parameters:
     this 
     val 
 val(this) 
  Parameters:
     this 
 val(this, val) 
  Parameters:
     this 
     val 
 val(this) 
  Parameters:
     this 
 val(this, val) 
  Parameters:
     this 
     val 
 count(dict) 
  count
  Parameters:
     dict : float_dict
 count(dict) 
  Parameters:
     dict 
 count(dict) 
  Parameters:
     dict 
 count(dict) 
  Parameters:
     dict 
 get(dict, index) 
  get
  Parameters:
     dict : float_dict
     index : int
 get(dict, index) 
  get
  Parameters:
     dict : float_dict
     index : int
 get(d, key) 
  Parameters:
     d 
     key 
 get(dict, index) 
  Parameters:
     dict 
     index 
 get(dict, index) 
  Parameters:
     dict 
     index 
 get(d, key) 
  Parameters:
     d 
     key 
 get(dict, index) 
  Parameters:
     dict 
     index 
 get(dict, index) 
  Parameters:
     dict 
     index 
 get(d, key) 
  Parameters:
     d 
     key 
 get(dict, index) 
  Parameters:
     dict 
     index 
 get(dict, index) 
  Parameters:
     dict 
     index 
 get(d, key) 
  Parameters:
     d 
     key 
 set(d, key, val) 
  set
  Parameters:
     d : float_dict
     key : string
     val : float
 set(d, key, val) 
  Parameters:
     d 
     key 
     val 
 set(d, key, val) 
  Parameters:
     d 
     key 
     val 
 set(d, key, val) 
  Parameters:
     d 
     key 
     val 
 get_keys(d) 
  Parameters:
     d 
 get_keys(d) 
  Parameters:
     d 
 get_keys(d) 
  Parameters:
     d 
 get_keys(d) 
  Parameters:
     d 
 get_values(d) 
  Parameters:
     d 
 get_values(d) 
  Parameters:
     d 
 get_values(d) 
  Parameters:
     d 
 get_values(d) 
  Parameters:
     d 
 get_items(d) 
  Parameters:
     d 
 get_items(d) 
  Parameters:
     d 
 get_items(d) 
  Parameters:
     d 
 get_items(d) 
  Parameters:
     d 
 remove(dict, key) 
  Parameters:
     dict 
     key 
 remove(dict, key) 
  Parameters:
     dict 
     key 
 remove(dict, key) 
  Parameters:
     dict 
     key 
 remove(dict, key) 
  Parameters:
     dict 
     key 
 create_multi_dict() 
 add_float_dict(this) 
  Parameters:
     this 
 add_int_dict(this) 
  Parameters:
     this 
 add_string_dict(this) 
  Parameters:
     this 
 add_bool_dict(this) 
  Parameters:
     this 
 get_float_dict(this, index) 
  Parameters:
     this 
     index 
 get_float_dict(this, key) 
  Parameters:
     this 
     key 
 get_int_dict(this, index) 
  Parameters:
     this 
     index 
 get_int_dict(this, key) 
  Parameters:
     this 
     key 
 get_string_dict(this, index) 
  Parameters:
     this 
     index 
 get_string_dict(this, key) 
  Parameters:
     this 
     key 
 get_bool_dict(this, index) 
  Parameters:
     this 
     index 
 get_bool_dict(this, key) 
  Parameters:
     this 
     key 
 set_float(this, key, val) 
  Parameters:
     this 
     key 
     val 
 set_int(this, key, val) 
  Parameters:
     this 
     key 
     val 
 set_string(this, key, val) 
  Parameters:
     this 
     key 
     val 
 set_bool(this, key, val) 
  Parameters:
     this 
     key 
     val 
Relative Falling three Methods IndicatorAbstract
This script measure the related speed between rising and falling.
This script can replace binary Falling Three Methods detector and, report continuous value and estimate potential trend direction.
My suggestion of using this script is combining it with trading emotion.
Introduction
Falling Three Methods (F3M) is a candlestick pattern.
Many trading courses say traders can regard it as predicting falling will continue.
However, it is not easy to see perfect Falling Three Methods pattern from charts.
Therefore, we need an alternative method to measure it.
We can use the observation that falling is faster than rising during those time.
When falling is faster than rising, some long ( buy , call , higher , upper ) position owners may worry the price will fall very much suddenly.
When rising is faster than falling, some traders may worry they may miss buy opportunities.
Computing Related Falling Three Methods Indicator
(1) The value of rising and falling
In this script, open price is replaced with previous close price.
If the previous price is equal to the close price, than both rising and falling are equal to high-low.
If the previous price is lower than the close price, than the falling value becomes smaller, high-close+previous-low.
If the previous price is higher than the close price, than the rising value becomes smaller, high-previous+close-low.
(2) Area of value (aov)
Area of value is equal to highest-lowest. The previous close price is included.
(3) Compute weight and filter noise
We need a threshold for the noise filter. The default setting is aov/length, where length means how many days are counted.
When a rising or falling value <= threshold, it is not counted.
When a rising or falling value > threshold, the counted value = original value - threshold
and its weight = min ( counted value , threshold )
(4) compute speed
Rising speed = sum ( counted rising value ) / sum ( rising weight )
Falling speed = sum ( counted falling value ) / sum ( falling weight )
(5) Final result
Final result = Rising speed / ( Rising speed + Falling speed ) * 100 - 50
I move the middle level to 0 because 0 axis is always visible unless you cannot see negative values or you cannot see positive values.
Parameters
Length : how many days are counted. The default value is 16 just because 16=4*4, using binary characteristic.
Multi : the multiplier of noise threshold. Threshold applied = default threshold * multi
src : current not used
Conclusion
Related Falling Three Methods Indicator can measure the related speed between rising and falling.
I hope this indicator can help us to evaluate the possibility of trend continue or reversal and potential breakout direction.
After all, we care how trading emotion control the price movement and therefore we can take advantage to it.
Reference
How to trade with Falling Three Methods pattern
How to trade with Related Strength Indicator



