Pinbar Highlighter

This indicator draws an arrow whenever a pinbar is formed. A pinbar is bar which have a significant tail in either up or down direction. When a pinbar is formed at a support or resistance level, it may indicate a price reversal.

Input Parameters

  • TailBodyRatio: is the required ratio between the tail and the body of a bar to be considered a pinbar.

Screenshots

pinbar-highlitgher

Code

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 PinbarHighlighter : Indicator
    {
        [Parameter(DefaultValue = 2)]
        public double TailBodyRatio { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            double dnbody = Bars.HighPrices[index] - Math.Min(Bars.OpenPrices[index], Bars.ClosePrices[index]);
            double dntail = Math.Min(Bars.OpenPrices[index], Bars.ClosePrices[index]) - Bars.LowPrices[index];

            double upbody = Math.Max(Bars.OpenPrices[index], Bars.ClosePrices[index]) - Bars.LowPrices[index];
            double uptail = Bars.HighPrices[index] - Math.Max(Bars.OpenPrices[index], Bars.ClosePrices[index]);

            if (dnbody > 0 && dntail / dnbody > TailBodyRatio)
                Chart.DrawIcon("dnpin" + index, ChartIconType.UpArrow, index, Bars.LowPrices[index] - Symbol.PipSize, Color.FromHex("FFAA83C6"));

            if (upbody > 0 && uptail / upbody > TailBodyRatio)
                Chart.DrawIcon("uppin" + index, ChartIconType.DownArrow, index, Bars.HighPrices[index] + Symbol.PipSize, Color.FromHex("FF33C1F3"));
        }
    }
}

You Might Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *