Bjorgum Triple EMA Strat

GoLo

Member
VIP
Help matching Bjorgum Triple EMA Strat from TradingView. Here's my attempt to convert TV indicator for Bjorgum Triple EMA Strat https://www.tradingview.com/script/pr3d5mum-Bjorgum-Triple-EMA-Strat/. It is close to Tradingview but doesn't match exactly. The 5 and 9 appear to match or nearly identical but the 21 seems to be lagging the TV indicator. Thank you @tomsk and @Investingtogive for original scripting and Bjorgum for open source TV Code. Can someone check what part of code is inccorect such that it doesn't match TradingView? I also tweaked slightly to allow painting bars to be turned on or off and to be able to change cloud color and candle colors under "Globals". Thank you.

#Code below

# Credit to tomsk and Investingtogive for original coding and BJorgum for open source Trading View Indicator


# START
input length1 = 5;
input length2 = 9;
input length3 = 21;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAclose = (open + high + low + close) / 4;
#HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (open[1] + close) / 2);
HAopen = CompoundValue(1, (open + close)/2, (HAopen[1] + HAclose[1]) / 2);
HAhigh = Max(high, max (HAopen, HAclose));
HAlow = Min(low, min (HAopen, HAclose));

#hahl2 = average(HAhigh, HAlow);


plot HAMA1 = Average(HAOpen, length1);
plot HAMA2 = Average(HAOpen, length2);
plot HAMA3 = Average(HAOpen, length3);


DefineGlobalColor( "Bull Candle", color.green);
DefineGlobalColor( "Bear Candle", color.red);

input paintbars = yes;
AssignPriceColor(if paintbars and close > HAMA1 and close > HAMA2 then GlobalColor ("Bull Candle") else if paintbars and close < HAMA1 and close < HAMA2 then GlobalColor ("Bear Candle") else color.current);
# AssignPriceColor(if paintbars and HAMA1 > HAMA1[1] and HAMA2 > HAMA2[1] and HAMA3 > HAMA3[1] then Color.GREEN else if paintbars and HAMA1 < HAMA1[1] and HAMA2 < HAMA2[1] and HAMA3 < HAMA3[1] then color.RED else Color.light_gray);

DefineGlobalColor( "Bull Lines", color.green);
DefineGlobalColor( "Bear Lines", color.red);

HAMA1.AssignValueColor(if HAMA1 > HAMA1[1] then GlobalColor ("Bull Lines") else if HAMA1 < HAMA1[1] then GlobalColor ("Bear Lines") else Color.GRAY);
HAMA2.AssignValueColor(if HAMA2 > HAMA2[1] then GlobalColor ("Bull Lines") else if HAMA2 < HAMA2[1] then GlobalColor ("Bear Lines") else Color.GRAY);
HAMA3.AssignValueColor(if HAMA3 > HAMA3[1] then GlobalColor ("Bull Lines") else if HAMA3 < HAMA3[1] then GlobalColor ("Bear Lines") else Color.GRAY);

# END

# --------------------------------------------------- Add Cloud -----------------------------------------------
input ShowfastCloud = yes;


DefineGlobalColor( "Bullish Fast Cloud", CreateColor(201, 255, 234));
DefineGlobalColor( "Bearish Fast Cloud", CreateColor(255, 105, 105));



AddCloud(if ShowfastCloud then HAMA1 else Double.NaN, HAMA2, GlobalColor("Bullish Fast Cloud"), GlobalColor("Bearish Fast Cloud"));



input ShowSlowCloud = yes;

DefineGlobalColor( "Bullish Slow Cloud", CreateColor(201, 255, 234));
DefineGlobalColor( "Bearish Slow Cloud", CreateColor(255, 105, 105));


AddCloud(if ShowSlowCloud then HAMA2 else Double.NaN, HAMA3, GlobalColor("Bullish Slow Cloud"), GlobalColor("Bearish Slow Cloud"));
 
Last edited:
@GoLo Having a little trouble turning off the painted candles. When I turn them off every candle turns yellow. Not sure how to fix them and turn them back to regular candles. Other than that, love the indicator.
1699153765463.png
 
@GoLo Having a little trouble turning off the painted candles. When I turn them off every candle turns yellow. Not sure how to fix them and turn them back to regular candles. Other than that, love the indicator.View attachment 20098
@Quantum33 Glad you like it I've updated the code below and also updated the first post for the yellow candles. Let me know if this works for you. Code as follows:

# Credit to tomsk and Investingtogive for original coding and BJorgum for open source Trading View Indicator


# START
input length1 = 5;
input length2 = 9;
input length3 = 21;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAclose = (open + high + low + close) / 4;
#HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (open[1] + close) / 2);
HAopen = CompoundValue(1, (open + close)/2, (HAopen[1] + HAclose[1]) / 2);
HAhigh = Max(high, max (HAopen, HAclose));
HAlow = Min(low, min (HAopen, HAclose));

#hahl2 = average(HAhigh, HAlow);


