KF_Mtf_MacdStoc_v1 free

by gmkenneyy in category Trend at 09/11/2022
Description

A great indicator that combines the Macd & Stochastics of different timefames to give you a birds eye view of the current chart

Will find time to put all the code in just one class and then re-upload. At the momment only coders will know what to do with this current code. Bear with me.

 

 

** Source code **

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    public class ErrorMessage : CustomControl
    {
        public ErrorMessage(string text)
        {
            VerticalAlignment = VerticalAlignment.Center;
            HorizontalAlignment = HorizontalAlignment.Center;
            IsHitTestVisible = false;

            var border = new Border 
            {
                CornerRadius = 8,
                Padding = "40 20",
                BorderColor = Color.DimGray,
                BackgroundColor = "#aa3b3b3b",
                BorderThickness = 1
            };

            var textBlock = new TextBlock 
            {
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Text = text,
                ForegroundColor = Color.White
            };

            border.Child = textBlock;
            AddChild(border);
        }
    }

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class KF_Mtf_MacdStoc_v1 : Indicator
    {
        [Parameter(DefaultValue = "26|12|9", Group = "Macd")]
        public string D3_L_S_Sig { get; set; }

        [Parameter(DefaultValue = "26|12|9", Group = "Macd")]
        public string D1_L_S_Sig { get; set; }

        [Parameter(DefaultValue = "26|12|9", Group = "Macd")]
        public string H4_L_S_Sig { get; set; }

        [Parameter(DefaultValue = "26|12|9", Group = "Macd")]
        public string H1_L_S_Sig { get; set; }



        [Parameter(DefaultValue = "9|3|3", Group = "Stochastic")]
        public string D3_kP_kS_dP { get; set; }

        [Parameter(DefaultValue = "9|3|3", Group = "Stochastic")]
        public string D1_kP_kS_dP { get; set; }

        [Parameter(DefaultValue = "9|3|3", Group = "Stochastic")]
        public string H4_kP_kS_dP { get; set; }

        [Parameter(DefaultValue = "9|3|3", Group = "Stochastic")]
        public string H1_kP_kS_dP { get; set; }



        [Parameter("Vertical position", Group = "Dashboard", DefaultValue = VerticalAlignment.Bottom)]
        public VerticalAlignment DB_Vert_Posn { get; set; }

        [Parameter("Horizontal position", Group = "Dashboard", DefaultValue = HorizontalAlignment.Right)]
        public HorizontalAlignment DB_Horz_Posn { get; set; }


        private Bars D3_brs, D1_brs, H4_brs, H1_brs;
        private StochasticOscillator D3_sto, D1_sto, H4_sto, H1_sto;
        private MacdCrossOver D3_mco, D1_mco, H4_mco, H1_mco;


        private Button btnD3_sto, btnD1_sto, btnH4_sto, btnH1_sto;
        private Button btnD3_mco, btnD1_mco, btnH4_mco, btnH1_mco;
        private Button btnMicro, btnMacro;

        private readonly Color clrBU = Color.FromHex("#009345"), clrBE = Color.FromHex("#F05824");

        private Button RenderBtn(string txt, int btnHeight = 1, int btnHwidth = 110)
        {
            return new Button 
            {
                Width = btnHwidth,
                Height = 20 * btnHeight,
                Margin = 2,
                Text = txt,
                ForegroundColor = Color.Snow,
                FontWeight = FontWeight.Light,
                FontSize = 10,
                FontFamily = "Arial"
            };
        }

        protected override void Initialize()
        {
            RefreshData();

            H1_brs = MarketData.GetBars(TimeFrame.Hour);
            H4_brs = MarketData.GetBars(TimeFrame.Hour4);
            D1_brs = MarketData.GetBars(TimeFrame.Daily);
            D3_brs = MarketData.GetBars(TimeFrame.Day3);

            while (H1_brs.OpenTimes[0] > Bars.OpenTimes[0])
                H1_brs.LoadMoreHistory();
            while (H4_brs.OpenTimes[0] > Bars.OpenTimes[0])
                H4_brs.LoadMoreHistory();



            D3_mco = Indicators.MacdCrossOver(D3_brs.ClosePrices, D3_L_S_Sig.GV(0), D3_L_S_Sig.GV(1), D3_L_S_Sig.GV(2));
            D1_mco = Indicators.MacdCrossOver(D1_brs.ClosePrices, D1_L_S_Sig.GV(0), D1_L_S_Sig.GV(1), D1_L_S_Sig.GV(2));
            H4_mco = Indicators.MacdCrossOver(H4_brs.ClosePrices, H4_L_S_Sig.GV(0), H4_L_S_Sig.GV(1), H4_L_S_Sig.GV(2));
            H1_mco = Indicators.MacdCrossOver(H1_brs.ClosePrices, H1_L_S_Sig.GV(0), H1_L_S_Sig.GV(1), H1_L_S_Sig.GV(2));


            D3_sto = Indicators.StochasticOscillator(D3_brs, D3_kP_kS_dP.GV(0), D3_kP_kS_dP.GV(1), D3_kP_kS_dP.GV(2), MovingAverageType.Simple);
            D1_sto = Indicators.StochasticOscillator(D1_brs, D1_kP_kS_dP.GV(0), D1_kP_kS_dP.GV(1), D1_kP_kS_dP.GV(2), MovingAverageType.Simple);
            H4_sto = Indicators.StochasticOscillator(H4_brs, H4_kP_kS_dP.GV(0), H4_kP_kS_dP.GV(1), H4_kP_kS_dP.GV(2), MovingAverageType.Simple);
            H1_sto = Indicators.StochasticOscillator(H1_brs, H1_kP_kS_dP.GV(0), H1_kP_kS_dP.GV(1), H1_kP_kS_dP.GV(2), MovingAverageType.Simple);

            const int half = 55;

            var hdr_St = RenderBtn("Stoc", 1, half);
            var hdr_Md = RenderBtn("Macd", 1, half);

            btnD3_sto = RenderBtn("D3", 1, half);
            btnD3_mco = RenderBtn("D3", 1, half);
            btnD1_sto = RenderBtn("D1", 1, half);
            btnD1_mco = RenderBtn("D1", 1, half);
            btnH4_sto = RenderBtn("H4", 1, half);
            btnH4_mco = RenderBtn("H4", 1, half);
            btnH1_sto = RenderBtn("H1", 1, half);
            btnH1_mco = RenderBtn("H1", 1, half);

            btnMicro = RenderBtn("Micro-trend", 2, 116);
            btnMacro = RenderBtn("Macro-trend", 2, 116);

            var d3_Hd = new WrapPanel 
            {
                Orientation = Orientation.Horizontal
            };
            d3_Hd.AddChild(hdr_St);
            d3_Hd.AddChild(hdr_Md);

            var d3_Wp = new WrapPanel 
            {
                Orientation = Orientation.Horizontal
            };
            d3_Wp.AddChild(btnD3_sto);
            d3_Wp.AddChild(btnD3_mco);

            var d1_Wp = new WrapPanel 
            {
                Orientation = Orientation.Horizontal
            };
            d1_Wp.AddChild(btnD1_sto);
            d1_Wp.AddChild(btnD1_mco);

            var h4_Wp = new WrapPanel 
            {
                Orientation = Orientation.Horizontal
            };
            h4_Wp.AddChild(btnH4_sto);
            h4_Wp.AddChild(btnH4_mco);

            var h1_Wp = new WrapPanel 
            {
                Orientation = Orientation.Horizontal
            };
            h1_Wp.AddChild(btnH1_sto);
            h1_Wp.AddChild(btnH1_mco);

            var vSpacer = 2;

            var sp = new StackPanel 
            {
                VerticalAlignment = DB_Vert_Posn,
                HorizontalAlignment = DB_Horz_Posn
            };

            sp.AddChild(d3_Hd);
            sp.AddChild(d3_Wp);
            sp.AddChild(d1_Wp);
            sp.AddChild(h4_Wp);
            sp.AddChild(h1_Wp);

            sp.AddChild(new TextBlock 
            {
                Height = vSpacer
            });

            sp.AddChild(btnMacro);

            sp.AddChild(new TextBlock 
            {
                Height = vSpacer
            });

            sp.AddChild(btnMicro);

            var bdr = new Border 
            {
                CornerRadius = 8,
                Padding = "6 4",
                BorderColor = Color.DimGray,
                BackgroundColor = Color.White,
                //"#aa3b3b3b",
                BorderThickness = 1,
                Child = sp,
                Height = 224,
                Width = 136
            };

            this.Chart.AddControl(bdr);
        }

        public override void Calculate(int index)
        {
            const int BU = 1, BE = -1;

            var d3_stoBU = D3_sto.Dir(BU, index, Bars, D3_brs);
            var d3_stoBE = D3_sto.Dir(BE, index, Bars, D3_brs);
            btnD3_sto.BackgroundColor = d3_stoBU ? clrBU : d3_stoBE ? clrBE : Color.DarkGray;

            var d1_stoBU = D1_sto.Dir(BU, index, Bars, D1_brs);
            var d1_stoBE = D1_sto.Dir(BE, index, Bars, D1_brs);
            btnD1_sto.BackgroundColor = d1_stoBU ? clrBU : d1_stoBE ? clrBE : Color.DarkGray;

            var h4_stoBU = H4_sto.Dir(BU, index, Bars, H4_brs);
            var h4_stoBE = H4_sto.Dir(BE, index, Bars, H4_brs);
            btnH4_sto.BackgroundColor = h4_stoBU ? clrBU : h4_stoBE ? clrBE : Color.DarkGray;

            var h1_stoBU = H1_sto.Dir(BU, index, Bars, H1_brs);
            var h1_stoBE = H1_sto.Dir(BE, index, Bars, H1_brs);
            btnH1_sto.BackgroundColor = h1_stoBU ? clrBU : h1_stoBE ? clrBE : Color.DarkGray;


            var d3_macd_BU = D3_mco.Dir(BU, index, Bars, D3_brs);
            var d3_macd_BE = D3_mco.Dir(BE, index, Bars, D3_brs);
            btnD3_mco.BackgroundColor = d3_macd_BU ? clrBU : d3_macd_BE ? clrBE : Color.DarkGray;

            var d1_macd_BU = D1_mco.Dir(BU, index, Bars, D1_brs);
            var d1_macd_BE = D1_mco.Dir(BE, index, Bars, D1_brs);
            btnD1_mco.BackgroundColor = d1_macd_BU ? clrBU : d1_macd_BE ? clrBE : Color.DarkGray;

            var h4_macd_BU = H4_mco.Dir(BU, index, Bars, H4_brs);
            var h4_macd_BE = H4_mco.Dir(BE, index, Bars, H4_brs);
            btnH4_mco.BackgroundColor = h4_macd_BU ? clrBU : h4_macd_BE ? clrBE : Color.DarkGray;

            var h1_macd_BU = H1_mco.Dir(BU, index, Bars, H1_brs);
            var h1_macd_BE = H1_mco.Dir(BE, index, Bars, H1_brs);
            btnH1_mco.BackgroundColor = h1_macd_BU ? clrBU : h1_macd_BE ? clrBE : Color.DarkGray;


            var macBU = (!d3_macd_BE && d1_macd_BU) && (d3_macd_BU && !d1_macd_BE);
            var macBE = (!d3_macd_BU && d1_macd_BE) && (d3_macd_BE && !d1_macd_BU);

            btnMacro.BackgroundColor = macBU ? clrBU : macBE ? clrBE : Color.DarkGray;

            btnMicro.BackgroundColor = ((h1_macd_BU && !h1_macd_BE) || (!h1_macd_BE && h1_macd_BU)) ? clrBU : ((h1_macd_BE && !h1_macd_BU) || (!h1_macd_BU && h1_macd_BE)) ? clrBE : Color.DarkGray;

        }

    }
}

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 cAlgo.API;
using cAlgo.API.Indicators;
using System;

