Zlema Cross

by cysecsbin.01 in category Trend at 05/07/2019
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

Download
52 downloads
How to install
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 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];
        }
    }
}
Comments
0