Category Trend  Published on 05/07/2019

Zlema Cross

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp

This indicator shows a line connecting all of the price crosses of two ZLEMAs.

To be used with the same philosophy of the MTF Open

For any bug report or suggestion contact me by joining the group linked above or by commenting below


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ZLEMACross : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        [Parameter("Slow Period", DefaultValue = 12)]
        public int sPer { get; set; }
        [Parameter("Fast Period", DefaultValue = 26)]
        public int fPer { get; set; }

        [Parameter("Show ZLEMAs", DefaultValue = true)]
        public bool show { get; set; }
        [Parameter("Show Info", Group = "Infos", DefaultValue = true)]
        public bool showInfo { get; set; }
        [Parameter("Text Color", Group = "Infos", DefaultValue = "White")]
        public string color { get; set; }
        [Parameter("Text Spacing", Group = "Infos", DefaultValue = 0)]
        public int spacing { get; set; }

        private double _alpha, _alpha2;
        private int _lag, _lag2;

        private IndicatorDataSeries ZLEMAslow, ZLEMAfast;

        [Output("Zlema Slow", LineColor = "Red")]
        public IndicatorDataSeries zls { get; set; }
        [Output("Zlema Fast", LineColor = "Cyan")]
        public IndicatorDataSeries zlf { get; set; }
        [Output("Zlema Cross", LineColor = "Gray")]
        public IndicatorDataSeries zlc { get; set; }


        protected override void Initialize()
        {
            ZLEMAfast = CreateDataSeries();
            ZLEMAslow = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            calculateFast(index);
            calculateSlow(index);

            if ((ZLEMAslow[index] > ZLEMAfast[index] && ZLEMAslow[index - 1] < ZLEMAfast[index - 1]) || (ZLEMAslow[index] < ZLEMAfast[index] && ZLEMAslow[index - 1] > ZLEMAfast[index - 1]))
                zlc[index] = (ZLEMAslow[index] + ZLEMAfast[index] + ZLEMAslow[index - 1] + ZLEMAfast[index - 1]) / 4;
            else
                zlc[index] = zlc[index - 1];

            if (showInfo)
            {
                string space = "";
                for (int i = 0; i < spacing; i++)
                {
                    space += "\n";
                }
                Chart.DrawStaticText("ZLEMAinfo", space + "Pips from last cross: " + (Math.Round((MarketSeries.Close[index] - zlc[index]) / Symbol.PipSize, 2)), VerticalAlignment.Top, HorizontalAlignment.Right, Color.FromName(color));
            }
        }

        private void calculateFast(int index)
        {
            if (index == 0)
            {
                _alpha = 2.0 / (sPer + 1);
                _lag = (int)Math.Ceiling((sPer - 1) / 2.0);
            }
            if (index < _lag)
            {
                ZLEMAslow[index] = Source[index];
                return;
            }

            ZLEMAslow[index] = _alpha * (2 * Source[index] - Source[index - _lag]) + (1 - _alpha) * ZLEMAslow[index - 1];
            if (show)
                zls[index] = ZLEMAslow[index];
        }

        private void calculateSlow(int index)
        {
            if (index == 0)
            {
                _alpha2 = 2.0 / (fPer + 1);
                _lag2 = (int)Math.Ceiling((fPer - 1) / 2.0);
            }
            if (index < _lag2)
            {
                ZLEMAfast[index] = Source[index];
                return;
            }

            ZLEMAfast[index] = _alpha2 * (2 * Source[index] - Source[index - _lag2]) + (1 - _alpha2) * ZLEMAfast[index - 1];
            if (show)
                zlf[index] = ZLEMAfast[index];
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: ZLEMA Cross.algo
  • Rating: 0
  • Installs: 1409
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
No comments found.