MA Colored Heiken Ashi Trend with PaintBars for ThinkorSwim

Welkin

Welkin

Active member
VIP
This script colors a Moving Average (simple, exponential, hull, weighted, wilders, and variable) line in accordance to how Heiken Ashi trend bars are painted. You can also toggle to Paint normal candle stick bars to match Heiken Ashi trend bars so that you can see the regular candlesticks without changing the chart type to Heiken Ashi.

edit: changed it to where if paint heiken MA is toggled to no then it'll just paint red or green on moving average reversals. Also if you have the MA type set to Hull, I don't believe it is necessary to paint according to Heiken Ashi trend because the Hull moving average also does a great job showing trend change ( I like the length set to 12 when using Hull for trend direction). Just mess around with different settings and find what works for you.

thinkScript Code

Code:
#MA colored according to Heiken Ashi Trend
def NA = Double.NaN;

input price = close;
input MALength = 50;
input MAtype = {Simple, default Exponential, Hull, Weighted, Variable, Wilders};
input paintbars = no;
input paintheikenMA = yes;

plot MA;

#wanted to note that I do not think painting the Hull Moving Average with Hekien Ashi trend is necessary, but I included it anyway.
switch (MAtype) {
case Simple:
    MA = MovingAverage(AverageType.SIMPLE, price, "length" = MALength);
case Exponential:
    MA = MovingAverage(AverageType.EXPONENTIAL, price, "length" = MALength);
case Hull:
    MA = MovingAverage(AverageType.HULL,price, "length" = MALength);
case Weighted:
    MA = MovingAverage(AverageType.WEIGHTED, price, "length" = MALength);
case Variable:
    MA = VariableMA(price, "length" = MALength);
case Wilders:
    MA = MovingAverage(AverageType.WILDERS, price, "length" = MALength);
}


def o = open;
def h = high;
def l = low;
def c = close;
def HAopen;
def HAhigh;
def HAlow;
def HAclose;
HAopen = CompoundValue(1, (HAopen[1] + HAclose[1]) / 2, (o[1] + c[1]) / 2);
HAhigh = Max(Max(h, HAopen), HAclose[1]);
HAlow = Min(Min(l, HAopen), HAclose[1]);
HAclose = (open + high + low + close) / 4;

MA.SetLineWeight(2);

MA.AssignValueColor(if !paintheikenMA and MA > MA[1] then Color.GREEN else if paintheikenMA and HAclose > HAopen then Color.GREEN else Color.RED);


AssignPriceColor(if !paintbars then Color.CURRENT else if HAclose > HAopen then Color.GREEN else Color.RED);
Shareable Link: http://tos.mx/ipvPoFg



Here it is with normal candlesticks painted to match Heiken Ashi.

 
Last edited:
U

uawgmsmco

New member
Very nice contribution! I'm definitely going to be playing around with this
 
A

ajai

New member
VIP
Hello Weilkin,consider this.

1.convert this to MTF HA strategy.
2.When both aggregations are bullish then MA is green ,when they are not in agreement then it is neutral and when both are bearish then it is red.
3.This MA can be plotted with regular candles on chart but MA is based on HA candle.

I use this strategy with actual HAcandles in future and have a success rate of over 70%.
 
Welkin

Welkin

Active member
VIP
Hello Weilkin,consider this.

1.convert this to MTF HA strategy.
2.When both aggregations are bullish then MA is green ,when they are not in agreement then it is neutral and when both are bearish then it is red.
3.This MA can be plotted with regular candles on chart but MA is based on HA candle.

I use this strategy with actual HAcandles in future and have a success rate of over 70%.
threw it together real quick
Code:
#MTF Heiken Ashi Trend Moving Average
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.TEN_MIN;


input maLength = 20;
input averageType = AverageType.SIMPLE;
input price = close;

DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);
#HAgg1
def o1 = open("period"= haAgg1);
def h1 = high("period"= haAgg1);
def l1 = low("period"= haAgg1);
def c1 = close("period"= haAgg1);
def HA1open;
def HA1high;
def HA1low;
def HA1close;
HA1open = CompoundValue(1, (HA1open[1] + HA1close[1]) / 2, (o1[1] + c1[1]) / 2);
HA1high = Max(Max(h1, HA1open), HA1close[1]);
HA1low = Min(Min(l1, HA1open), HA1close[1]);
HA1close = (o1 + h1 + l1 + c1) / 4;


#HAgg2
def o2 = open("period"= haAgg2);
def h2 = high("period"= haAgg2);
def l2 = low("period"= haAgg2);
def c2 = close("period"= haAgg2);
def HA2open;
def HA2high;
def HA2low;
def HA2close;
HA2open = CompoundValue(1, (HA2open[1] + HA2close[1]) / 2, (o2[1] + c2[1]) / 2);
HA2high = Max(Max(h2, HA2open), HA2close[1]);
HA2low = Min(Min(l2, HA2open), HA2close[1]);
HA2close = (o2 + h2 + l2 + c2) / 4;


def HA1 = HA1close > HA1open;
def HA2 = HA2close > HA2open;


AddLabel(1,"HA1", if HA1 then GlobalColor("Bullish") else GlobalColor("Bearish"));
AddLabel(1,"HA2", if HA2 then GlobalColor("Bullish") else GlobalColor("Bearish"));

plot MA = MovingAverage(AverageType, price, maLength);
MA.SetDefaultColor(Color.GRAY);
MA.SetLineWeight(2);
MA.AssignValueColor(if HA1 and HA2 then GlobalColor("Bullish") else if !HA1 and !HA2 then GlobalColor("Bearish") else GlobalColor("Neutral"));

def posHASig = HA1 and HA2;
def negHASig = !HA1 and !HA2;
plot UpSig = posHASig and !posHASig[1];
plot DownSig = negHASig and !negHASig[1];
UpSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSig.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
UpSig.AssignValueColor(GlobalColor("Bullish"));
DownSig.AssignValueColor(GlobalColor("Bearish"));
 
Last edited:
A

ajai

New member
VIP
Hello Welkin,
Good and quick response.TY.I will test it on Monday in live market and let you know.It looks good with last seven days of testing with proper rules.May be after my report you could give your feedback.I think with proper risk control we can help lot ES traders with this strategy.
Have a great one.
 
Thread starter Similar threads Forum Replies Date
A TEMA custom colored candles Questions 4
3AMBH Colored EMA/SMA at Tradingview.com Questions 3
T VWAP Colored up green and down red Questions 0
D Colored Candles - Assign Price Color Questions 0
T MACD Colored Candles? Questions 7
Top