TheTape

by cysecsbin.01 in category Trend at 04/08/2019
Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; 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 and an Instagram page https://www.instagram.com/ctrader_community/

This is a Tape indicator that synthesizes 3 different kind of information from 2 different time scales in one single chart.

This way of representing data is extremely efficient since it delivers 3-dimensional data points in a 1-dimensional ribbon-like indicator.

It is possible to extend the dimensions of the datapoints to 5 at max, by adding an alpha channel and variable height histograms (you can do this by modding the code).

For any bug report or suggestion, follow my telegram group or comment below

Download
67 downloads
How to install
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 cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ColorMapAdv : Indicator
    {
        [Parameter("Fast", Group = "LV 1 MACD", DefaultValue = 20)]
        public int Lv1MACDFast { get; set; }
        [Parameter("Slow", Group = "LV 1 MACD", DefaultValue = 50)]
        public int Lv1MACDSlow { get; set; }

        [Parameter("Fast", Group = "LV 2 MACD", DefaultValue = 60)]
        public int Lv2MACDFast { get; set; }
        [Parameter("Slow", Group = "LV 2 MACD", DefaultValue = 150)]
        public int Lv2MACDSlow { get; set; }

        [Parameter("SD 1", Group = "Standard Deviation", DefaultValue = 20)]
        public int Lv1STD { get; set; }
        [Parameter("SD 2", Group = "Standard Deviation", DefaultValue = 60)]
        public int Lv2STD { get; set; }

        private MacdCrossOver MACD, MACD3;
        private AverageTrueRange ATR;
        private StandardDeviation STD, STD2;
        private SimpleMovingAverage STDSma, STDSma2;

        private List<int[]> FirstRibbonColours;
        private List<int[]> SecondRibbonColours;

        protected override void Initialize()
        {
            MACD = Indicators.MacdCrossOver(Lv1MACDSlow, Lv1MACDFast, 0);
            MACD3 = Indicators.MacdCrossOver(Lv2MACDSlow, Lv2MACDFast, 0);
            ATR = Indicators.AverageTrueRange(200, MovingAverageType.Exponential);
            STD = Indicators.StandardDeviation(MarketSeries.Close, Lv1STD, MovingAverageType.Simple);
            STD2 = Indicators.StandardDeviation(MarketSeries.Close, Lv2STD, MovingAverageType.Simple);
            STDSma = Indicators.SimpleMovingAverage(STD.Result, 200);
            STDSma2 = Indicators.SimpleMovingAverage(STD2.Result, 200);
            FirstRibbonColours = new List<int[]>();
            SecondRibbonColours = new List<int[]>();
        }

        public override void Calculate(int index)
        {
            FirstRibbonColours.Add(new int[4]);
            FirstRibbonColours[index][0] = (int)(CalculateFAlpha(index));
            FirstRibbonColours[index][1] = (int)(CalculateFRed(index));
            FirstRibbonColours[index][2] = (int)(CalculateFGreen(index));
            FirstRibbonColours[index][3] = (int)(CalculateFBlue(index));

            SecondRibbonColours.Add(new int[4]);
            SecondRibbonColours[index][0] = (int)(CalculateSAlpha(index));
            SecondRibbonColours[index][1] = (int)(CalculateSRed(index));
            SecondRibbonColours[index][2] = (int)(CalculateSGreen(index));
            SecondRibbonColours[index][3] = (int)(CalculateSBlue(index));

            IndicatorArea.DrawTrendLine("First Ribbon " + index, index, -0.5, index, 0.5, Color.FromArgb(FirstRibbonColours[index][0], FirstRibbonColours[index][1], FirstRibbonColours[index][2], FirstRibbonColours[index][3]), 5);
            IndicatorArea.DrawTrendLine("ColSecond Ribbon " + index, index, 0.5, index, 1.5, Color.FromArgb(SecondRibbonColours[index][0], SecondRibbonColours[index][1], SecondRibbonColours[index][2], SecondRibbonColours[index][3]), 5);
        }

        ////////////////////First Ribbon
        private double CalculateFAlpha(int index)
        {
            double Result = 255;
            return Result;
        }

        private double CalculateFRed(int index)
        {
            double Result = 0;
            if (MACD.MACD[index] >= 0)
                Result = 0;
            else if (MACD.MACD[index] > -ATR.Result[index])
                Result = (-MACD.MACD[index] / ATR.Result[index]) * 100;
            else if (MACD.MACD[index] < -ATR.Result[index] && MACD.MACD[index] > -2 * ATR.Result[index])
                Result = 100 + 155 * (-MACD.MACD[index] / ATR.Result[index] - 1);
            else if (MACD.MACD[index] < 2 * ATR.Result[index])
                Result = 255;
            return Result;
        }

        private double CalculateFGreen(int index)
        {
            double Result = 0;
            if (MACD.MACD[index] <= 0)
                Result = 0;
            else if (MACD.MACD[index] < ATR.Result[index])
                Result = (MACD.MACD[index] / ATR.Result[index]) * 100;
            else if (MACD.MACD[index] > ATR.Result[index] && MACD.MACD[index] < 2 * ATR.Result[index])
                Result = 100 + 155 * (MACD.MACD[index] / ATR.Result[index] - 1);
            else if (MACD.MACD[index] > 2 * ATR.Result[index])
                Result = 255;
            return Result;
        }

        private double CalculateFBlue(int index)
        {
            double Result = 0;
            if (STD.Result[index] > 2 * STDSma.Result[index])
                Result = 150;
            else if (STD.Result[index] >= STDSma.Result[index])
                Result = (STD.Result[index] / STDSma.Result[index] - 1) * 100 + 50;
            return Result;
        }
        /////////////////////////////////

        ////////////////////Second Ribbon
        private double CalculateSAlpha(int index)
        {
            double Result = 255;
            return Result;
        }

        private double CalculateSRed(int index)
        {
            double Result = 0;
            if (MACD3.MACD[index] >= 0)
                Result = 0;
            else if (MACD3.MACD[index] > -ATR.Result[index])
                Result = (-MACD3.MACD[index] / ATR.Result[index]) * 100;
            else if (MACD3.MACD[index] < -ATR.Result[index] && MACD3.MACD[index] > -2 * ATR.Result[index])
                Result = 100 + 155 * (-MACD3.MACD[index] / ATR.Result[index] - 1);
            else if (MACD3.MACD[index] < 2 * ATR.Result[index])
                Result = 255;
            return Result;
        }

        private double CalculateSGreen(int index)
        {
            double Result = 0;
            if (MACD3.MACD[index] <= 0)
                Result = 0;
            else if (MACD3.MACD[index] < ATR.Result[index])
                Result = (MACD3.MACD[index] / ATR.Result[index]) * 100;
            else if (MACD3.MACD[index] > ATR.Result[index] && MACD3.MACD[index] < 2 * ATR.Result[index])
                Result = 100 + 155 * (MACD3.MACD[index] / ATR.Result[index] - 1);
            else if (MACD3.MACD[index] > 2 * ATR.Result[index])
                Result = 255;
            return Result;
        }

        private double CalculateSBlue(int index)
        {
            double Result = 0;
            if (STD2.Result[index] > 2 * STDSma2.Result[index])
                Result = 150;
            else
                Result = (STD2.Result[index] / STDSma2.Result[index] - 1) * 100 + 50;
            return Result;
        }
        /////////////////////////////////
    }
}
Comments
0