Page 1 of 6

Heikin-Ashi Smoothed

PostPosted: Sun Apr 11, 2010 8:14 pm
by Nikolay.Gekht
HASM.png

The Heikin-Ashi smoothed indicator is similar to the regular Heikin-Ashi, but:

a) uses the smoothed open, close, high and low prices
b) smooths the candles

So, formula of the indicator is:

open = MVA(MVA(OPEN, N1)[-1] + MVA(CLOSE, N1) / 2, N2)
close = MVA(MVA(OPEN, N1) + MVA(CLOSE, N1) + MVA(HIGH, N1) + MVA(LOW, N1)/ 2, N2)
high = MAX(open, close, MVA(HIGH, N1), N2)
low = MIN(open, close, MVA(LOW, N1), N2)

By default, the indicator hides the source data and is shown instead of the source.
To show the both, source data and Heikin-Ashi chart:

1) Uncheck "Hide Source" on the "Data Source" tab of the indicator properties.
2) Check "Show indicator/oscillator in an new area..." on the "Location" tab of the indicator properties.

As the standard HA indicator, the HASM indicator result is a regular bar source, so you can apply any existing indicator on it.

HASM.lua
(5.88 KiB) Downloaded 3366 times

HASM with Alert.lua
(13.98 KiB) Downloaded 733 times

Transparent Heikin Ashi Smoothed.lua
(8.66 KiB) Downloaded 1122 times

MTF MCP Heikin-Ashi Smoothed.png

MTF MCP Heikin-Ashi Smoothed.lua
(13.25 KiB) Downloaded 949 times

Indicator will show the current direction of Heikin-Ashi Smoothed indicator for all selected time frames and currency pairs.
Active Cross is graphically presented.
MTF MCP Heikin-Ashi Smoothed.png

MTF MCP Heikin-Ashi Smoothed (2).lua
(11.71 KiB) Downloaded 777 times

A similar indicator can be found here.
viewtopic.php?f=17&t=63347&p=105655#p105655

The indicator was revised and updated

Re: Heikin-Ashi Smoothed

PostPosted: Thu May 27, 2010 4:30 pm
by koyote44
Hi Nikolay,

i think you have missing a part in your code.
see lines 60 and 75

[upd by ng:]
Download:
HASM.lua
(5.32 KiB) Downloaded 3233 times


The original version does not use, in fact, the specified N1 and N2 parameters, so, therefore, the default Moving Average parameter is used. This update fixes this error.

Code: Select all
function Init()
    indicator:name("Heikin-Ashi Smoothed");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);
    indicator:setTag("group", "Trend");
    indicator:setTag("replaceSource", "t");

    indicator.parameters:addString("Method1", "The smoothing method for prices", "The methods marked by the star (*) requires to have approriate indicators installed", "MVA");
    indicator.parameters:addStringAlternative("Method1", "MVA", "", "MVA");
    indicator.parameters:addStringAlternative("Method1", "EMA", "", "EMA");
    indicator.parameters:addStringAlternative("Method1", "LWMA", "", "LWMA");
    indicator.parameters:addStringAlternative("Method1", "SMMA*", "", "SMMA");
    indicator.parameters:addStringAlternative("Method1", "Vidya (1995)*", "", "VIDYA");
    indicator.parameters:addStringAlternative("Method1", "Vidya (1992)*", "", "VIDYA92");
    indicator.parameters:addStringAlternative("Method1", "Wilders*", "", "WMA");

    indicator.parameters:addInteger("N1", "Periods to smooth prices", "", 6, 1, 1000);

    indicator.parameters:addString("Method2", "The smoothing method for candles", "The methods marked by the star (*) requires to have approriate indicators installed", "MVA");
    indicator.parameters:addStringAlternative("Method2", "MVA", "", "MVA");
    indicator.parameters:addStringAlternative("Method2", "EMA", "", "EMA");
    indicator.parameters:addStringAlternative("Method2", "LWMA", "", "LWMA");
    indicator.parameters:addStringAlternative("Method2", "SMMA*", "", "SMMA");
    indicator.parameters:addStringAlternative("Method2", "Vidya (1995)*", "", "VIDYA");
    indicator.parameters:addStringAlternative("Method2", "Vidya (1992)*", "", "VIDYA92");
    indicator.parameters:addStringAlternative("Method2", "Wilders*", "", "WMA");

    indicator.parameters:addInteger("N2", "Periods to smooth candles", "", 6, 1, 1000);
end

local smopen = nil;
local smhigh = nil;
local smlow = nil;
local smclose = nil;

local iopen = nil;
local ihigh = nil;
local ilow = nil;
local iclose = nil;

local smiopen = nil;
local smihigh = nil;
local smilow = nil;
local smiclose = nil;

local open = nil;
local high = nil;
local low = nil;
local close = nil;

local first1 = 0;
local first2 = 0;

