Change background color when HMA changes color


Category:
0
0

Part 1
This is a 5 minute chart study that uses Heikin Ashi price bars. The background changes when the HMA 5 line changes color. The Bell sounds when the Arrow changes color. The Arrow is supposed to change simultaneously with the background color change and the HMA 5 line color change. It does not, it happens before the colors change, as if it is anticipating the change. As you can see by the inclosed snapshot, uptrend arrow is green but the HMA 5 line and Background color is red.
How do I fix this?

Part 2
I must have a Second HMA5 study run after this Background change HMA5 study so that I can display the colors change Red to Green based on direction of the HMA 5 line. The Background HMA 5 study just gives a single colored line. I have tried replacing it with the same instructions that are on the HullMovingAvg study but I have been unsuccessful. If you could fix this as well it would also be very appreciated.

Thank you

input price = close;
input length = 5;
input displace = 0;
input showBreakoutSignals = yes;

plot AvgHull = HullMovingAvg(price[-displace], length);
plot UpSignal = price crosses above AvgHull;
plot DownSignal = price crosses below AvgHull;

#UpSignal.SetHiding(!showBreakoutSignals);
#DownSignal.SetHiding(!showBreakoutSignals);

AvgHull.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Alert(UpSignal, “Trend Up”, Alert.BAR, Sound.DING);
Alert(DownSignal, “Trend Down”, Alert.BAR, Sound.CHIMES);

AssignBackgroundColor(if AvgHull[1] < AvgHull then CreateColor (0, 125, 51) else if AvgHull[1] > AvgHull then CreateColor (125, 50, 51) else Color.CURRENT);

 

 

Attachments:
Marked as spam
Posted by (Questions: 5, Answers: 5)
Asked on May 19, 2020 11:15 am
551 views
0
Private answer

I updated the title of the question so that it describes the context of the request.

You stated that this chart study uses Heiken-Ashi candles. It does not. When you set a chart on Thinkorswim to display Heiken-Ashi candles it does NOT force the chart studies to plot based on those candles. All studies added to the chart continue to use the standard candles for all computation.

I think what you have requested is:

  1. Hull moving average that changes color the same as the built-in version that comes with Thinkorswim
  2. Arrows that plot at the same location the Hull moving average changes color
  3. Alerts that are triggered at the same time to arrows appear
  4. Background color changing to reflect the current direction of the Hull moving average

Here is the code that ticks all of those boxes:

input price = close;
input length = 5;
input displace = 0;
plot hma = MovingAverage(AverageType.HULL, price, length)[-displace];
hma.DefineColor("Up", GetColor(1));
hma.DefineColor("Down", GetColor(0));
hma.AssignValueColor(if hma > hma[1] then hma.Color("Up") else hma.Color("Down"));
AssignBackgroundColor(if hma > hma[1] then CreateColor(0, 125, 51) else CreateColor (125, 50, 51));
plot upArrow = hma > hma[1] and hma[1] < hma[2];
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetDefaultColor(Color.BLUE);
upArrow.SetLineWeight(3);
plot downArrow = hma < hma[1] and hma[1] > hma[2];
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downArrow.SetDefaultColor(Color.YELLOW);
downArrow.SetLineWeight(3);
Alert(upArrow, “Trend Up”, Alert.BAR, Sound.DING);
Alert(downArrow, “Trend Down”, Alert.BAR, Sound.CHIMES);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 19, 2020 11:55 am
0
Thank you so much for your help. It worked EXACTLY as I needed. It amazes me how much time it takes me to work on coding and how wrong I get it and how little time it takes you to work on the script and how perfectly you accomplish what you want. Thanks again
( at May 22, 2020 4:32 pm)