namespace cAlgo
{
    public static class Extensions
    {
        public static int GV(this String str, int idx)
        {
            var cleaned = str.Trim();

            if (cleaned.Length > 0)
            {
                var value = cleaned.Split("|".ToCharArray())[idx];

                int val;

                return int.TryParse(value, out val) ? val : -1;
            }
            else
                return -1;
        }

        public static bool Dir(this MacdCrossOver mco, int dir, int index, Bars lbrs, Bars hbrs)
        {
            bool ok = false;

            var idx = hbrs.OpenTimes.GetIndexByTime(lbrs.OpenTimes[index]);

            switch (dir)
            {
                case 1:
                    ok = mco.MACD[idx].CompareTo(mco.MACD[idx - 1]) > 0 && 
                         mco.MACD[idx].CompareTo(mco.Signal[idx]) > 0 && 
                         mco.Histogram[idx].CompareTo(mco.Histogram[idx - 1]) > 0;
                    break;

                case -1:
                    ok = mco.MACD[idx].CompareTo(mco.MACD[idx - 1]) < 0 &&
                         mco.MACD[idx].CompareTo(mco.Signal[idx]) < 0 &&
                         mco.Histogram[idx].CompareTo(mco.Histogram[idx - 1]) < 0;
                    break;
            }

            return ok;
        }