-- Routine
function Prepare()
    source = instance.source;
   
    -- was missing, so N1 was not set
    local N1 = instance.parameters.N1;
   
    smopen = core.indicators:create(instance.parameters.Method1, source.open, N1);
    smclose = core.indicators:create(instance.parameters.Method1, source.close, N1);
    smhigh = core.indicators:create(instance.parameters.Method1, source.high, N1);
    smlow = core.indicators:create(instance.parameters.Method1, source.low, N1);

    first1 = smopen.DATA:first() + 1;

    iopen = instance:addInternalStream(first1, 0);
    iclose = instance:addInternalStream(first1, 0);
    ihigh = instance:addInternalStream(first1, 0);
    ilow = instance:addInternalStream(first1, 0);
   
    -- was missing, so N2 was not set
    local N2 = instance.parameters.N2;
   
    smiopen = core.indicators:create(instance.parameters.Method2, iopen, N2);
    smiclose = core.indicators:create(instance.parameters.Method2, iclose, N2);
    smihigh = core.indicators:create(instance.parameters.Method2, ihigh, N2);
    smilow = core.indicators:create(instance.parameters.Method2, ilow, N2);

    first2 = smiopen.DATA:first() + 1;

    local name = "Heikin-Ashi Smoothed" .. "(" .. source:name() .. "," .. instance.parameters.Method1 .. "(" .. instance.parameters.N1 .. ")," .. instance.parameters.Method2 .. "(" .. instance.parameters.N2.. "))"
    instance:name(name);
    open = instance:addStream("open", core.Line, name, "open", core.rgb(0, 0, 0), first2)
    high = instance:addStream("high", core.Line, name, "high", core.rgb(0, 0, 0), first2)
    low = instance:addStream("low", core.Line, name, "low", core.rgb(0, 0, 0), first2)
    close = instance:addStream("close", core.Line, name, "close", core.rgb(0, 0, 0), first2)
    instance:createCandleGroup("HAS", "HAS", open, high, low, close);
end

-- Indicator calculation routine
function Update(period, mode)
    -- smooth source
    smopen:update(mode);
    smhigh:update(mode);
    smlow:update(mode);
    smclose:update(mode);

    if period >= first1 then
        -- calculate candles
        if (period == first1) then
            iopen[period] = (smopen.DATA[period - 1] + smclose.DATA[period - 1]) / 2;
        else
            iopen[period] = (iopen[period - 1] + iclose[period - 1]) / 2;
        end
        iclose[period] = (smopen.DATA[period] + smhigh.DATA[period] + smlow.DATA[period] + smclose.DATA[period]) / 4;
        ihigh[period] = math.max(iopen[period], iclose[period], smhigh.DATA[period]);
        ilow[period] = math.min(iopen[period], iclose[period], smlow.DATA[period]);

        -- smooth candles
        smiopen:update(mode);
        smihigh:update(mode);
        smilow:update(mode);
        smiclose:update(mode);
    end

    if period >= first2 then
        open[period] = smiopen.DATA[period];
        close[period] = smiclose.DATA[period];
        high[period] = math.max(open[period], close[period], smihigh.DATA[period]);
        low[period] = math.min(open[period], close[period], smilow.DATA[period]);
    end
end

Re: Heikin-Ashi Smoothed

PostPosted: Thu May 27, 2010 7:43 pm
by Nikolay.Gekht
Thank you very much for spotting and fixing the problem.

Re: Heikin-Ashi Smoothed

PostPosted: Fri May 13, 2011 9:49 am
by kitar01
all ok but this indicator cancel all the candles and do not allow to watch both...

Re: Heikin-Ashi Smoothed

PostPosted: Fri May 13, 2011 9:56 am
by kitar01
ok it is working.
would be better if we can have a separated colour option...
thank you

Re: Heikin-Ashi Smoothed

PostPosted: Fri May 13, 2011 11:26 am
by Apprentice
Color option added.
HASM.lua
(5.88 KiB) Downloaded 2722 times

Re: Heikin-Ashi Smoothed

PostPosted: Mon May 16, 2011 4:03 am
by lisa_baby_xx
Hi,

I have only yesterday discoverd the joy of the Heikin-Ashi Smoothed Indicator.

:?: Is there a signal available for this type of indicator? One that signals when the bars change colour?

Many thanks and much love. XX
lisa_baby_xx

Re: Heikin-Ashi Smoothed

PostPosted: Mon May 16, 2011 5:22 am
by Apprentice
Signal that you seek is available here.
viewtopic.php?f=29&t=2344&p=5013&hilit=Heikin+Ashi#p5013

Re: Heikin-Ashi Smoothed

PostPosted: Mon May 16, 2011 5:24 am
by lisa_baby_xx
Thanks sweetie. XX. ;)

lisa_baby_xx

Re: Heikin-Ashi Smoothed

PostPosted: Wed Jul 06, 2011 1:48 pm
by Platinum
Hi,

I love this indicator. Can anyone please explain wht MVA is?

I would like to program this indcator into excel Can anyone please help me with the formula? Any help would be greatly appreciated.

Many Thanks