bgc free

by djigue1899 in category Trend at 17/04/2022
Description

centre de gravite de belkhayat

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]

    public class BelkhayateCog : Indicator
    {

        [Parameter("Degree", DefaultValue = 3, MinValue = 0)]
        public int degree { get; set; }

        [Parameter("Period", DefaultValue = 270, MinValue = 0)]
        public int period { get; set; }

        [Parameter("strdDev", DefaultValue = 0, MinValue = 0)]
        public double strdDev { get; set; }

        [Parameter("strdDev2", DefaultValue = 1.618, MinValue = 0)]
        public double strdDev2 { get; set; }

        [Parameter("strdDev3", DefaultValue = 2.618, MinValue = 0)]
        public double strdDev3 { get; set; }

        public IndicatorDataSeries Prc { get; set; }

        [Output("SQL2", Color = Colors.Red)]
        public IndicatorDataSeries Sql2 { get; set; }

        [Output("SQL3", Color = Colors.Red)]
        public IndicatorDataSeries Sql3 { get; set; }

        [Output("SQL", Color = Colors.Red)]
        public IndicatorDataSeries Sql { get; set; }

        [Output("SQH", Color = Colors.Green)]
        public IndicatorDataSeries Sqh { get; set; }

        [Output("SQH2", Color = Colors.Green)]
        public IndicatorDataSeries Sqh2 { get; set; }

        [Output("SQH3", Color = Colors.Green)]
        public IndicatorDataSeries Sqh3 { get; set; }

        private IndicatorDataSeries prc;
        private IndicatorDataSeries sql2;
        private IndicatorDataSeries sqh2;
        private IndicatorDataSeries sql;
        private IndicatorDataSeries sqh;
        private IndicatorDataSeries sqh3;
        private IndicatorDataSeries sql3;
        ////////////////////////////////////////////////////////////////////
        //////////////////////HelpFull Settings//////////////////////////////
        //int degree = 3;
        //int period = 270;
        //int strdDev = 0;
        //double strdDev2 = 1.618;
        //double strdDev3 = 2.618;
        /////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////
        double[,] ai = new double[10, 10];
        double[] b = new double[10];
        double[] x = new double[10];
        double[] sx = new double[10];
        double sum;
        int ip;
        int p;
        int n;
        double qq;
        double mm;
        double tt;
        int ii;
        int jj;
        int kk;
        int ll;
        int nn;
        double sq;
        double sq2;
        double sq3;
        int i0 = 0;
        int mi;

        protected override void Initialize()
        {
            prc = CreateDataSeries();
            sql2 = CreateDataSeries();
            sqh2 = CreateDataSeries();
            sql = CreateDataSeries();
            sqh = CreateDataSeries();
            sqh3 = CreateDataSeries();
            sql3 = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            try
            {
                if (Bars.Count < period)
                {
                    return;
                }

                //int i = index;
                ip = period;
                p = ip;
                sx[1] = p + 1;
                nn = degree + 1;
                //----------------------sx-------------------------------------------------------------------
                // 

                for (mi = 1; mi <= nn * 2 - 2; mi++)
                {
                    sum = 0;
                    for (n = i0; n <= i0 + p; n++)
                    {
                        sum += Math.Pow(n, mi);
                    }
                    sx[mi + 1] = sum;
                }
                //----------------------syx-----------

                for (mi = 1; mi <= nn; mi++)
                {
                    sum = 0.0;
                    for (n = i0; n <= i0 + p; n++)
                    {
                        if (mi == 1)
                            sum += Bars.ClosePrices[index - n];
                        else
                            sum += Bars.ClosePrices[index - n] * Math.Pow(n, mi - 1);
                    }
                    b[mi] = sum;
                }
                //===============Matrix=======================================================================================================

                for (jj = 1; jj <= nn; jj++)
                {
                    for (ii = 1; ii <= nn; ii++)
                    {
                        kk = ii + jj - 1;
                        ai[ii, jj] = sx[kk];
                    }
                }

                //===============Gauss========================================================================================================
                for (kk = 1; kk <= nn - 1; kk++)
                {
                    ll = 0;
                    mm = 0;
                    for (ii = kk; ii <= nn; ii++)
                    {
                        if (Math.Abs(ai[ii, kk]) > mm)
                        {
                            mm = Math.Abs(ai[ii, kk]);
                            ll = ii;
                        }
                    }
                    if (ll == 0)
                        return;
                    if (ll != kk)
                    {
                        for (jj = 1; jj <= nn; jj++)
                        {
                            tt = ai[kk, jj];
                            ai[kk, jj] = ai[ll, jj];
                            ai[ll, jj] = tt;
                        }
                        tt = b[kk];
                        b[kk] = b[ll];
                        b[ll] = tt;
                    }
                    for (ii = kk + 1; ii <= nn; ii++)
                    {
                        qq = ai[ii, kk] / ai[kk, kk];
                        for (jj = 1; jj <= nn; jj++)
                        {
                            if (jj == kk)
                                ai[ii, jj] = 0;
                            else
                                ai[ii, jj] = ai[ii, jj] - qq * ai[kk, jj];
                        }
                        b[ii] = b[ii] - qq * b[kk];
                    }
                }

                x[nn] = b[nn] / ai[nn, nn];
                for (ii = nn - 1; ii >= 1; ii--)
                {
                    tt = 0;
                    for (jj = 1; jj <= nn - ii; jj++)
                    {
                        tt = tt + ai[ii, ii + jj] * x[ii + jj];
                        x[ii] = (1 / ai[ii, ii]) * (b[ii] - tt);
                    }
                }
                sq = 0.0;
                sq2 = 0.0;
                sq3 = 0.0;
                for (n = i0; n <= i0 + p; n++)
                {
                    sum = 0;
                    for (kk = 1; kk <= degree; kk++)
                    {
                        sum += x[kk + 1] * Math.Pow(n, kk);
                    }

                    prc[index - n] = (x[1] + sum);
                    sq += Math.Pow(Bars.ClosePrices[index - n] - prc[index - n], 2);
                    sq2 = sq;
                    sq3 = sq;
                }

                sq = Math.Sqrt(sq / (p + 1)) * strdDev;
                sq2 = Math.Sqrt(sq2 / (p + 1)) * strdDev2;
                sq3 = Math.Sqrt(sq3 / (p + 1)) * strdDev3;
                Sqh[index] = sqh[index - 1];
                Sqh2[index] = sqh2[index - 4];
                Sqh3[index] = sqh3[index - 6];
                Sql[index] = sql[index - 2];
                Sql2[index] = sql2[index - 3];
                Sql3[index] = sql3[index - 5];

                for (n = 0; n <= period; n++)
                {

                    Sqh[index - n] = prc[index - n] + sq;
                    Sqh2[index - n] = prc[index - n] + sq2;
                    Sqh3[index - n] = prc[index - n] + sq3;
                    Sql[index - n] = prc[index - n] - sq;
                    Sql2[index - n] = prc[index - n] - sq2;
                    Sql3[index - n] = prc[index - n] - sq3;

                }


            } catch (Exception e)
            {
                Print("Error : {0}", e);
            }

        }
    }
}
Comments

streetview890 - April 22, 2022 @ 18:36

thanks. I was looking for this formula everywhere

cookie clicker

shemikasoraya9081 - April 29, 2022 @ 05:47

The previous version of this library was using CSV files too, but due to performance issues, I switched to LiteDB.

 

Family Lawyer

thomassnow623 - May 14, 2022 @ 17:21

Thanks for sharing this is such a great blog that you are providing and you give it away for free.

Take Online Exam Help Now

0