Welkin
Active member
The author of the study isn't available on the forum to provide answers to questions. So this thread has been locked.
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
Here it is with normal candlesticks painted to match Heiken Ashi.
Last edited by a moderator: