Category Trend  Published on 05/07/2022

KF - TEMA - DEMA - v3

Description

This is a far better version than the one i uploaded prior to this. 

PLEASE USE THIS ONE INSTEAD.

 

Most of us use moving average cross-overs to enter / exit trades.

This composite indicator that i created combines the best two of the Moving Average types as cross-over pairs

It lets you place a moving average of a higher timeframe onto the current chart. 

YOU WONT BE DISSAPPOiNTED!!!

 

Please feel free to reshape all my uploaded tools and PLEASE share the code. Thanks!!!


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

namespace cAlgo
{
    public enum TimeFrameE
    {
        Current_Chart,
        M1,
        M2,
        M3,
        M4,
        M5,
        M6,
        M7,
        M8,
        M9,
        M10,
        M15,
        M20,
        M30,
        M45,

        H1,
        H2,
        H3,
        H4,
        H6,
        H8,
        H12,

        D1,
        D2,
        D3,

        W1,

        MN1
    }
    
    public enum DSTypeE
    {
        OpenPrices,
        ClosePrices,
        HighPrices,
        LowPrices,
        MedianPrices,
        TypicalPrices,
        WeightedPrices
    }    

    [Indicator(IsOverlay = true, AutoRescale = false, AccessRights = AccessRights.None)]
    public class KF_Mtf_TemaDema_v3 : Indicator
    {
        [Parameter("Tema_Period", DefaultValue = 14, Group = "Tema")]
        public int Tema_Period { get; set; }

        [Parameter("Tema_TimeFrame", DefaultValue = TimeFrameE.Current_Chart, Group = "Tema")]
        public TimeFrameE Tema_TimeFrame { get; set; }

        [Parameter("Tema_DsType", DefaultValue = DSTypeE.ClosePrices)]
        public DSTypeE Tema_DsType { get; set; }



        [Parameter("Dema_Period", DefaultValue = 14, Group = "Dema")]
        public int Dema_Period { get; set; }

        [Parameter("Dema_TimeFrame", DefaultValue = TimeFrameE.Current_Chart, Group = "Dema")]
        public TimeFrameE Dema_TimeFrame { get; set; }

        [Parameter("Dema_DsType", DefaultValue = DSTypeE.ClosePrices)]
        public DSTypeE Dema_DsType { get; set; }



        [Output("TEMA", LineColor = "Teal", Thickness = 2)]
        public IndicatorDataSeries TEMA { get; set; }

        [Output("DEMA", LineColor = "Yellow", Thickness = 2)]
        public IndicatorDataSeries DEMA { get; set; }


        private ExponentialMovingAverage tEMA1, tEMA2, tEMA3;
        private ExponentialMovingAverage dEMA1, dEMA2;

        private Bars temaBars, demaBars;

        private TimeFrame ToTimeFrame(TimeFrameE tfe)
        {
            TimeFrame tmp = Chart.TimeFrame;

            switch (tfe)
            {
                case TimeFrameE.Current_Chart:
                    tmp = Chart.TimeFrame;
                    break;
                case TimeFrameE.D1:
                    tmp = TimeFrame.Daily;
                    break;
                case TimeFrameE.D2:
                    tmp = TimeFrame.Day2;
                    break;
                case TimeFrameE.D3:
                    tmp = TimeFrame.Day3;
                    break;
                case TimeFrameE.H1:
                    tmp = TimeFrame.Hour;
                    break;
                case TimeFrameE.H12:
                    tmp = TimeFrame.Hour12;
                    break;
                case TimeFrameE.H2:
                    tmp = TimeFrame.Hour2;
                    break;
                case TimeFrameE.H3:
                    tmp = TimeFrame.Hour3;
                    break;
                case TimeFrameE.H4:
                    tmp = TimeFrame.Hour4;
                    break;
                case TimeFrameE.H6:
                    tmp = TimeFrame.Hour6;
                    break;
                case TimeFrameE.H8:
                    tmp = TimeFrame.Hour8;
                    break;
                case TimeFrameE.M1:
                    tmp = TimeFrame.Minute;
                    break;
                case TimeFrameE.M10:
                    tmp = TimeFrame.Minute10;
                    break;
                case TimeFrameE.M15:
                    tmp = TimeFrame.Minute15;
                    break;
                case TimeFrameE.M2:
                    tmp = TimeFrame.Minute2;
                    break;
                case TimeFrameE.M20:
                    tmp = TimeFrame.Minute20;
                    break;
                case TimeFrameE.M3:
                    tmp = TimeFrame.Minute3;
                    break;
                case TimeFrameE.M30:
                    tmp = TimeFrame.Minute30;
                    break;
                case TimeFrameE.M4:
                    tmp = TimeFrame.Minute4;
                    break;
                case TimeFrameE.M45:
                    tmp = TimeFrame.Minute45;
                    break;
                case TimeFrameE.M5:
                    tmp = TimeFrame.Minute5;
                    break;
                case TimeFrameE.M6:
                    tmp = TimeFrame.Minute6;
                    break;
                case TimeFrameE.M7:
                    tmp = TimeFrame.Minute7;
                    break;
                case TimeFrameE.M8:
                    tmp = TimeFrame.Minute8;
                    break;
                case TimeFrameE.M9:
                    tmp = TimeFrame.Minute9;
                    break;
                case TimeFrameE.MN1:
                    tmp = TimeFrame.Monthly;
                    break;
                case TimeFrameE.W1:
                    tmp = TimeFrame.Weekly;
                    break;
            }

            return tmp;
            ;
        }
        
