MA Colored Heiken Ashi Trend with PaintBars for ThinkorSwim

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

6SNE0La.png


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

1qvQTWj.png
 
Last edited by a moderator:
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%.
 
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:
So I have been a member here for awhile but only read through. I have scripted some of my own stuff but I'm at about a 3rd grade level when it comes to scripting...lol. So I found a Heiken Ashi Trend indicator on here awhile back and have been toying with it but want to create a dashboard to get a quick visual glance. The problem I'm running into is the code uses 2 timeframes and when I try to create a scan for it I get an error about multiple timeframes. I usually create a scan then load that into the dashboard and edit it to do what I want but I'm stuck here.
So what I'm trying to do is to highlight the cell for this indicator when an alert (arrow) appears. Green for up arrow and red for down arrow. I have also created another column for green when the 10EMA is greater than the 30EMA and red when the opposite. If these 2 can be combined into one cell (script) then great but if not I'm fine with separating them.

So in summary, highlight my cell in my watchlist dashboard green when there is an up arrow and red when there is a down arrow. BTW-I'm using AggregationPeriod.THIRTY_MIN and EXPONENTIAL. I'm using it on a 15m chart.

Thanks in advance!


So here is the code for the indicator that I got from here:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#MTF Heiken Ashi Trend Moving Average
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.TEN_MIN;
#def fastEMA = movAvgExponential (10);
#def slowEMA = movAvgExponential (30);
#def Bull = fastEMA is greater than slowEMA;
#def Bear = fastEMA is less than slowEMA;



input maLength = 20;
input averageType = AverageType.SIMPLE;
input price = close;
input Alerts = yes; #Hint Alerts: BUY/SELL audio alerts

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

Alert(UpSig[1] and Alerts, "HA Long", Alert.BAR, Sound.Bell);
Alert(DownSig[1] and Alerts, "HA Short", Alert.BAR, Sound.Bell);
 
So I have been a member here for awhile but only read through. I have scripted some of my own stuff but I'm at about a 3rd grade level when it comes to scripting...lol. So I found a Heiken Ashi Trend indicator on here awhile back and have been toying with it but want to create a dashboard to get a quick visual glance. The problem I'm running into is the code uses 2 timeframes and when I try to create a scan for it I get an error about multiple timeframes. I usually create a scan then load that into the dashboard and edit it to do what I want but I'm stuck here.
So what I'm trying to do is to highlight the cell for this indicator when an alert (arrow) appears. Green for up arrow and red for down arrow. I have also created another column for green when the 10EMA is greater than the 30EMA and red when the opposite. If these 2 can be combined into one cell (script) then great but if not I'm fine with separating them.

So in summary, highlight my cell in my watchlist dashboard green when there is an up arrow and red when there is a down arrow. BTW-I'm using AggregationPeriod.THIRTY_MIN and EXPONENTIAL. I'm using it on a 15m chart.
The ToS platform does not support the use of 2 timeframes in the Scan Hacker, Watchlists, Conditional Orders, etc...
MTF studies can only be used for plotting on charts.
The first post: https://usethinkscript.com/threads/ma-colored-heiken-ashi-trend-with-paintbars-for-thinkorswim.1667/ does not use multiple times. It can be used in Scan Hacker, Watchlists, Conditional Orders, etc...
 
The ToS platform does not support the use of 2 timeframes in the Scan Hacker, Watchlists, Conditional Orders, etc...
MTF studies can only be used for plotting on charts.
The first post: https://usethinkscript.com/threads/ma-colored-heiken-ashi-trend-with-paintbars-for-thinkorswim.1667/ does not use multiple times. It can be used in Scan Hacker, Watchlists, Conditional Orders, etc...
Thanks. I think I got it to do what I want but will test more and provide my code for others if they want it. I created a 2nd column so one is for bullish and one for bearish. The idea is to have those 2 columns and a 3rd for status of the 10EMA vs the 30 EMA. if the EMA column is green and the Bull column is green as per this script then I need to take a look at it. If the EMA column is red and the bear column is red then take a look at that
 
So this is what it looks like. There are 2 columns to display the arrow status. If the 15 Bull MA Trend column is green then there should be an up arrow on the 15m chart on the previous candle. If the15 Bear MA Trend block is red then there will be a red arrow on the 15m chart. The last column shows the status of the 10/30EMA's. If the 10 is above the 30 then it is green, if it's below it then its red.
dashboard.png
 
Here is the code for the 15 Bull MA Trend. Code could be cleaned up as there is a bunch of lines that aren't needed for this:
---------------------------------------------------------------------------------------------------------------------------------------------------
#MTF Heiken Ashi Trend Moving Average
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.THIRTY_MIN;


input maLength = 20;
input averageType = AverageType.EXPONENTIAL;
input price = close;
input Alerts = yes; #Hint Alerts: BUY/SELL audio alerts

