Read the Beforeitsnews.com story here. Advertise at Before It's News here.
Profile image
By Traders Laboratory
Contributor profile | More stories
Story Views
Now:
Last hour:
Last 24 hours:
Total:

Amibroker "BB-MACD" Created by KelvinHand Using Dominant Cycle As Calculated by "Ehlers Autocorre

% of readers think this story is Fact. Add your two cents.


Hi

Using Amibroker I would like to Plot the “BB-MACD” Created by KelvinHand
for a Variable time period Dominant Cycle as calculated by “Ehlers Autocorrelation Periodogram” code below

I have only able to plot the “BB-MACD” Created by KelvinHand
using the fixed time period of the last value of “Ehlers Autocorrelation Periodogram”

Hoping that you can help
Thanking you in advance

Best regards

Derek

///////////////////////////////////////////////

Code:

//Ehlers Autocorrelation Periodogram for Amibroker (AFL)

/*
        Autocorrelation Periodogram
        2013 John F. Ehlers
*/

SetBarsRequired(sbrAll);

LPeriod = Param("Low-pass Period", 10, 3, 20);
HPeriod = Param("High-pass Period", 48, 22, 80);
IsPlotHeatMap = ParamToggle("Show HeatMap?", "No|Yes", 1);
IsPlotDominantCycle = ParamToggle("Show Dom. Cycle?", "No|Yes");

pi=3.1415926;

