Breakout Box

This indicator draws a box containing all the close prices for the selected period of time. Only works on H1 time-frame.

Input Parameters

  • BreakoutHour: the server time hour after which the breakout take place.
  • Periods: the with of the box measured in periods.

Screenshots

breakout-box-indicator

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 BreakoutBox : Indicator
    {
        [Parameter(DefaultValue = 8)]
        public int BreakoutHour { get; set; }

        [Parameter(DefaultValue = 10)]
        public int Periods { get; set; }

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            if (IsLastBar)
                drawRectangles();
        }

        private void drawRectangles()
        {
            for (int i = 0; i < 1000; i++)
            {
                double min = double.MaxValue, max = double.MinValue;

                if (Bars.OpenTimes.Last(i).Hour == BreakoutHour)
                {
                    for (int j = i; j <= i + Periods; j++)
                    {
                        min = Math.Min(min, Bars.ClosePrices.Last(j));
                        max = Math.Max(max, Bars.ClosePrices.Last(j));
                    }

                    Chart.DrawRectangle("rect" + i, Bars.ClosePrices.Count - i - Periods - 1, min, Bars.ClosePrices.Count - i - 1, max, Color.FromArgb(0xff, 0x70, 0x30, 0xa0));
                }
            }
        }
    }
}

You Might Also Like

Leave a Reply

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