Hi, need support in creating a simple indicator with following criteria:
If at least one of the last 5 Hieken Ashi candles have body size 20% of its total length, return true.
Colour of the candle doesn’t matter.
Thanks a million in advance.
The below code should do the job.
xClose = (open+high+low+close)/4
IF BarIndex=0 THEN
xOpen = open
xHigh = high
xLow = low
ELSe
xOpen = (xOpen[1] + xClose[1])/2
xHigh = Max(Max(high, xOpen), xClose)
xLow = Min(Min(low, xOpen), xClose)
ENDIF
harange = xhigh-xlow
habody = abs(xclose-xopen)
test = summation[5](habody>=.2*harange)>0
return test
There you go:
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
xRange = xHigh - xLow
xBody = abs(xClose - xOpen)
Cond = xBody >= (xRange * 0.20) //Body is 20%+ of the range
Result = summation[5](Cond)
RETURN Result AS "Result"
you asked for “body is 20%”, but his would almost never return a true value, since being exactly 20% is so rare, if not impossible! So I added >= so that any candle that is equal to or exceeds 20% returns true. Should you want to be returned when the body is <= 20% just replace “>” with “<“.
The returned values are 0 to 5 (0=none, 1…5=the number of candles that match your criterion). With the indicator properties you may select either a line or a histogram.
I was writing while Nicolas posted.
Better two than none!
You can see two different ways of setting up the HA candlesticks.