armybender
Active member
I converted the LazyBear Ehler's Instantaneous Trend. This is used in another study on this forum, but it is not available as a standalone study, so I thought I would add it.
Full disclosure - I don't use this study, but found the math interesting and decided to study it a bit, so I converted it into a ToS study.
Full disclosure - I don't use this study, but found the math interesting and decided to study it a bit, so I converted it into a ToS study.
Ruby:
#Ehlers Instantaneous Trend [LazyBear]
#Converted from https://www.tradingview.com/script/DaHLcICg-Ehlers-Instantaneous-Trend-LazyBear/
#DECLARATIONS
declare upper;
#USER INPUTS
input price = hl2;
input alpha = 0.07;
input fillTrend = no;
input colorBars = no;
input showCloud = no;
### GLOBAL COLOR DEFINITIONS
DefineGlobalColor("Green", CreateColor(0, 155, 0));
DefineGlobalColor("Red", CreateColor(225, 105, 105));
DefineGlobalColor("Gray", CreateColor(181, 181, 181));
#CALCULATIONS
def alpha2 = Power(alpha, 2);
def it = ( alpha - ( ( alpha2 ) / 4.0 ) ) * price + 0.5 * alpha2 * price[1] - ( alpha - 0.75 * alpha2 ) * price[2] + 2 * ( 1 - alpha ) * ( if IsNaN( it[1] ) then ( ( price + 2 * price[1] + price[2] ) / 4.0 ) else it[1] ) - ( 1 - alpha ) * ( 1 - alpha ) * ( if IsNaN( it[2] ) then ( ( price + 2 * price[1] + price[2] ) / 4.0 ) else it[2] );
def lag = 2.0 * it - if IsNaN(it[2]) then 0 else it[2];
#PLOTS
plot instTrend = it;
plot instTrendLag = 2.0 * it - (if IsNaN(it[2]) then 0 else it[2]);
#CLOUDS
AddCloud(if showCloud then instTrendLag else Double.NaN, instTrend, GlobalColor("Green"), GlobalColor("Red"));
#BAR COLORING
AssignPriceColor(
if colorBars then
if it > it[1] then GlobalColor("Green")
else if it < it[1] then GlobalColor("Red")
else GlobalColor("Gray")
else Color.CURRENT
);
#FORMATTING
instTrend.AssignValueColor(
if it > it[1] then GlobalColor("Green")
else if it < it[1] then GlobalColor("Red")
else GlobalColor("Gray")
);
instTrend.HideTitle();
instTrend.HideBubble();
instTrend.SetLineWeight(1);
instTrendLag.AssignValueColor(
if lag > lag[1] then GlobalColor("Green")
else if lag < lag[1] then GlobalColor("Red")
else GlobalColor("Gray")
);
instTrendLag.HideTitle();
instTrendLag.HideBubble();
instTrendLag.SetLineWeight(1);
Last edited: