Category Oscilators  Published on 08/06/2023

The RationalSL indicator

Description

The RationalSL indicator shows the size of the Stop Loss based on the average true range of the price over a specified number of periods, for both long and short trades.

The indicator is adapted to different pair decimals and time frames.


//idea: mfejza (https://ctrader.com/users/profile/58775)

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

namespace cAlgo
{
    [Levels(0)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class mRationalSL : Indicator
    {
        [Parameter("Range Periods (10)", DefaultValue = 10, MinValue = 1, Group = "RationalSL")]
        public int inpRangePeriods { get; set; }
        [Parameter("Smooth Type", DefaultValue = MovingAverageType.Simple, Group = "RationalSL")]
        public MovingAverageType inpSmoothType { get; set; }
        [Parameter("OverBought% (80)", DefaultValue = 70, MinValue = 51, MaxValue = 99, Group = "RationalSL")]
        public int inpRSIOverBought { get; set; }
        [Parameter("OverSold% (20)", DefaultValue = 30, MinValue = 1, MaxValue = 49, Group = "RationalSL")]
        public int inpRSIOverSold { get; set; }

        [Output("SL close", Thickness = 1, LineColor = "Black")]
        public IndicatorDataSeries outSLc { get; set; }

        private MovingAverage _ma;
        private AverageTrueRange _atr;


        protected override void Initialize()
        {
            _ma = Indicators.MovingAverage(Bars.ClosePrices, inpRangePeriods, inpSmoothType);
            _atr = Indicators.AverageTrueRange(inpRangePeriods, inpSmoothType);
        }

        public override void Calculate(int index)
        {
            outSLc[index] = ((_ma.Result[index] + (_atr.Result[index] * (inpRSIOverBought - 50) / 100)) - (_ma.Result[index] - (_atr.Result[index] * (50 - inpRSIOverSold) / 100)));
        }
    }
}


mfejza's avatar
mfejza

Joined on 25.01.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: mRationalSL.algo
  • Rating: 5
  • Installs: 823
  • Modified: 18/09/2022 10:28
Comments
Log in to add a comment.
KA
kajav65227 · 2 years ago

This website called assignment service turned out to be the best option for me. I had no clue they'd put on such an excellent show. This one has made me very happy!

MA
mahsomcorp · 2 years ago

Mehsom is the leading quality pulses and extra virgin olive oil exporters in Canada. We work in agri-food industries. We deliver quality products to our clients at affordable rates worldwide. We develop strong and long-term relationships with our clients and we cover all the business aspects with sincerity and integrity.