Category Trend  Published on 30/01/2021

Multi MA BTMM v1.2

Description

This is all in one MAs for use in BTMM trading approach. 

Version 1.1

- Customizable colors for arrows
- Improved offset calculation for arrows 

Version 1.2

- Do not draw arrow marker if candle is not closed


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class MultiMA : Indicator
    {
        [Parameter("Show Arrows", Group = "Arrows", DefaultValue = true)]
        public bool ShowArrow { get; set; }

        [Parameter("Buy Color", Group = "Arrows", DefaultValue = "LimeGreen")]
        public string UpColorName { get; set; }

        [Parameter("Sell Color", Group = "Arrows", DefaultValue = "Red")]
        public string DownColorName { get; set; }

        [Parameter("Mustard", Group = "Periods", DefaultValue = 5)]
        public int Mustard { get; set; }

        [Parameter("Ketchup", Group = "Periods", DefaultValue = 13)]
        public int Ketchup { get; set; }

        [Parameter("Water", Group = "Periods", DefaultValue = 50)]
        public int Water { get; set; }

        [Parameter("Mayo", Group = "Periods", DefaultValue = 200)]
        public int Mayo { get; set; }

        [Parameter("Blueberry", Group = "Periods", DefaultValue = 800)]
        public int Blueberry { get; set; }

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

        [Output("Ketchup", LineColor = "Red", Thickness = 2)]
        public IndicatorDataSeries KetchupResult { get; set; }

        [Output("Water", LineColor = "Aqua", Thickness = 2)]
        public IndicatorDataSeries WaterResult { get; set; }

        [Output("Mayo", LineColor = "White", Thickness = 2)]
        public IndicatorDataSeries MayoResult { get; set; }

        [Output("Blueberry", LineColor = "RoyalBlue", Thickness = 2)]
        public IndicatorDataSeries BlueberryResult { get; set; }

        private ExponentialMovingAverage MustardMA;
        private ExponentialMovingAverage KetchupMA;
        private ExponentialMovingAverage WaterMA;
        private ExponentialMovingAverage MayoMA;
        private ExponentialMovingAverage BlueberryMA;

        private string upArrow = "▲";
        private string downArrow = "▼";
        private double arrowOffset;

        private Color UpColor;
        private Color DownColor;

        protected override void Initialize()
        {
            try
            {
                UpColor = Color.FromName(UpColorName);
                DownColor = Color.FromName(DownColorName);
            } catch
            {
                UpColor = Color.LimeGreen;
                DownColor = Color.Red;
            }

            MustardMA = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Mustard);
            KetchupMA = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Ketchup);
            WaterMA = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Water);
            MayoMA = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Mayo);
            BlueberryMA = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Blueberry);

            Bars DailyBars = MarketData.GetBars(TimeFrame.Daily);
            AverageTrueRange atr = Indicators.AverageTrueRange(DailyBars, 14, MovingAverageType.Simple);
            arrowOffset = atr.Result.Last(1) / 30;
        }

        public override void Calculate(int index)
        {
            MustardResult[index] = MustardMA.Result[index];
            KetchupResult[index] = KetchupMA.Result[index];
            WaterResult[index] = WaterMA.Result[index];
            MayoResult[index] = MayoMA.Result[index];
            BlueberryResult[index] = BlueberryMA.Result[index];

            if (IsLastBar)
                return;

            if (ShowArrow & MustardResult[index] > KetchupResult[index] & MustardResult[index - 1] < KetchupResult[index - 1])
            {
                ChartText ct = Chart.DrawText("Arrow" + index, upArrow, index, Bars.LowPrices[index] - arrowOffset, UpColor);
                ct.HorizontalAlignment = HorizontalAlignment.Center;
                ct.VerticalAlignment = VerticalAlignment.Bottom;
            }

            if (ShowArrow & MustardResult[index] < KetchupResult[index] & MustardResult[index - 1] > KetchupResult[index - 1])
            {
                ChartText ct = Chart.DrawText("Arrow" + index, downArrow, index, Bars.HighPrices[index] + arrowOffset, DownColor);
                ct.HorizontalAlignment = HorizontalAlignment.Center;
                ct.VerticalAlignment = VerticalAlignment.Top;
            }
        }
    }
}


LA
lazarevic.miroslav

Joined on 26.01.2021

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Multi MA.algo
  • Rating: 0
  • Installs: 1688
Comments
Log in to add a comment.
No comments found.