Category Trend  Published on 20/04/2019

Marlyn Crossover

Description

This is an indicator for the trading strategy described in the Filtering Wall Street blog.

http://filteringwallstreet.blogspot.com/2007/06/cross-overs-are-key.html

Added Bull/Bear arrows to make the signal clearer.


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 MarlynCrossover : Indicator
    {
        private string upArrow = "▲";
        private string downArrow = "▼";

        [Output("EMA_Short", Color = Colors.SeaGreen)]
        public IndicatorDataSeries Short_EMA { get; set; }

        [Output("EMA_Mid", Color = Colors.Gold)]
        public IndicatorDataSeries Mid_EMA { get; set; }

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

        [Parameter("EMA_Short", DefaultValue = 4)]
        public int Period1 { get; set; }

        [Parameter("EMA_Mid", DefaultValue = 8)]
        public int Period2 { get; set; }

        [Parameter("EMA_Long", DefaultValue = 21)]
        public int Period3 { get; set; }

        [Parameter("Arrow offset", DefaultValue = 10)]
        public int ArrowOffset { get; set; }

        private ExponentialMovingAverage m_shortEma;
        private ExponentialMovingAverage m_midEma;
        private ExponentialMovingAverage m_longEma;
        private double m_arrowOffset;

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            m_shortEma = Indicators.ExponentialMovingAverage(MarketSeries.Close, Period1);
            m_midEma = Indicators.ExponentialMovingAverage(MarketSeries.Close, Period2);
            m_longEma = Indicators.ExponentialMovingAverage(MarketSeries.Close, Period3);
            m_arrowOffset = Symbol.PipSize * 5;
        }

        public override void Calculate(int index)
        {
            double openPrice = MarketSeries.Open[index];
            double closePrice = MarketSeries.Close[index];

            // Calculate value at specified index
            Short_EMA[index] = m_shortEma.Result[index];
            Mid_EMA[index] = m_midEma.Result[index];
            Long_EMA[index] = m_longEma.Result[index];

            bool BuySignal = closePrice > openPrice && openPrice < Short_EMA[index] && openPrice < Mid_EMA[index] && openPrice < Long_EMA[index] && closePrice > Short_EMA[index] && closePrice > Mid_EMA[index] && closePrice > Long_EMA[index];
            bool SellSignal = closePrice < openPrice && openPrice > Short_EMA[index] && openPrice > Mid_EMA[index] && openPrice > Long_EMA[index] && closePrice < Short_EMA[index] && closePrice < Mid_EMA[index] && closePrice < Long_EMA[index];

            if (BuySignal)
            {
                double y = MarketSeries.Low[index] - m_arrowOffset * ArrowOffset;
                string TextName = string.Format("BuySignal {0}", index);

                ChartObjects.DrawText(TextName, upArrow, index, y, VerticalAlignment.Top, HorizontalAlignment.Center, Colors.MediumSeaGreen);
            }
            else if (SellSignal)
            {
                double y = MarketSeries.High[index] + m_arrowOffset * ArrowOffset;
                string TextName = string.Format("SellSignal {0}", index);

                ChartObjects.DrawText(TextName, downArrow, index, y, VerticalAlignment.Bottom, HorizontalAlignment.Center, Colors.Crimson);
            }
        }
    }
}


BO
boh.lemuelleogene.reyes@gmail.com

Joined on 20.04.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Marlyn Crossover.algo
  • Rating: 0
  • Installs: 1916
Comments
Log in to add a comment.
dokinya's avatar
dokinya · 4 years ago

hi there is it possible to convert the ema to lwma?