plot HAMA1 = Average(HAOpen, length1);
plot HAMA2 = Average(HAOpen, length2);
plot HAMA3 = Average(HAOpen, length3);

# Delete the "#" below to color code your price bars.

DefineGlobalColor( "Bull Candle", color.green);
DefineGlobalColor( "Bear Candle", color.red);

input paintbars = yes;
AssignPriceColor(if paintbars and close > HAMA1 and close > HAMA2 then GlobalColor ("Bull Candle") else if paintbars and close < HAMA1 and close < HAMA2 then GlobalColor ("Bear Candle") else color.current);
# AssignPriceColor(if paintbars and HAMA1 > HAMA1[1] and HAMA2 > HAMA2[1] and HAMA3 > HAMA3[1] then Color.GREEN else if paintbars and HAMA1 < HAMA1[1] and HAMA2 < HAMA2[1] and HAMA3 < HAMA3[1] then color.RED else Color.light_gray);

DefineGlobalColor( "Bull Lines", color.green);
DefineGlobalColor( "Bear Lines", color.red);

HAMA1.AssignValueColor(if HAMA1 > HAMA1[1] then GlobalColor ("Bull Lines") else if HAMA1 < HAMA1[1] then GlobalColor ("Bear Lines") else Color.light_gray);
HAMA2.AssignValueColor(if HAMA2 > HAMA2[1] then GlobalColor ("Bull Lines") else if HAMA2 < HAMA2[1] then GlobalColor ("Bear Lines") else Color.light_gray);
HAMA3.AssignValueColor(if HAMA3 > HAMA3[1] then GlobalColor ("Bull Lines") else if HAMA3 < HAMA3[1] then GlobalColor ("Bear Lines") else Color.light_gray);

# END

# --------------------------------------------------- Add Cloud -----------------------------------------------
input ShowfastCloud = yes;


DefineGlobalColor( "Bullish Fast Cloud", CreateColor(201, 255, 234));
DefineGlobalColor( "Bearish Fast Cloud", CreateColor(255, 105, 105));



AddCloud(if ShowfastCloud then HAMA1 else Double.NaN, HAMA2, GlobalColor("Bullish Fast Cloud"), GlobalColor("Bearish Fast Cloud"));



input ShowSlowCloud = yes;

DefineGlobalColor( "Bullish Slow Cloud", CreateColor(201, 255, 234));
DefineGlobalColor( "Bearish Slow Cloud", CreateColor(255, 105, 105));


AddCloud(if ShowSlowCloud then HAMA2 else Double.NaN, HAMA3, GlobalColor("Bullish Slow Cloud"), GlobalColor("Bearish Slow Cloud"));
 
Last edited:
I've also attempted to plot the Bjorgum Superscript T3 cloud below, note this does not include the rest of his Superscript as it's above my coding abilities.



#Tillson T3 Moving Average MTF Edition for ThinkOrSwim
#@diazlaz 2020.03.31 Version 1.1
#
# filename: Tillson_T3_Moving_Average
# source: https://futures.io/thinkorswim/34287-tilson-t3-moving-average.html#post460861
# created by: rmejia
# last update: 12/17/2014
# MTF Version @diazlaz 2020.03.31 Version 1.0
# Version 1.1 @diazlaz 2020.03.31 Version 1.1 - Updated Line Plots to plot both states at lower timeframe.
#
#hint:<b>T3 Adaptive Smoothing Indicator</b>\nThis study was adopted from the Technical Analysis of Stocks and Commodities article "Smoothing Techniques for More Accurate Signals" by Tim Tillson, Jan 1998 (V16:1 pp33-37)
#hint: indicator: Defines the level of filtering to occur, default is 3
#hint: volumeFactor: Adjusts the amplitude of the feedback added back into the base filter


input indicator = { T1, T2, default T3, T4, T5, T6 };
input price = close;
input fast = 5;
input slow = 8;


input volumeFactor = 0.70;
input displace = 0;
input sign = { plus, default minus };
input Label = No;
input paintbars = No; #paints Primary aggregation1
#input aggregation1 = AggregationPeriod.MIN;
#input aggregation2 = AggregationPeriod.FIVE_MIN;
#aggregation1
#T1
def t1_price_01 = close;
def t1_ema_01 = ExpAverage( t1_price_01, fast );
def t1_gd_01 = ( t1_ema_01 * ( 1 + volumeFactor ) ) - ( ExpAverage( t1_ema_01, fast ) * volumeFactor );
#T2
def t2_price_01 = t1_gd_01;
def t2_ema_01 = ExpAverage( t2_price_01, fast );
def t2_gd_01 = ( t2_ema_01 * ( 1 + volumeFactor ) ) - ( ExpAverage( t2_ema_01, fast ) * volumeFactor );
#T3
def t3_price_01 = t2_gd_01;
def t3_ema_01 = ExpAverage( t3_price_01, fast );
def t3_gd_01 = ( t3_ema_01 * ( 1 + volumeFactor ) ) - ( ExpAverage( t3_ema_01, fast ) * volumeFactor );
#T4
def T4_price_01 = t3_gd_01;
def T4_ema_01 = ExpAverage( T4_price_01, fast );
def T4_gd_01 = ( T4_ema_01 * ( 1 + volumeFactor ) ) - ( ExpAverage( T4_ema_01, fast ) * volumeFactor );
#T5
def T5_price_01 = T4_gd_01;
def T5_ema_01 = ExpAverage( T5_price_01, fast );
def T5_gd_01 = ( T5_ema_01 * ( 1 + volumeFactor ) ) - ( ExpAverage( T5_ema_01, fast ) * volumeFactor );
#T6
def T6_price_01 = T5_gd_01;
def T6_ema_01 = ExpAverage( T6_price_01, fast );
def T6_gd_01 = ( T6_ema_01 * ( 1 + volumeFactor ) ) - ( ExpAverage( T6_ema_01, fast ) * volumeFactor );
plot T3_01;
switch( indicator ) {
case T1:
T3_01 = t1_gd_01;
case T2:
T3_01 = t2_gd_01;
case T3:
T3_01 = t3_gd_01;
case T4:
T3_01 = t4_gd_01;
case T5:
T3_01 = t5_gd_01;
case T6:
T3_01 = t6_gd_01;
}