DefineGlobalColor("Bullish", Color.dark_GREEN);
DefineGlobalColor("Bearish", Color.dark_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"));

Alert(UpSig[1] and Alerts, "HA Long", Alert.BAR, Sound.Bell);
#Alert(DownSig[1] and Alerts, "HA Short", Alert.BAR, Sound.Bell);

AssignBackgroundColor(if UpSig then color.dark_green else color.current);
 
And this one for the bear column:
---------------------------------------------------------------------------------------------------------------------------------------------
#MTF Heiken Ashi Trend Moving Average
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.THIRTY_MIN;


input maLength = 20;
input averageType = AverageType.EXPONENTIAL;
input price = close;
input Alerts = yes; #Hint Alerts: BUY/SELL audio alerts

DefineGlobalColor("Bullish", Color.dark_GREEN);
DefineGlobalColor("Bearish", Color.dark_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"));

#Alert(UpSig[1] and Alerts, "HA Long", Alert.BAR, Sound.Bell);
Alert(DownSig[1] and Alerts, "HA Short", Alert.BAR, Sound.Bell);

AssignbackgroundColor(if DownSig then color.dark_red else color.current);
 
And the EMA status:
------------------------------------------------------------------------------------------------------------------------------------------------------
#created by optionizerSS to indicate EMA trend on watchlist

#SMA Bearish Bounce...Basic...all colored
def EMABullTrend = MovAvgExponential("length" = 10) is greater than MovAvgExponential("length" = 30);


AssignbackgroundColor(if EMABullTrend then Color.dark_green else Color.dark_RED);

plot s = EMABullTrend;
 
So these scripts have been working pretty good to get good entries but for exits I'm using the same script but selecting 'is false' so to me that says that when either the 15 or 30 minute HA turns false it will exit. It doesn't turn true until both are true so the 15 would be the first to turn false and for an exit I don't care where the MA's are, I just want to exit. Problem is I have been seeing some exits immediately after the entry. Today an alert triggered at 11:16AM EST for SPY puts. I entered then went in and set my exit to 'is false' and it sold instantly. Tried it again and the same thing happened. Went in for a 3rd entry and made about 25% on that one but had to use a different style exit. Yet sometimes it works fine.

Here is the code I'm using to alert an entry. As long as the 10 EMA is greater than the 30 EMA for calls then it's a go. For puts the 10 must be below the 30. For an exit I go in and set the exit to the same script but select 'is false'. And ideas or even a different script to use for exits? Thanks!


#MTF Heiken Ashi Trend Moving Average
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.TEN_MIN;
#def fastEMA = movAvgExponential (10);
#def slowEMA = movAvgExponential (30);
#def Bull = fastEMA is greater than slowEMA;
#def Bear = fastEMA is less than slowEMA;



input maLength = 20;
input averageType = AverageType.SIMPLE;
input price = close;
input Alerts = yes; #Hint Alerts: BUY/SELL audio alerts

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

Alert(UpSig[1] and Alerts, "HA Long", Alert.BAR, Sound.Bell);
Alert(DownSig[1] and Alerts, "HA Short", Alert.BAR, Sound.Bell);
 
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

Just started looking at Heiken Ashi stuff, and I like this idea of coloring a moving avg to show the Heiken Ashi candle color change without
having to be using the Heiken Ashi candles on the charts. I also like being able to color the regular candles also.
Now I have a question on a flag idea that would be helpful to me.
There is a price point each day that will cause the heiken ashi to turn green or red if it closes cross it Can someone make a flag that will put the price at the end of the day that if closed below or above the Heiken Ashi will change colors?
In other words If Heiken Ashi is green today what price tomorrow will cause it to change to red? And if heiken Ashi is red what price will cause it
to turn green tomorrow?
And put that price number each day in a flag so it can be known at what price will change the color etc?
Thanks,
 
So these scripts have been working pretty good to get good entries but for exits I'm using the same script but selecting 'is false' so to me that says that when either the 15 or 30 minute HA turns false it will exit. It doesn't turn true until both are true so the 15 would be the first to turn false and for an exit I don't care where the MA's are, I just want to exit. Problem is I have been seeing some exits immediately after the entry. Today an alert triggered at 11:16AM EST for SPY puts. I entered then went in and set my exit to 'is false' and it sold instantly. Tried it again and the same thing happened. Went in for a 3rd entry and made about 25% on that one but had to use a different style exit. Yet sometimes it works fine.

Here is the code I'm using to alert an entry. As long as the 10 EMA is greater than the 30 EMA for calls then it's a go. For puts the 10 must be below the 30. For an exit I go in and set the exit to the same script but select 'is false'. And ideas or even a different script to use for exits? Thanks!


#MTF Heiken Ashi Trend Moving Average
def haAgg1 = GetAggregationPeriod();
input haAgg2 = AggregationPeriod.TEN_MIN;
#def fastEMA = movAvgExponential (10);
#def slowEMA = movAvgExponential (30);
#def Bull = fastEMA is greater than slowEMA;
#def Bear = fastEMA is less than slowEMA;



input maLength = 20;
input averageType = AverageType.SIMPLE;
input price = close;
input Alerts = yes; #Hint Alerts: BUY/SELL audio alerts

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

Alert(UpSig[1] and Alerts, "HA Long", Alert.BAR, Sound.Bell);
Alert(DownSig[1] and Alerts, "HA Short", Alert.BAR, Sound.Bell);
Is there a way to make the alerts and signals happen on the 2nd red or 2nd green candle? @SleepyZ @samer800 @halcyonguy

Also, Is there a way to make the signals only confirm once the TF candle has closed? For example: I use the 1m TF to Scalp and I like the Heikin MTF on the 5 min to help me stay in trades longer, however, the signals trigger as soon as it goes from red to green or green to red and the it may repaint and go away. Is there a way to keep the Line as is but only have the arrows plot once that TF candle has closed?
 
Last edited:
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"));

View attachment 7424
The HA labels at the top what why are there 2 of them and what do they mean?
 
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

View attachment 6629

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

View attachment 6630
Anyone know what change within the code would need to be done in order for me to change the colors ? Obviously it would be one set of colors for both the line and the candles, if paint bars = yes.

Thanks

Any takers?
 
Last edited by a moderator:

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
493 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