function RoofingFilter(lpPeriod, hpPeriod)
{
        alpha1 = (cos(0.707*2*pi / hpPeriod) + sin(0.707*2*pi / hpPeriod) - 1) / cos(0.707*2*pi / hpPeriod);
        a1 = exp(-1.414*pi / lpPeriod);
        b1 = 2*a1*cos(1.414*pi / lpPeriod);
        c2 = b1;
        c3 = -a1*a1;
        c1 = 1 - c2 - c3;
       
        HP = Close;
        Filt = HP;
       
        for(i = 2; i         {
                HP[i] = ((1 - alpha1 / 2)^2)*(Close[i] - 2*Close[i-1] + Close[i-2]) + 2*(1 - alpha1)*HP[i-1] - ((1 - alpha1)^2)*HP[i-2];
                Filt[i] = c1*(HP[i] + HP[i-1]) / 2 + c2*Filt[i-1] + c3*Filt[i-2];
        }
       
        return Filt;
}

function AGC(lowerCutoff, higherCutoff, acceptableSlope)
{       
        factor = 0;
        accSlope = -acceptableSlope;        //acceptableSlope = 1.5 dB
        halfLC = lowerCutoff / 2;
        halfHC = higherCutoff / 2;
        ratio = 10^(accSlope/20);
        if(halfHC - halfLC > 0)
                factor = ratio^(1/(halfHC - halfLC));
        return factor;
}

function AutocorrelationPeriodogram(data, isHeatMap, isDomCyc)
{
        avgLength = 3;
        dominantCycle = 0;

        //Pearson correlation for each value of lag
        for(lag = 0; lag         {
                //Set the average length as M
                M = avgLength;
                if(avgLength == 0)
                        M = lag;
                //Initialize correlation sums
                Sx = 0;
                Sy = 0;
                Sxx = 0;
                Syy = 0;
                Sxy = 0;
                //Advance samples of both data streams and sum Pearson components
                for(count = 0; count                 {
                        X = Ref(data, -count);
                        Y = Ref(data, -(lag + count));
                        Sx += X;
                        Sy += Y;
                        Sxx += X^2;
                        Syy += Y^2;
                        Sxy += X*Y;
                }
                var1 = (M*Sxx - Sx^2)*(M*Syy - Sy^2);
                VarSet("corr" + lag, IIf(var1 > 0, (M*Sxy - Sx*Sy)/sqrt(var1), 0));        //Compute correlation for each value of lag
                //VarSet("corrScale" + lag, IIf(var1 > 0, 0.5*((M*Sxy - Sx*Sy)/sqrt(var1) + 1), 0));        //Scale each correlation to range between 0 and 1
        }
       
        /*//Plot as a Heatmap (for scale each correlation to range between 0 and 1)
        for(period = 3; period         {
                corr = VarGet("corrScale" + period);
                Red = IIf(corr > 0.5, 255*(2 - 2*corr), 255);
                Green = IIf(corr > 0.5, 255, 2*255*corr);
                PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel);
        }*/
       
        /*
                The DFT is accomplished by correlating the autocorrelation at each value of lag with the cosine and sine of each period of interest.
                The sum of the squares of each of these values represents the relative power at each period.
        */
        for(period = 10; period         {
                cosinePart = 0;
                sinePart = 0;
               
                for(n = 3; n                 {
                        cosinePart += VarGet("corr" + n)*cos(2*pi*n / period);
                        sinePart += VarGet("corr" + n)*sin(2*pi*n / period);
                }
                VarSet("sqSum" + period, cosinePart^2 + sinePart^2);
        }
       
        //EMA is used to smooth the power measurement at each period
        for(period = 10; period                 VarSet("r" + period, AMA((VarGet("sqSum" + period))^2, 0.2));

        //Find Maximum Power Level for Normalization
        K = AGC(10, 48, 1.5);
        for(period = 10; period         {
                if(period == 10)
                        VarSet("maxPwr", 0);               
                VarSet("maxPwr", IIf(VarGet("r" + period) > VarGet("maxPwr"), K*VarGet("r" + period), VarGet("maxPwr")));
        }
       
        //Normalization power
        for(period = 10; period                 VarSet("pwr" + period, VarGet("r" + period)/VarGet("maxPwr"));
               
        //Compute the dominant cycle using the CG of the spectrum
        Spx = 0;
        Sp = 0;
        for(period = 10; period         {
                Spx += IIf(VarGet("pwr" + period) >= 0.5,  period*VarGet("pwr" + period), 0);
                Sp += IIf(VarGet("pwr" + period) >= 0.5, VarGet("pwr" + period), 0);
        }
        dominantCycle = IIf(Sp != 0, Spx / Sp, 0);
        dominantCycle =(dominantCycle);
       
        if(isHeatMap)
        {
                //Plot as a Heatmap
                for(period = 10; period                 {
                        pwr = VarGet("pwr" + period);
                        Red = IIf(pwr > 0.5, 255, 2*255*pwr);
                        Green = IIf(pwr > 0.5, 255*(2*pwr - 1), 0);
                        PlotOHLC( period-1, period-1, period, period, "", ColorRGB( Red, Green, 0 ), styleCloud | styleNoLabel, Null, Null, 0, 0);
                }
        }
       
        if(isDomCyc)
                Plot(LastValue(dominantCycle,1), "Dominant Cycle", colorBlue, styleThick, Null, Null, 0, 1);

        pds=LastValue(dominantCycle,1);

//"BB-MACD")    Created by KelvinHand
       
SetChartBkColor( ParamColor("background",colorBlack) );
A1=EMA(C,pds/2)-EMA(C,pds);
BBtop=BBandTop(A1,10,1);
BBbot=BBandBot(A1,10,1);
Color=IIf(a1<0 AND a1>Ref(a1,-1), colorLime,IIf(a1>0 AND a1>Ref(a1,-1),colorBrightGreen,IIf(a1>0 AND a1
Plot(a1,"MACD",color,styleThick+styleLine);
Plot(BBtop,"BBtop",colorWhite,styleDashed);
Plot(BBbot,"BBbot",colorWhite,styleDashed);
Plot(0,"",colorWhite,1);

        AddColumn(round(dominantCycle), " DominantCycle", 2.0 ,  colorRed, colorLightYellow,50) ;

        return dominantCycle;

}

filtData = RoofingFilter(LPeriod, HPeriod);
AutocorrelationPeriodogram(filtData, IsPlotHeatMap, IsPlotDominantCycle);



Source: http://www.traderslaboratory.com/forums/trading-indicators/20476-amibroker-bb-macd-created-kelvinhand-using.html


Before It’s News® is a community of individuals who report on what’s going on around them, from all around the world.

Anyone can join.
Anyone can contribute.
Anyone can become informed about their world.

"United We Stand" Click Here To Create Your Personal Citizen Journalist Account Today, Be Sure To Invite Your Friends.

Before It’s News® is a community of individuals who report on what’s going on around them, from all around the world. Anyone can join. Anyone can contribute. Anyone can become informed about their world. "United We Stand" Click Here To Create Your Personal Citizen Journalist Account Today, Be Sure To Invite Your Friends.


LION'S MANE PRODUCT


Try Our Lion’s Mane WHOLE MIND Nootropic Blend 60 Capsules


Mushrooms are having a moment. One fabulous fungus in particular, lion’s mane, may help improve memory, depression and anxiety symptoms. They are also an excellent source of nutrients that show promise as a therapy for dementia, and other neurodegenerative diseases. If you’re living with anxiety or depression, you may be curious about all the therapy options out there — including the natural ones.Our Lion’s Mane WHOLE MIND Nootropic Blend has been formulated to utilize the potency of Lion’s mane but also include the benefits of four other Highly Beneficial Mushrooms. Synergistically, they work together to Build your health through improving cognitive function and immunity regardless of your age. Our Nootropic not only improves your Cognitive Function and Activates your Immune System, but it benefits growth of Essential Gut Flora, further enhancing your Vitality.



Our Formula includes: Lion’s Mane Mushrooms which Increase Brain Power through nerve growth, lessen anxiety, reduce depression, and improve concentration. Its an excellent adaptogen, promotes sleep and improves immunity. Shiitake Mushrooms which Fight cancer cells and infectious disease, boost the immune system, promotes brain function, and serves as a source of B vitamins. Maitake Mushrooms which regulate blood sugar levels of diabetics, reduce hypertension and boosts the immune system. Reishi Mushrooms which Fight inflammation, liver disease, fatigue, tumor growth and cancer. They Improve skin disorders and soothes digestive problems, stomach ulcers and leaky gut syndrome. Chaga Mushrooms which have anti-aging effects, boost immune function, improve stamina and athletic performance, even act as a natural aphrodisiac, fighting diabetes and improving liver function. Try Our Lion’s Mane WHOLE MIND Nootropic Blend 60 Capsules Today. Be 100% Satisfied or Receive a Full Money Back Guarantee. Order Yours Today by Following This Link.


Report abuse

    Comments

    Your Comments
    Question   Razz  Sad   Evil  Exclaim  Smile  Redface  Biggrin  Surprised  Eek   Confused   Cool  LOL   Mad   Twisted  Rolleyes   Wink  Idea  Arrow  Neutral  Cry   Mr. Green

    MOST RECENT
    Load more ...

    SignUp

    Login

    Newsletter

    Email this story
    Email this story

    If you really want to ban this commenter, please write down the reason:

    If you really want to disable all recommended stories, click on OK button. After that, you will be redirect to your options page.