Category Trend  Published on 26/03/2015

3 EMA MTF (Multi-timeframe)

Description

3 EMA MTF (Multi-timeframe)

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class EMAMTF : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("EMA Timeframe1", DefaultValue = "Minute15")]
        public TimeFrame EMATimeframe1 { get; set; }

        [Parameter("EMA Timeframe2", DefaultValue = "Hour")]
        public TimeFrame EMATimeframe2 { get; set; }

        [Parameter("EMA Timeframe3", DefaultValue = "Hour4")]
        public TimeFrame EMATimeframe3 { get; set; }

        [Output("EMA1", Color = Colors.Blue)]
        public IndicatorDataSeries EMA1 { get; set; }

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

        [Output("EMA3", Color = Colors.Yellow)]
        public IndicatorDataSeries EMA3 { get; set; }

        private MarketSeries series1;
        private MarketSeries series2;
        private MarketSeries series3;

        private ExponentialMovingAverage Ema1;
        private ExponentialMovingAverage Ema2;
        private ExponentialMovingAverage Ema3;

        protected override void Initialize()
        {
            series1 = MarketData.GetSeries(EMATimeframe1);
            series2 = MarketData.GetSeries(EMATimeframe2);
            series3 = MarketData.GetSeries(EMATimeframe3);

            Ema1 = Indicators.ExponentialMovingAverage(series1.Close, Periods);
            Ema2 = Indicators.ExponentialMovingAverage(series2.Close, Periods);
            Ema3 = Indicators.ExponentialMovingAverage(series3.Close, Periods);

        }

        public override void Calculate(int index)
        {

            var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]);
            if (index1 != -1)
            {
                EMA1[index] = Ema1.Result[index1];
            }

            var index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);
            if (index2 != -1)
            {
                EMA2[index] = Ema2.Result[index2];
            }

            var index3 = GetIndexByDate(series3, MarketSeries.OpenTime[index]);
            if (index3 != -1)
            {
                EMA3[index] = Ema3.Result[index3];
            }

        }


        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i > 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}

 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class EMAMTF : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("EMA Timeframe1", DefaultValue = "Minute15")]
        public TimeFrame EMATimeframe1 { get; set; }

        [Parameter("EMA Timeframe2", DefaultValue = "Hour")]
        public TimeFrame EMATimeframe2 { get; set; }

        [Parameter("EMA Timeframe3", DefaultValue = "Hour4")]
        public TimeFrame EMATimeframe3 { get; set; }

        [Output("EMA1", Color = Colors.Blue)]
        public IndicatorDataSeries EMA1 { get; set; }

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

        [Output("EMA3", Color = Colors.Yellow)]
        public IndicatorDataSeries EMA3 { get; set; }

        private MarketSeries series1;
        private MarketSeries series2;
        private MarketSeries series3;

        private ExponentialMovingAverage Ema1;
        private ExponentialMovingAverage Ema2;
        private ExponentialMovingAverage Ema3;

        protected override void Initialize()
        {
            series1 = MarketData.GetSeries(EMATimeframe1);
            series2 = MarketData.GetSeries(EMATimeframe2);
            series3 = MarketData.GetSeries(EMATimeframe3);

            Ema1 = Indicators.ExponentialMovingAverage(series1.Close, Periods);
            Ema2 = Indicators.ExponentialMovingAverage(series2.Close, Periods);
            Ema3 = Indicators.ExponentialMovingAverage(series3.Close, Periods);

        }

        public override void Calculate(int index)
        {

            var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]);
            if (index1 != -1)
            {
                EMA1[index] = Ema1.Result[index1];
            }

            var index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);
            if (index2 != -1)
            {
                EMA2[index] = Ema2.Result[index2];
            }

            var index3 = GetIndexByDate(series3, MarketSeries.OpenTime[index]);
            if (index3 != -1)
            {
                EMA3[index] = Ema3.Result[index3];
            }

        }


        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i > 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}


cjdduarte's avatar
cjdduarte

Joined on 16.01.2015

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: EMA MTF.algo
  • Rating: 5
  • Installs: 7318
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
SO
sohoj · 8 years ago

 

//For SMA By Sohoj

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class SMAMTF : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter("SMA Timeframe1", DefaultValue = "Minute15")]
        public TimeFrame SMATimeframe1 { get; set; }

        [Parameter("SMA Timeframe2", DefaultValue = "Hour")]
        public TimeFrame SMATimeframe2 { get; set; }

        [Parameter("SMA Timeframe3", DefaultValue = "Hour4")]
        public TimeFrame SMATimeframe3 { get; set; }

        [Output("SMA1", Color = Colors.Blue)]
        public IndicatorDataSeries SMA1 { get; set; }

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

        [Output("SMA3", Color = Colors.Yellow)]
        public IndicatorDataSeries SMA3 { get; set; }

        private MarketSeries series1;
        private MarketSeries series2;
        private MarketSeries series3;

        private SimpleMovingAverage Sma1;
        private SimpleMovingAverage Sma2;
        private SimpleMovingAverage Sma3;

        protected override void Initialize()
        {
            series1 = MarketData.GetSeries(SMATimeframe1);
            series2 = MarketData.GetSeries(SMATimeframe2);
            series3 = MarketData.GetSeries(SMATimeframe3);

            Sma1 = Indicators.SimpleMovingAverage(series1.Close, Periods);
            Sma2 = Indicators.SimpleMovingAverage(series2.Close, Periods);
            Sma3 = Indicators.SimpleMovingAverage(series3.Close, Periods);

        }

        public override void Calculate(int index)
        {

            var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]);
            if (index1 != -1)
            {
                SMA1[index] = Sma1.Result[index1];
            }

            var index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);
            if (index2 != -1)
            {
                SMA2[index] = Sma2.Result[index2];
            }

            var index3 = GetIndexByDate(series3, MarketSeries.OpenTime[index]);
            if (index3 != -1)
            {
                SMA3[index] = Sma3.Result[index3];
            }

        }


        private int GetIndexByDate(MarketSeries series, DateTime time)
        {
            for (int i = series.Close.Count - 1; i > 0; i--)
            {
                if (time == series.OpenTime[i])
                    return i;
            }
            return -1;
        }
    }
}