Category Trend  Published on 17/10/2021

Ultimate Renko indicator

Description

Very flexible renko indicator for cTrader offering presets for the most popular renko chart types:

  • Renko
  • Median Renko
  • PointO
  • Turbo Renko
  • Hybrid Renko

Turbo renko and median renko on cTrader

This is an updated version of the Median Renko Ultimate indicator offered from https://ctrader.com/algos/indicators/show/1332 and it is a FREE update for all of the licensed users of the MedianRenko indicator for cTrader.

The indicator lets you freely design renko charts tailored to your specific needs by tweaking the 4 variables presented below and specifying whether you want to see the wicks or not.

This is a 14-day trial version.  Lifetime license can be purchased >> here << 

The latest version always available on OneDrive


IMPORTANT: The renko chart displayed as an overlay on the main chart so, you may want to change the chart properties to "line chart" and the "Bear Outline" color to black for better clarity of displayed bars.


 


using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using cT_UltimateRenkoEngine;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AutoRescale = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class UltimateRenko : Indicator
    {
        [Parameter("Bar Size (Pips)", DefaultValue = 10, MinValue = 0.1, Step = 1)]
        public double BarSizePips { get; set; }

        [Parameter("Renko mode preset", DefaultValue = RENKO_PRESET.None)]
        public RENKO_PRESET Preset { get; set; }

        [Parameter("Open offset % (0 to ...)", DefaultValue = 50, MinValue = 0, MaxValue = Int32.MaxValue, Step = 1)]
        public int OpenOffset { get; set; }

        [Parameter("Reversal Open offset % (0 to ...)", DefaultValue = 50, MinValue = 0, MaxValue = Int32.MaxValue, Step = 1)]
        public int ReversalOpenOffset { get; set; }

        [Parameter("Reversal bar size % (0 to ...)", DefaultValue = 150, MinValue = 0, MaxValue = Int32.MaxValue, Step = 1)]
        public int ReversalBarSize { get; set; }

        [Parameter("Show wicks", DefaultValue = true)]
        public bool ShowWicks { get; set; }

        [Parameter("Maximum Bars", DefaultValue = 300, MinValue = 1)]
        public int BricksToShow { get; set; }

        [Parameter("Reset Open on new trading day", DefaultValue = false)]
        public bool ResetOpenOnNewTradingDay { get; set; }

        [Parameter("Use fixed Open price for 1st renko", DefaultValue = 0)]
        public double FixedOpenPriceForFirstRenko { get; set; }

        [Parameter("Truncate trailing digits on the first renko", DefaultValue = false)]
        public bool ApplyOffsetToFirstBar { get; set; }

        [Parameter("Number of digits to truncate", DefaultValue = 1, MinValue = 0)]
        public int OffsetValue { get; set; }

        [Output("Open", LineColor = "Transparent", Thickness = 0, PlotType = PlotType.Points)]
        public IndicatorDataSeries Open { get; set; }

        [Output("High", LineColor = "Transparent", Thickness = 0, PlotType = PlotType.Points)]
        public IndicatorDataSeries High { get; set; }

        [Output("Low", LineColor = "Transparent", Thickness = 0, PlotType = PlotType.Points)]
        public IndicatorDataSeries Low { get; set; }

        [Output("Close", LineColor = "Transparent", Thickness = 0, PlotType = PlotType.Points)]
        public IndicatorDataSeries Close { get; set; }

        private const string INFO_TEXT = "UltimateRenkoInfoTextObj";
        private const string LIVE_WICK_OBJ = "az_Wick_Live";
        private const string LIVE_BAR_OBJ = "az_Bar_Live";
        private const string WICK_OBJ_PREFIX = "as_Wick_";
        private const string BAR_OBJ_PREFIX = "as_Bar_";
        private const int WICK_THICKNESS = 1;
        private const int BAR_THICKNESS = 10;

        private UltimateRenkoCore core = null;
        private bool coreOK = true;

        private DateTime lastTime;

        private bool appliedOffset = false;

        private T_OLHCV pOLHCV;
        private T_OLHCV OLHCV;
        private T_OLHCV mOLHCV;
        private T_OLHCV cOLHCV;
        private T_OLHCV memRates;

        private double barSize;
        private double pOpen;
        private double pRevOpen;
        private double pRevSize;

        private readonly List<T_OLHCV> bars = new List<T_OLHCV>();

        protected override void Initialize()
        {
            core = new UltimateRenkoCore();
            coreOK = core.StatusCheck();

            barSize = BarSizePips * Symbol.PipSize;

            if (Preset == RENKO_PRESET.None)
            {
                pOpen = Math.Abs(OpenOffset * 0.01);
                pRevOpen = Math.Abs(ReversalOpenOffset * 0.01);
                pRevSize = Math.Max(0.01, Math.Abs(ReversalBarSize * 0.01));
            }
            else
            {
                Presets.Get(Preset, ref pOpen, ref pRevOpen, ref pRevSize);
            }

            lastTime = new DateTime();
            lastTime = Bars.OpenTimes[Bars.ClosePrices.Count - 1];

            pOLHCV = new T_OLHCV();
            OLHCV = new T_OLHCV();
            mOLHCV = new T_OLHCV();
            cOLHCV = new T_OLHCV();
            memRates = new T_OLHCV();

            appliedOffset = false;

            Chart.ChartType = ChartType.Line;
            Chart.ColorSettings.BearOutlineColor = Color.Transparent;
        }

        private bool NewBar(int index)
        {
            if (lastTime != Bars.OpenTimes[index])
            {
                lastTime = Bars.OpenTimes[index];
                return true;
            }

            return false;
        }

        private static int cc = 0;
        private void PushBars(T_OLHCV bar, bool display)
        {
            int count = bars.Count();

            var newBar = new T_OLHCV();
            newBar.Copy(bar);
            newBar.Index = cc++;

            bars.Insert(0, newBar);
            count++;

            if (display)
            {
                ShitBars();
            }

            if (count > BricksToShow)
            {
                if (display)
                {
                    for (int i = BricksToShow - 1; i < count; i++)
                    {
                        Chart.RemoveObject(WICK_OBJ_PREFIX + bars[i].Index);
                        Chart.RemoveObject(BAR_OBJ_PREFIX + bars[i].Index);
                    }
                }

                bars.RemoveRange(BricksToShow, count - BricksToShow);

                Open[count - BricksToShow] = double.NaN;
                High[count - BricksToShow] = double.NaN;
                Low[count - BricksToShow] = double.NaN;
                Close[count - BricksToShow] = double.NaN;
            }

        }

        private void ShitBars()
        {
            int count = bars.Count;
            int ix = Bars.ClosePrices.Count - 2;

            for (int i = 0; i < count && i < BricksToShow; i++)
            {
                var candleColor = (bars[i].Close > bars[i].Open) ? Chart.ColorSettings.BullFillColor : Chart.ColorSettings.BearFillColor;

                Chart.DrawTrendLine(WICK_OBJ_PREFIX + bars[i].Index, ix, bars[i].High, ix, bars[i].Low, candleColor, WICK_THICKNESS, LineStyle.Solid);
                Chart.DrawTrendLine(BAR_OBJ_PREFIX + bars[i].Index, ix, bars[i].Close, ix, bars[i].Open, candleColor, BAR_THICKNESS, LineStyle.Solid);

                Open[ix] = bars[i].Open;
                High[ix] = bars[i].High;
                Low[ix] = bars[i].Low;
                Close[ix] = bars[i].Close;

                ix--;
            }
        }

        private void UpdateLastBar(int ix)
        {
            var candleColor = (memRates.Close > memRates.Open) ? Chart.ColorSettings.BullFillColor : Chart.ColorSettings.BearFillColor;

            Chart.DrawTrendLine(LIVE_WICK_OBJ, ix, memRates.High, ix, memRates.Low, candleColor, WICK_THICKNESS, LineStyle.Solid);
            Chart.DrawTrendLine(LIVE_BAR_OBJ, ix, memRates.Close, ix, memRates.Open, candleColor, BAR_THICKNESS, LineStyle.Solid);

            Open[ix] = memRates.Open;
            High[ix] = memRates.High;
            Low[ix] = memRates.Low;
            Close[ix] = memRates.Close;

        }

        public override void Calculate(int index)
        {
            if (ResetOpenOnNewTradingDay)
            {
                if (IsNewSession(Bars.OpenTimes[(index > 0) ? (index - 1) : index], Bars.OpenTimes[index]))
                {
                    cOLHCV.Clear();
                    mOLHCV.Clear();
                    pOLHCV.Clear();
                    memRates.Copy(mOLHCV);
                }
            }

            if (IsLastBar)
            {
                if (!coreOK)
                {
                    Chart.DrawStaticText(INFO_TEXT, "UltimateRenko - Trial period ended. Please purchase a license at www.az-invest.eu", VerticalAlignment.Center, API.HorizontalAlignment.Center, Chart.ColorSettings.ForegroundColor);

                    return;
                }

                if (NewBar(index))
                {
                    ShitBars();

                    Open[index - BricksToShow - 1] = double.NaN;
                    High[index - BricksToShow - 1] = double.NaN;
                    Low[index - BricksToShow - 1] = double.NaN;
                    Close[index - BricksToShow - 1] = double.NaN;
                }

                OLHCV.Open = Bars.ClosePrices[index];
                OLHCV.Low = Bars.ClosePrices[index];
                OLHCV.High = Bars.ClosePrices[index];
                OLHCV.Close = Bars.ClosePrices[index];
                OLHCV.OpenTime = Bars.OpenTimes[index];
                OLHCV.TickVolume = 1;


                ProcessMarketData(OLHCV);
                UpdateLastBar(index);
            }
            else
            {

                OLHCV.Open = Bars.OpenPrices[index];
                OLHCV.Low = Bars.LowPrices[index];
                OLHCV.High = Bars.HighPrices[index];
                OLHCV.Close = Bars.ClosePrices[index];
                OLHCV.OpenTime = Bars.OpenTimes[index];
                OLHCV.TickVolume = Bars.TickVolumes[index];

                if (FixedOpenPriceForFirstRenko != 0)
                {
                    OLHCV.Open = Math.Abs(FixedOpenPriceForFirstRenko);
                    appliedOffset = true;
                }
                else if (ApplyOffsetToFirstBar && !appliedOffset)
                {
                    OLHCV.Open = Math.Round(OLHCV.Open, (Symbol.Digits - OffsetValue), MidpointRounding.ToEven);
                    appliedOffset = true;
                }

                ProcessMarketData(OLHCV);

                if (IsLastBar)
                    UpdateLastBar(index);
            }
        }

        private void ProcessMarketData(T_OLHCV ___OLHCV)
        {
            int rb_return = core.ProcessUltimateRenko(barSize, pOpen, pRevSize, pRevOpen, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 1);
            while (true)
            {
                if ((rb_return >= 1) && (rb_return <= 4))
                {
                    if (!ShowWicks)
                        HideWick(cOLHCV);

                    PushBars(cOLHCV, IsLastBar);
                    memRates.Copy(mOLHCV);
                    OLHCV.Copy(memRates);

                    cOLHCV.Clear();
                    mOLHCV.Clear();

                    rb_return = core.ProcessUltimateRenko(barSize, pOpen, pRevSize, pRevOpen, ___OLHCV, ref pOLHCV, ref mOLHCV, ref cOLHCV, 0);
                    continue;

                }
                else if (rb_return == 10)
                {
                    memRates.Copy(mOLHCV);
                    break;
                }
                else if (rb_return == -1)
                {
                    return;
                }
                else
                {
                    throw new Exception("Unhandled return value = " + rb_return);
                }
            }

            if (IsLastBar)
            {
                ShitBars();
            }
        }

        private bool IsNewSession(DateTime prevTime, DateTime currTime)
        {
            if (prevTime.DayOfWeek != currTime.DayOfWeek)
                return true;
            else
                return false;
        }

        private void HideWick(T_OLHCV rateInfo)
        {
            if (rateInfo.Close > rateInfo.Open)
            {
                rateInfo.High = rateInfo.Close;
                rateInfo.Low = rateInfo.Open;
            }
            else
            {
                rateInfo.High = rateInfo.Open;
                rateInfo.Low = rateInfo.Close;
            }
        }
    }
}



AR
arturzas

Joined on 15.06.2016

  • Distribution: Paid
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: UltimateRenko.algo
  • Rating: 5
  • Installs: 1916
  • Modified: 17/10/2021 16:41
Comments
Log in to add a comment.
JE
jerrybillynathy · 1 year ago

esta com erro o link da versao de teste

AR
arturzas · 3 years ago

Changelog for Version 1.40:

  • Various UI improvements.
  • BugFix: Wicks were not hidden when Show Wicks was switched off
  • Added optional parameter "Use fixed Open price for 1st renko"