        protected DataSeries GetDS(Bars bars, DSTypeE rqdDS)
        {
            switch (rqdDS)
            {
                case DSTypeE.OpenPrices: return bars.OpenPrices;
                case DSTypeE.HighPrices: return bars.HighPrices;                    
                case DSTypeE.LowPrices: return bars.LowPrices;
                case DSTypeE.MedianPrices: return bars.MedianPrices;
                case DSTypeE.TypicalPrices: return bars.TypicalPrices;
                case DSTypeE.WeightedPrices: return bars.WeightedPrices;

                default: return bars.ClosePrices;
            }
        }        

        protected override void Initialize()
        {
            var temaTF = ToTimeFrame(Tema_TimeFrame);
            var demaTF = ToTimeFrame(Dema_TimeFrame);

            temaBars = temaTF == Chart.TimeFrame ? Bars : MarketData.GetBars(temaTF);
            demaBars = demaTF == Chart.TimeFrame ? Bars : MarketData.GetBars(demaTF);

            while (temaBars.LoadMoreHistory() > 0) { };
            while (demaBars.LoadMoreHistory() > 0) { };

            tEMA1 = Indicators.ExponentialMovingAverage(GetDS(temaBars, Tema_DsType), Tema_Period);
            tEMA2 = Indicators.ExponentialMovingAverage(tEMA1.Result, Tema_Period);
            tEMA3 = Indicators.ExponentialMovingAverage(tEMA2.Result, Tema_Period);

            dEMA1 = Indicators.ExponentialMovingAverage(GetDS(demaBars, Dema_DsType), Dema_Period);
            dEMA2 = Indicators.ExponentialMovingAverage(dEMA1.Result, Dema_Period);
        }

        public override void Calculate(int index)
        {
            var temaIdx = temaBars.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index]);
            temaIdx = temaIdx == -1 ? temaBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) : temaIdx;

            var demaIdx = demaBars.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index]);
            demaIdx = demaIdx == -1 ? demaBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) : demaIdx;

            if (temaIdx != -1)
                TEMA[index] = (3 * tEMA1.Result[temaIdx]) - (3 * tEMA2.Result[temaIdx]) + tEMA3.Result[temaIdx];

            if (demaIdx != -1)
                DEMA[index] = (2 * dEMA1.Result[demaIdx]) - dEMA2.Result[demaIdx];
        }
    }
}


GM
gmkenneyy

Joined on 20.03.2020 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: KF_Mtf_TemaDema_v3.algo
  • Rating: 0
  • Installs: 1103
  • Modified: 05/07/2022 16:37
Comments
Log in to add a comment.
GM
gmkenneyy · 2 years ago

@lemieuxhelmsis65

Are you sure about that? - Stochastic is an oscillator, so is the DMS. Tema-Dema is not