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
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