Category Trend  Published on 11/05/2021

SSL Indicator

Description

The SSL indicator consists of two SMAs, one of the Highs,the other of the Lows.

On Close above High SMA, the indicator is Long, on Close below Low SMA, the indicator is Short.
The Long vs. Short is visualized by a red and a blue line.
When Long, the blue line is at the High SMA and the red line is at the Low SMA.
When Short, the red line is at the High SMA and the blue line is at the Low SMA.

Furthermore, transitions between Long and Short coincide with crossing of the red and blue lines.

 


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

        [Output("SSL High", LineColor = "#3BB3E4")]
        public IndicatorDataSeries High { get; set; }

        [Output("SSL Low", LineColor = "#FF006E")]
        public IndicatorDataSeries Low { get; set; }

        private SimpleMovingAverage SMAHigh;
        private SimpleMovingAverage SMALow;

        public SSLIndicator()
        {
        }

        protected override void Initialize()
        {
            SMAHigh = Indicators.SimpleMovingAverage(Bars.HighPrices, Period);
            SMALow = Indicators.SimpleMovingAverage(Bars.LowPrices, Period);
        }

        public int GetDirectionAt(int index)
        {
            var p = High[index];
            var m = Low[index];
            return double.IsNaN(p) || double.IsNaN(m) ? 0 : p >= m ? +1 : -1;
        }

        public override void Calculate(int index)
        {
            var h = SMAHigh.Result[index];
            var l = SMALow.Result[index];
            var c = Bars.ClosePrices[index];
            var prevDir = index > 0 ? GetDirectionAt(index - 1) : 0;
            var r = c > h ? +1 : c < l ? -1 : prevDir;
            High[index] = r > 0 ? h : r < 0 ? l : double.NaN;
            Low[index] = r > 0 ? l : r < 0 ? h : double.NaN;
        }
    }
}


BA
BartNL

Joined on 10.05.2021

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: SSL Indicator.algo
  • Rating: 0
  • Installs: 1640
Comments
Log in to add a comment.
KH
khushal09 · 3 years ago

i have a trend line formula similar to your ssl indicator ..but in another language .. can you convert or code that formula.. please

BA
BartNL · 3 years ago

Thanks for the update, but I just saw an SSL indicator has already been published. So I think I just remove mine.

Symposium's avatar
Symposium · 3 years ago

Just an update to Bart's SSL Indicator which allows you to access variable types of Moving Averages.

Cheers

Symposium's avatar
Symposium · 3 years ago

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

        [Parameter("Fast MA Type")]
        public MovingAverageType MAType { get; set; }

        [Output("SSL High", LineColor = "#3BB3E4")]
        public IndicatorDataSeries High { get; set; }

        [Output("SSL Low", LineColor = "#FF006E")]
        public IndicatorDataSeries Low { get; set; }

        private MovingAverage MAHigh;
        private MovingAverage MALow;

        public SSLIndicator()
        {
        }

        protected override void Initialize()
        {
            MAHigh = Indicators.MovingAverage(Bars.HighPrices, Period, MAType);
            MALow = Indicators.MovingAverage(Bars.LowPrices, Period, MAType);
        }

        public int GetDirectionAt(int index)
        {
            var p = High[index];
            var m = Low[index];
            return double.IsNaN(p) || double.IsNaN(m) ? 0 : p >= m ? +1 : -1;
        }

        public override void Calculate(int index)
        {
            var h = MAHigh.Result[index];
            var l = MALow.Result[index];
            var c = Bars.ClosePrices[index];
            var prevDir = index > 0 ? GetDirectionAt(index - 1) : 0;
            var r = c > h ? +1 : c < l ? -1 : prevDir;
            High[index] = r > 0 ? h : r < 0 ? l : double.NaN;
            Low[index] = r > 0 ? l : r < 0 ? h : double.NaN;
        }
    }
}