Higher Time Frame Heikin-Ashi and EMA Histogram


Category:
0
0

Hello Pete,

I would like to request that a study that I found useful be converted into a histogram. The study that I intend to convert into a histogram is as follows,


def cl = close(period=aggregationPeriod.THirty_MIN);

def op = open(period=aggregationPeriod.THirty_MIN);

def hi = high(period=aggregationPeriod.THirty_MIN);

def lo = high(period=aggregationPeriod.THirty_MIN);

def EM35 = MovAvgExponential(cl,35);

def haC = (op + hi + lo + cl)/4 ;

def haO = (haO[1] +haC[1])/2 ;

def haL = min(min(lo,haO),haC);

def haH = max(max(hi,haO),haC);

def Per_1 = (((hac[3] – haC)/haC)*100);

def Per_2 = (((EM35[3] – EM35)/EM35)*100);

def Histogram value = Per_1 + Per_2 ; “

The color of the histogram should be in a similar pattern to that of a MACD. If the Histogram value is negative, the color should be red; otherwise, the color should be green. It should also be able to track histogram bars where the value has increased/decreased from its previous histogram bar (by changing the histogram bar colors just like MACD). Any help is much appreciated.

Thank you

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on March 5, 2023 1:28 pm
84 views
0
Private answer

In this forum the goal is to produce solutions which serve the majority of our viewers so I have adapted your code to allow for adjustments without modifying the code. I also updated the title of your question to include a bit more context. This will make it easier for other viewers to locate this solution using the search function.

I also cleaned up the code to make it easier to read and correct syntax errors. For those interested in how I solved to core question... All I did was copy the lines of code controlling the plot style of the built-in study named "MACDHistogram". Before I show my solution, here is the section of code I copied from the MACDHistogram study:

Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));

Your code did not include a plot statement. So I had to convert that last line of your code from 'def' to 'plot'. And I also had to fix the name of that variable because your code contained a syntax error which made it fail. So the variable you named "Histogram value" was replaced with a valid variable name of "histogramValue". Here is my solution:

declare lower;
input timeFrameOne = AggregationPeriod.THIRTY_MIN;
input emaLength = 35;
def priceClose = close(period = timeFrameOne);
def priceOpen = open(period = timeFrameOne);
def priceHigh = high(period = timeFrameOne);
def priceLow = high(period = timeFrameOne);
def maOne = MovAvgExponential(priceClose, emaLength);
def haClose = (priceOpen + priceHigh + priceLow + priceClose) / 4 ;
def haOpen = (haOpen[1] + haClose[1]) / 2 ;
def valueOne = ((haClose[3] – haClose) / haClose) * 100;
def valueTwo = ((maOne[3] – maOne) / maOne) * 100;
plot histogramValue = valueOne + valueTwo;
histogramValue.SetDefaultColor(GetColor(5));
histogramValue.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogramValue.SetLineWeight(3);
histogramValue.DefineColor("Positive and Up", Color.GREEN);
histogramValue.DefineColor("Positive and Down", Color.DARK_GREEN);
histogramValue.DefineColor("Negative and Down", Color.RED);
histogramValue.DefineColor("Negative and Up", Color.DARK_RED);
histogramValue.AssignValueColor(if histogramValue >= 0 then if histogramValue > histogramValue[1] then histogramValue.color("Positive and Up") else histogramValue.color("Positive and Down") else if histogramValue < histogramValue[1] then histogramValue.color("Negative and Down") else histogramValue.color("Negative and Up"));

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 5, 2023 5:16 pm
0
Thanks a lot, Pete
( at March 5, 2023 7:31 pm)