        public static bool Dir(this StochasticOscillator sto, int dir, int index, Bars lbrs, Bars hbrs)
        {
            bool ok = false;

            var idx = hbrs.OpenTimes.GetIndexByTime(lbrs.OpenTimes[index]);

            var g0 = sto.PercentK[idx];
            var g1 = sto.PercentK[idx -1];

            var r0 = sto.PercentD[idx]; 

            switch (dir)
            {
                case 1:
                    ok = g0.CompareTo(g1) > 0 && g0.CompareTo(r0) > 0;
                    break;

                case -1:
                    ok = g0.CompareTo(g1) < 0 && g0.CompareTo(r0) < 0;
                    break;
            }

            return ok;
        }
    }
}
Comments

leeminho2662000 - November 09, 2022 @ 11:41

This is an excellent article. This is, in my opinion, one of the best posts ever written. Your work is excellent and inspiring. Thank you very much. Weaver game online

 

 

velu130486 - November 09, 2022 @ 16:00

Hello Friend,

Thanks for this Indicator. Very nice work really appreciated. Could you please share your TG or email ID, I would like to have your support for my Cbot Coding update.

Thanks and Regards

R. Vadivelan

velu130486@gmail.com

gmkenneyy - November 10, 2022 @ 00:03

@velu130486 Telegram: TG_KFTD