DefineGlobalColor( "Bull Candle", CreateColor(100,181,246));
DefineGlobalColor( "Bear Candle", CreateColor(211,47,47));

DefineGlobalColor( "Bull Trend", CreateColor(100,181,246));
DefineGlobalColor( "Bear Trend", CreateColor(211,47,47));

T3_01.AssignValueColor(if T3_01 > T3_01[1] then GlobalColor ("Bull Trend") else GlobalColor ("Bear Trend"));
T3_01.HideBubble();
AddLabel(Label, if T3_01 > T3_01[1] then " A " else " A ", if T3_01 > T3_01[1] then Color.GREEN else Color.RED);
assignPriceColor(if paintbars and T3_01 < T3_01[1] then GlobalColor ("Bear Candle") else if paintbars and T3_01 > T3_01[1] then GlobalColor ("Bull Candle") else color.CURRENT);
#aggregation2
#T1
def t1_price_02 = close;
def t1_ema_02 = ExpAverage( t1_price_02, slow );
def t1_gd_02 = ( t1_ema_02 * ( 1 + volumeFactor ) ) - ( ExpAverage( t1_ema_02, slow ) * volumeFactor );
#T2
def t2_price_02 = t1_gd_02;
def t2_ema_02 = ExpAverage( t2_price_02, slow );
def t2_gd_02 = ( t2_ema_02 * ( 1 + volumeFactor ) ) - ( ExpAverage( t2_ema_02, slow ) * volumeFactor );
#T3
def t3_price_02 = t2_gd_02;
def t3_ema_02 = ExpAverage( t3_price_02, slow );
def t3_gd_02 = ( t3_ema_02 * ( 1 + volumeFactor ) ) - ( ExpAverage( t3_ema_02, slow ) * volumeFactor );
#T4
def T4_price_02 = t3_gd_02;
def T4_ema_02 = ExpAverage( T4_price_02, slow );
def T4_gd_02 = ( T4_ema_02 * ( 1 + volumeFactor ) ) - ( ExpAverage( T4_ema_02, slow ) * volumeFactor );
#T5
def T5_price_02 = T4_gd_02;
def T5_ema_02 = ExpAverage( T5_price_02, slow );
def T5_gd_02 = ( T5_ema_02 * ( 1 + volumeFactor ) ) - ( ExpAverage( T5_ema_02, slow ) * volumeFactor );
#T6
def T6_price_02 = T5_gd_02;
def T6_ema_02 = ExpAverage( T6_price_02, slow );
def T6_gd_02 = ( T6_ema_02 * ( 1 + volumeFactor ) ) - ( ExpAverage( T6_ema_02, slow ) * volumeFactor );
plot T3_02;
switch( indicator ) {
case T1:
T3_02 = t1_gd_02;
case T2:
T3_02 = t2_gd_02;
case T3:
T3_02 = t3_gd_02;
case T4:
T3_02 = t4_gd_02;
case T5:
T3_02 = t5_gd_02;
case T6:
T3_02 = t6_gd_02;
}

def sState1 = if T3_01 > T3_01[1] then 100 else -100;
def sState2 = if T3_02 > T3_02[1] then 100 else -100;
T3_02.AssignValueColor(if sState2 == 100 then GlobalColor ("Bull Trend") else GlobalColor ("Bear Trend"));
T3_02.setLineWeight(2);
T3_02.HideBubble();
AddLabel(Label, if T3_02 > T3_02[1] then " B " else " B ", if T3_02 > T3_02[1] then Color.GREEN else Color.RED);


#End of #Tillson T3 Moving Average MTF Edition for ThinkOrSwim

# ------------------------------------------ Add Cloud -----------------------------------------------

input ShowCloud = yes;


AddCloud(if ShowCloud then T3_01 else Double.NaN, T3_02, GlobalColor ("Bull Trend"), GlobalColor ("Bear Trend"));
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
496 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top