SupportCenterResistance PerHours free

by d.deel in category Other at 20/05/2021
Description

New update

Not necessarily a trend based indicator. 

Using the RSI indicator as reference, levels are being implimented on the Chart, higher, lower and center.

With three types of parameters, the higher the more precise they might be, but the fewer levels will be shown.

Notice: aside frome the center levels, for better use of the support and resistence levels, the higher the type the better, levels are only been shown, as prices  reach a certain axis.  

Chartshot: EURUSD, h1

04:23:13 (UTC+0) on Jun 9th, 2021

 

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 System.Collections.Generic;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class LevelsPerHour : Indicator
    {
        [Parameter("Center LevelsU", Group = "Color Sett", DefaultValue = "Yellow")]
        public string Colo1 { get; set; }
        [Parameter("Center LevelsD", Group = "Color Sett", DefaultValue = "Crimson")]
        public string Colo5 { get; set; }
        [Parameter("Higher Levels", Group = "Color Sett", DefaultValue = "Blue")]
        public string Colo2 { get; set; }
        [Parameter("Lower Levels", Group = "Color Sett", DefaultValue = "Purple")]
        public string Colo3 { get; set; }
        [Parameter("Color Opaccity", Group = "Color Sett", DefaultValue = 50)]
        public int ColorOpt { get; set; }
        [Parameter(DefaultValue = 4)]
        public int LinesPeriod { get; set; }
        [Parameter(DefaultValue = 3)]
        public int LastPeriod { get; set; }
        [Parameter("Switch Levels", DefaultValue = 2, MinValue = 1, MaxValue = 3)]
        public int TypesLevels { get; set; }

        [Parameter("LastOpenIndex Set", DefaultValue = TmSet.Monthly)]
        public TmSet Tm { get; set; }

        public enum TmSet
        {
            Weekly,
            Monthly
        }

        private Bars _onBars;
        private RelativeStrengthIndex _rsi1, _rsi2;
        protected override void Initialize()
        {
            for (int i = 0; i < 26526; i += LinesPeriod)
            {
                GetTimes.Add(i);
            }
            _onBars = MarketData.GetBars(Tm == TmSet.Weekly ? TimeFrame.Weekly : Tm == TmSet.Monthly ? TimeFrame.Monthly : TimeFrame.Monthly);
            int periodType = TypesLevels == 1 ? 70 : TypesLevels == 2 ? 120 : TypesLevels == 3 ? 160 : 70;
            _rsi1 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, periodType);
            _rsi2 = Indicators.RelativeStrengthIndex(Bars.ClosePrices, 14);
        }

        private List<int> GetTimes = new List<int>();
        private DateTime _openTime, _closingTime;
        public override void Calculate(int index)
        {
            foreach (int i in GetTimes)
            {
                var barsOpenTimes = _onBars.OpenTimes.Last(LastPeriod).AddHours(i);
                if (Bars.OpenTimes.LastValue >= barsOpenTimes && Bars.OpenTimes.Last(1) < barsOpenTimes)
                {
                    _openTime = barsOpenTimes;
                    _closingTime = _openTime.AddHours(LinesPeriod);
                }
            }
            GetLevelsHigherLower(ref _higher1, ref _lower1, ref _higher2, ref _lower2);
            GetLevelsFifth(ref _fifth1, ref _fifth2);
            var some1 = Color.FromArgb(ColorOpt, Color.FromName(_rsi1.Result.LastValue > 50 ? Colo1 : _rsi1.Result.LastValue < 50 ? Colo5 : Colo1).R, Color.FromName(_rsi1.Result.LastValue > 50 ? Colo1 : _rsi1.Result.LastValue < 50 ? Colo5 : Colo1).G, Color.FromName(_rsi1.Result.LastValue > 50 ? Colo1 : _rsi1.Result.LastValue < 50 ? Colo5 : Colo1).B);
            var some2 = Color.FromArgb(ColorOpt, Color.FromName(Colo2).R, Color.FromName(Colo2).G, Color.FromName(Colo2).B);
            var some3 = Color.FromArgb(ColorOpt, Color.FromName(Colo3).R, Color.FromName(Colo3).G, Color.FromName(Colo3).B);

            Chart.DrawRectangle("first" + _openTime, _openTime, _fifth1, _closingTime, _fifth2, some1).IsFilled = true;
            var lev1 = _fifth1 + (Symbol.PipSize * 10);
            var lev2 = _fifth2 - (Symbol.PipSize * 10);
            if (_higher2 > lev1)
                Chart.DrawRectangle("second" + _openTime, _openTime, _higher1, _closingTime, _higher2, some2).IsFilled = true;
            if (_lower2 < lev2)
                Chart.DrawRectangle("third" + _openTime, _openTime, _lower1, _closingTime, _lower2, some3).IsFilled = true;

        }
        private void GetLevelsHigherLower(ref double _result1, ref double _result2, ref double _result3, ref double _result4)
        {
            if (Functions.HasCrossedAbove(_rsi1.Result, 55, 3))            /*&& _rsi2.Result.LastValue < 60*/
            {
                _result1 = Bars.HighPrices.LastValue;
                double valuePips = Bars.TimeFrame < TimeFrame.Hour2 ? Symbol.PipSize * 3 : Bars.TimeFrame >= TimeFrame.Hour2 ? Symbol.PipSize * 5 : Symbol.PipSize * 5;
                _result3 = Bars.HighPrices.LastValue - valuePips;
            }
            else
            {
                if (Functions.HasCrossedBelow(_rsi1.Result, 45, 3))                /* && _rsi2.Result.LastValue > 40*/
                {
                    _result2 = Bars.LowPrices.LastValue;
                    double valuePips = Bars.TimeFrame < TimeFrame.Hour2 ? Symbol.PipSize * 3 : Bars.TimeFrame >= TimeFrame.Hour2 ? Symbol.PipSize * 5 : Symbol.PipSize * 5;
                    _result4 = Bars.LowPrices.LastValue + valuePips;
                }
            }
        }
        private double _fifth1, _fifth2;
        private double _higher1, _higher2;
        private double _lower1, _lower2;
        private void GetLevelsFifth(ref double _result1, ref double _result2)
        {
            double result1 = _result1;
            double result2 = _result2;
            if (Functions.HasCrossedAbove(_rsi1.Result, 50, 0) && _rsi2.Result.LastValue < 60)
            {
                result1 = Bars.HighPrices.LastValue;
                result2 = (Bars.LowPrices.LastValue + Bars.HighPrices.LastValue) / 2;
            }
            else
            {
                if (Functions.HasCrossedBelow(_rsi1.Result, 50, 0) && _rsi2.Result.LastValue > 40)
                {
                    result1 = (Bars.LowPrices.LastValue + Bars.HighPrices.LastValue) / 2;
                    result2 = Bars.LowPrices.LastValue;
                }
            }
            _result1 = result1;
            _result2 = result2;
        }
    }
}
Comments

aang.bawono - June 13, 2021 @ 18:00

Awesome indicator, thanks for share

d.deel - June 15, 2021 @ 15:43

:)

5