MA Colored Heiken Ashi Trend with PaintBars for ThinkorSwim

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: https://tos.mx/ipvPoFg

6SNE0La.png


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

1qvQTWj.png
 
Last edited:

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

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"));

oJ6gzlT.png
 
Last edited:

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.
 

ajai

New member
VIP
TY Welkin,I am pleased to report that MTF HA strategy works although there is problem.MTFHA repaints and thus entry is somewhat delayed or false.I would like to post some chats to show you how I use it and see if you could come up with something to improve it.
 

Sparrow

New member
VIP
Hello everyone! I am playing with a study and would like to add a close indicator on the first red Heiken Ashi candlestick. Many positions I am not tied to and don't want to sit through a long drawdown. So far, I have been unable to pull off detecting it in think script. Any help would be greatly appreciated. :)
 

kiska

New member
VIP
I wrote an indicator on TradingView long ago.

A friend provided me with the code below and it seems to work well with my indicator.

I already converted mine to thinkscript (http://tos.mx/maaDfLd) but I was wondering if someone could help me in converting this piece to thinkscript as well.


Code:
// ** START Heiken-Ashi Code

//@version=3

ha_handle = heikinashi(tickerid)

ha_open = security(ha_handle, period, open)
ha_close = security(ha_handle, period, close)

o = security(tickerid, period, open)
c = security(tickerid, period, close)

col_blue=#32a7ff
col_green=#669b66
col_black=#550000
col_red=#e54444

ha1 = ha_close > ha_open ? col_blue : col_black
ha2 = ha_close[1] > ha_open[1] ? col_blue : col_black
ha3 = ha1 == ha2 ? white : ha1

pl = c > o ? col_green : col_red

final = ha3 == white ? pl : ha3

barcolor(final)


// ** END Heiken-Ashi Code
 

Similar threads

Top