velu130486 - November 10, 2022 @ 12:46

Hello Friend,

Please give me the telegram ID where I can communicate with you about my Project. Provide ID "TG_KFTD" seems like a bot, there is no response.

asshancuc - November 19, 2022 @ 04:43

I've been looking for photos and articles on this topic over the past few days due to a school assignment, casinosite and I'm really happy to find a post with the material I was looking for!  I bookmark and will come often! Thanks :D 

juliabafrden - November 19, 2022 @ 10:05

It’s very informative and you are obviously very knowledgeable in this area. You have opened my eyes to varying views on this topic with interesting and solid content.Maasalong Reviews

lauraolmedillasol - December 01, 2022 @ 14:46

Indicador bastante fiable en plazos cortos. Fuerte saludo desde nueva web de Euromillones con datos relevantes para sus millones de seguidores en el mundo. Resultados Euromillones

robertfcrocker - December 07, 2022 @ 09:33

 

<a href="https://www.meedblogging.com/">meed blogging</a>

sofiahenry135 - December 08, 2022 @ 13:13

This chic Yellowstone Beth Dutton Pink Coat is something you may wear, in our opinion. This Coat was modeled by the American drama and western television program Yellowstone. A chic Coat can be used if you need to layer anything over your clothing to be warm.

alexanderlexander1357 - December 09, 2022 @ 09:17

Our Future Trunks Capsule Corp Jacket is made of high-quality polyester for a luxurious look. The quilt is made of skin-friendly cotton and has a viscose lining on the inside, so you can always feel warm and comfortable. Please take advantage of it while it is still reasonably priced before it becomes obsolete.

kylesrolfe508 - December 16, 2022 @ 05:21

There is no obvious pattern to the questions, so you'll need to give some serious thought to your responses. Among the questions is "Can a match box?" 

color by number

0