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.

gemma140622 - November 16, 2022 @ 09:56

It was enjoyable to read your essay. For me, this is an excellent document. I bookmarked it and will check back later to read more posts snake game.

offpageseo69 - November 18, 2022 @ 18:25

A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one. Alpilean

offpageseo69 - November 18, 2022 @ 18:28

Very nice article. I enjoyed reading your post. very nice share. I want to twit this to my followers. Thanks !. Alpilean Reviews

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

offpageseo69 - November 22, 2022 @ 15:58

Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog. Peacock Premium

offpageseo69 - November 22, 2022 @ 16:00

I think about it is most required for making more on this get engaged Peacock

offpageseo69 - November 22, 2022 @ 16:02

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. YouTube TV Free Trial

offpageseo69 - November 22, 2022 @ 16:03

Thanks for sharing this information. I really like your blog post very much. You have really shared a informative and interesting blog post . Youtube TV Channels

offpageseo69 - November 22, 2022 @ 16:05

Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Youtube TV

offpageseo69 - November 22, 2022 @ 16:06

Your work is very good and I appreciate you and hopping for some more informative posts Best Shows to Watch on Peacock

offpageseo69 - November 22, 2022 @ 16:07

This was incredibly an exquisite implementation of your ideas Red Boost

offpageseo69 - November 22, 2022 @ 16:09

cool stuff you have and you keep overhaul every one of us Red Boost Reviews

offpageseo69 - November 22, 2022 @ 16:10

I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. Peacock Premium Free Trial

offpageseo69 - November 22, 2022 @ 16:12

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. Peacock Free Trial

offpageseo69 - November 22, 2022 @ 16:13

Very useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. peacock world cup 2022

offpageseo69 - November 22, 2022 @ 16:14

Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work! peacock world cup 2022

offpageseo69 - November 22, 2022 @ 16:17

This was incredibly an exquisite implementation of your ideas Best Shows to Watch on Netflix

offpageseo69 - November 22, 2022 @ 16:18

I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts. Best Shows on Apple TV+

offpageseo69 - November 23, 2022 @ 17:28

Glad to chat your blog, I seem to be forward to more reliable articles and I think we all wish to thank so many good articles, blog to share with us. Peacock Black Friday

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

0