Category Other  Published on 11/01/2018

SupportResistance

Description

This indicator will help you find support and resistance levels,increase the number of confirmations for stronger levels.


//+------------------------------------------------------------------+
//|                                                SupportResistance |
//|                                       Copyright © 2016, UCHE OBI |
//|                                               Developer:UCHE OBI |
//|                                                 Skype:  OBI.UCHE |
//|                                      email:ucheceleste@Gmail.com | 
//+------------------------------------------------------------------+
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 SupportResistance : Indicator
    {
        [Parameter(DefaultValue = 10)]
        public int range { get; set; }

        [Parameter(DefaultValue = 3)]
        public int confirmations { get; set; }

        [Output("Res", Color = Colors.Black, LineStyle = LineStyle.DotsVeryRare)]
        public IndicatorDataSeries resistance { get; set; }
        [Output("Sup", Color = Colors.Black, LineStyle = LineStyle.DotsVeryRare)]
        public IndicatorDataSeries support { get; set; }

        public double res;
        public double sup;

        private MarketSeries Series;


        protected override void Initialize()
        {
            // Initialize and create nested indicators
            Series = MarketSeries;
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...

            var upline = (Series.Close.Maximum(range) + Series.High.Maximum(range)) / 2;
            var dnline = (Series.Close.Minimum(range) + Series.Low.Minimum(range)) / 2;
            resistance[index] = double.NaN;
            support[index] = double.NaN;
            if (resbarsconfirmed(upline, index) >= confirmations)
            {
                res = upline;
                ChartObjects.DrawLine("resline" + upline.ToString(), Series.OpenTime[index], upline, Series.OpenTime[index - range], upline, Colors.DarkRed, 2, LineStyle.Solid);
            }

            if (supbarsconfirmed(dnline, index) >= confirmations)
            {
                sup = dnline;
                ChartObjects.DrawLine("supline" + dnline.ToString(), Series.OpenTime[index], dnline, Series.OpenTime[index - range], dnline, Colors.DarkBlue, 2, LineStyle.Solid);
            }

        }
        private int resbarsconfirmed(double line, int index)
        {
            int touches = 0;
            for (int i = index; i > index - range; i--)
            {
                if (Series.Low[i] < line && Series.High[i] >= line && Series.Close[i] < line)
                    touches += 1;
                if (Series.Close[i] > line)
                    touches = 0;
            }
            return touches;
        }
        private int supbarsconfirmed(double line, int index)
        {
            int touches = 0;
            for (int i = index; i > index - range; i--)
            {
                if (Series.High[i] > line && Series.Low[i] <= line && Series.Close[i] > line)
                    touches += 1;
                if (Series.Close[i] < line)
                    touches = 0;
            }
            return touches;
        }
    }
}


Uche's avatar
Uche

Joined on 25.10.2012

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: SupportResistance.algo
  • Rating: 5
  • Installs: 11068
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
ForexCommunity's avatar
ForexCommunity · 1 month ago

Great thank you for keeping it free. 

dokinya's avatar
dokinya · 3 years ago

the best SUPPORTnRESISTANCE indicator