TMA Bands v2 free

by kamilsz in category Trend at 06/01/2021
Description

Without alerting stuff and other useless things from other version, additionally, painting arrows when price gets back from below/above upper or lower band

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 TMABandsv2 : Indicator
    {
        [Parameter(DefaultValue = 60, MinValue = 1)]
        public int HalfLength { get; set; }

        [Parameter()]
        public DataSeries Price { get; set; }

        [Parameter(DefaultValue = 2.5)]
        public double ATRMultiplier { get; set; }

        [Parameter(DefaultValue = 100)]
        public int ATRPeriod { get; set; }

        [Output("Center", LineColor = "red", PlotType = PlotType.Points)]
        public IndicatorDataSeries Center { get; set; }

        [Output("Upper", LineColor = "blue")]
        public IndicatorDataSeries Upper { get; set; }

        [Output("Lower", LineColor = "blue")]
        public IndicatorDataSeries Lower { get; set; }

        private AverageTrueRange _atr;

        private bool previousClosesAbove;
        private bool previousClosesBelow;
        private int arrowLastCalculated;

        protected override void Initialize()
        {
            _atr = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            if (index < HalfLength)
                return;
            double sum = (HalfLength + 1) * Price[index];
            double sumw = (HalfLength + 1);

            for (int j = 1, k = HalfLength; j <= HalfLength; j++,k--)
            {
                sum += k * Price[index - j];
                sumw += k;
            }

            double range = _atr.Result[index - 10] * ATRMultiplier;

            Center[index] = sum / sumw;
            Upper[index] = Center[index] + range;
            Lower[index] = Center[index] - range;

            paintArrows(index);
        }

        private void paintArrows(int index)
        {
            if (arrowLastCalculated == index || index == 0)
            {
                return;
            }
            arrowLastCalculated = index;
            previousClosesAbove = Bars[index - 2].Close > Upper[index - 2];
            previousClosesBelow = Bars[index - 2].Close < Lower[index - 2];
            if (previousClosesAbove && Bars[index - 1].Close < Upper[index - 1])
            {
                Chart.DrawIcon(index + "AD", ChartIconType.DownArrow, Bars[index - 1].OpenTime, Math.Max(Bars[index - 2].High, Bars[index - 1].High), Color.Yellow);
            }
            if (previousClosesBelow && Bars[index - 1].Close > Lower[index - 1])
            {
                Chart.DrawIcon(index + "AU", ChartIconType.UpArrow, Bars[index - 1].OpenTime, Math.Min(Bars[index - 2].Low, Bars[index - 1].Low), Color.LightBlue);
            }
        }
    }
}
Comments

BullittTradersbyIan - January 18, 2021 @ 09:38

Hi, is this the same as in MT4 https://www.best-metatrader-indicators.com/price-border-indicator/

Thank you

5