Category Volatility  Published on 30/06/2019

Stridsman Volatility Quality

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp

This is the Volatility Quality indicator, converted for cTrader.

This version lacks the Filter option, it may be added in the future.

For any bug report or suggestion, contact me by joining the group linked above or just by commenting below


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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class VolatilityQuality : Indicator
    {
        [Parameter("Smoothing", DefaultValue = 5)]
        public int smt { get; set; }
        [Parameter("Short MA", DefaultValue = 9)]
        public int shortMA { get; set; }
        [Parameter("Long MA", DefaultValue = 200)]
        public int longMA { get; set; }


        [Output("Main", LineColor = "Lime")]
        public IndicatorDataSeries Result { get; set; }
        [Output("Long MA", LineColor = "Gray", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries MALong { get; set; }
        [Output("Short MA", LineColor = "Gray", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries MAShort { get; set; }

        private TrueRange tr;
        private IndicatorDataSeries vqi_t, vqi;
        private SimpleMovingAverage smaLong, smaShort;
        private SimpleMovingAverage closeSmt, openSmt, highSmt, lowSmt;

        protected override void Initialize()
        {
            tr = Indicators.TrueRange();
            vqi_t = CreateDataSeries();
            vqi = CreateDataSeries();

            smaLong = Indicators.SimpleMovingAverage(Result, longMA);
            smaShort = Indicators.SimpleMovingAverage(Result, shortMA);

            closeSmt = Indicators.SimpleMovingAverage(MarketSeries.Close, smt);
            openSmt = Indicators.SimpleMovingAverage(MarketSeries.Open, smt);
            highSmt = Indicators.SimpleMovingAverage(MarketSeries.High, smt);
            lowSmt = Indicators.SimpleMovingAverage(MarketSeries.Low, smt);
        }

        public override void Calculate(int index)
        {
            //(((close-close[1])/tr)+((close-open)/(high-low)))*0.5
            vqi_t[index] = ((closeSmt.Result[index] - closeSmt.Result[index - 1]) / tr.Result[index] + (closeSmt.Result[index] - openSmt.Result[index]) / (highSmt.Result[index] - lowSmt.Result[index])) * 0.5;
            //abs(vqi_t) * ((close - close[1] + (close - open)) * 0.5)
            vqi[index] = Math.Abs(vqi_t[index]) * ((closeSmt.Result[index] - closeSmt.Result[index - 1] + (closeSmt.Result[index] - openSmt.Result[index])) * 0.5);

            Result[index] = 0;

            for (int i = 1; i < index; i++)
            {
                if (!double.IsNaN(vqi[i]))
                    Result[index] += vqi[i];
            }

            MALong[index] = smaLong.Result[index];
            MAShort[index] = smaShort.Result[index];
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Volatility Quality.algo
  • Rating: 5
  • Installs: 1987
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
AL
alexsanramon · 5 years ago

This is nice. Join the Discord chat now.