Category Other  Published on 26/03/2015

Break Out Candles

Description

Only break out candles have Green and Red color.  The other candles are by default LightGray for both up and down, but you can give them separate colors if you want. 

A break out candle is defined as a candle that closes above the high or below the low of the previous candle.  

These break out candles can be adjusted from 1 to 8 bars.  Thus if the setting is 4, then  the red and green candles appear only if they have closed above the high or below the low of the last 4 previous candles.  

The default setting is set to 2 candles .  The pictures below show the setting for 2 and for 8.

The only BO candle indicator that I have seen only used 1 candle. I usually use 2, 4 and 8,  but I thought I should just include all of the numbers up to 8.  So you can pick any number between 1 and 8.

You will want to adjust your chart colors so that bull and bear outlines are the same color as your background.  That way you won't see any vestiges of the original candle underneath.

BY THE WAY, you can can turn these into candles that only show the high and low without open and close by setting the wick thickness to equal the candle thickness.

ALSO you can make them wickless by setting the wick thickness to zero.

Setting is twoSetting is eight.


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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class BreakOutCandles : Indicator
    {

        [Parameter("How Many Break Out Bars", DefaultValue = 2)]
        public int HowMany { get; set; }

        [Parameter("Candle width", DefaultValue = 5)]
        public int CandleWidth { get; set; }

        [Parameter("Wick width", DefaultValue = 1)]
        public int WickWidth { get; set; }

        [Parameter("Breakout up color", DefaultValue = "LimeGreen")]
        public string UpColor { get; set; }

        [Parameter("Breakout down color", DefaultValue = "Red")]
        public string DownColor { get; set; }

        [Parameter("Range up color", DefaultValue = "LightGray")]
        public string RangeUpColor { get; set; }

        [Parameter("Rangedown color", DefaultValue = "LightGray")]
        public string RangeDownColor { get; set; }


        private Colors _UpColor;
        private Colors _DownColor;
        private Colors _RangeUpColor;
        private Colors _RangeDownColor;
        private Colors color;


        private bool _incorrectColors;
        private Random _random = new Random();

        protected override void Initialize()
        {
            if (!Enum.TryParse<Colors>(UpColor, out _UpColor) || !Enum.TryParse<Colors>(DownColor, out _DownColor) || !Enum.TryParse<Colors>(RangeUpColor, out _RangeUpColor) || !Enum.TryParse<Colors>(RangeDownColor, out _RangeDownColor))
                _incorrectColors = true;
        }

        public override void Calculate(int index)
        {
            if (_incorrectColors)
            {
                var errorColor = _random.Next(2) == 0 ? Colors.Red : Colors.White;
                ChartObjects.DrawText("Error", "Incorrect colors", StaticPosition.Center, errorColor);
                return;
            }

            var open = MarketSeries.Open[index];
            var high = MarketSeries.High[index];
            var low = MarketSeries.Low[index];
            var close = MarketSeries.Close[index];

            var High1 = MarketSeries.High[index - 1];
            var High2 = MarketSeries.High[index - 2];
            var High3 = MarketSeries.High[index - 3];
            var High4 = MarketSeries.High[index - 4];
            var High5 = MarketSeries.High[index - 5];
            var High6 = MarketSeries.High[index - 6];
            var High7 = MarketSeries.High[index - 7];
            var High8 = MarketSeries.High[index - 8];

            var Low1 = MarketSeries.Low[index - 1];
            var Low2 = MarketSeries.Low[index - 2];
            var Low3 = MarketSeries.Low[index - 3];
            var Low4 = MarketSeries.Low[index - 4];
            var Low5 = MarketSeries.Low[index - 5];
            var Low6 = MarketSeries.Low[index - 6];
            var Low7 = MarketSeries.Low[index - 7];
            var Low8 = MarketSeries.Low[index - 8];



            if (HowMany == 1)
            {
                if (close > High1)
                    color = _UpColor;
                else if (close < Low1)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }


            if (HowMany == 2)
            {
                if (close > High1 && close > High2)
                    color = _UpColor;
                else if (close < Low1 && close < Low2)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }

            if (HowMany == 3)
            {
                if (close > High1 && close > High2 && close > High3)
                    color = _UpColor;
                else if (close < Low1 && close < Low2 && close < Low3)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }

            if (HowMany == 4)
            {
                if (close > High1 && close > High2 && close > High3 && close > High4)
                    color = _UpColor;
                else if (close < Low1 && close < Low2 && close < Low3 && close < Low4)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }


            if (HowMany == 5)
            {
                if (close > High1 && close > High2 && close > High3 && close > High4 && close > High5)
                    color = _UpColor;
                else if (close < Low1 && close < Low2 && close < Low3 && close < Low4 && close < Low5)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }


            if (HowMany == 6)
            {
                if (close > High1 && close > High2 && close > High3 && close > High4 && close > High5 && close > High6)
                    color = _UpColor;
                else if (close < Low1 && close < Low2 && close < Low3 && close < Low4 && close < Low5 && close < Low6)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }


            if (HowMany == 7)
            {
                if (close > High1 && close > High2 && close > High3 && close > High4 && close > High5 && close > High6 && close > High7)
                    color = _UpColor;
                else if (close < Low1 && close < Low2 && close < Low3 && close < Low4 && close < Low5 && close < Low6 && close < Low7)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }

            if (HowMany > 7)
            {
                if (close > High1 && close > High2 && close > High3 && close > High4 && close > High5 && close > High6 && close > High7 && close > High8)
                    color = _UpColor;
                else if (close < Low1 && close < Low2 && close < Low3 && close < Low4 && close < Low5 && close < Low6 && close < Low7 && close < Low8)
                    color = _DownColor;
                else if (close > open)
                    color = _RangeUpColor;
                else if (close <= open)
                    color = _RangeDownColor;

            }



























            ChartObjects.DrawLine("candle" + index, index, open, index, close, color, CandleWidth, LineStyle.Solid);
            ChartObjects.DrawLine("line" + index, index, high, index, low, color, WickWidth, LineStyle.Solid);

        }
    }
}


FO
foreman01

Joined on 04.07.2014

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Break Out Candles.algo
  • Rating: 5
  • Installs: 7115
Comments
Log in to add a comment.
MO
moiz.forex · 1 year ago

Well what if this is not just an indicator and a bot how can we make this as a bot i mean we can buy/sell on breakouts and also we can set a number of pips manually that if it breaks out a certin number of pips then only trigger my trades and yes further we can set TP SL and all.. Can me make this a bot ? the same script ?

77
77suns · 1 year ago

Nice indicator, Do please add in an alert sound, message or an email alert when a break up/down color candle occurs will make it awesome!.

KA
karp29 · 3 years ago

Hi. Could someone add black wicks and border  to Above version ?

IF
iForex2015 · 4 years ago

Changing candle color algorithmically is possible now .  

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class BreakOutCandles : Indicator
    {

        [Parameter("How Many Break Out Bars", DefaultValue = 5)]
        public int HowManyBreakOutCandles { get; set; }

        [Parameter("Breakout up color", DefaultValue = "Green")]
        public string UpColor { get; set; }

        [Parameter("Breakout down color", DefaultValue = "Red")]
        public string DownColor { get; set; }

        [Parameter("Range color", DefaultValue = "LightGray")]
        public string RangeColor { get; set; }

        private Color color;

        protected override void Initialize()
        {

        }
        public override void Calculate(int index)
        {
            try
            {
                var open = MarketSeries.Open[index];
                var close = MarketSeries.Close[index];
                var high = MarketSeries.High[index];
                var low = MarketSeries.Low[index];

                var highest = MarketSeries.High[index - 1];
                var lowest = MarketSeries.Low[index - 1];
                for (int i = 2; i <= HowManyBreakOutCandles; i++)
                {
                    if (highest < MarketSeries.High[index - i])
                        highest = MarketSeries.High[index - i];
                    if (lowest > MarketSeries.Low[index - i])
                        lowest = MarketSeries.Low[index - i];
                }

                if (close > highest && close > open)
                    color = Color.FromName(UpColor);
                else if (close < lowest && close < open)
                    color = Color.FromName(DownColor);
                else if (close > open)
                    color = Color.FromName(RangeColor);
                else if (close <= open)
                    color = Color.FromName(RangeColor);
                Chart.SetBarColor(index, color);
            } catch (Exception)
            {
            }

        }
    }

}

 

IF
if.mihai@gmail.com · 6 years ago

smaller code working with any number of breakout bars (not only 8)

 

```

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class BreakOutCandles : Indicator
    {

        [Parameter("How Many Break Out Bars", DefaultValue = 2)]
        public int HowMany { get; set; }

        [Parameter("Candle width", DefaultValue = 5)]
        public int CandleWidth { get; set; }

        [Parameter("Wick width", DefaultValue = 1)]
        public int WickWidth { get; set; }

        [Parameter("Breakout up color", DefaultValue = "LimeGreen")]
        public string UpColor { get; set; }

        [Parameter("Breakout down color", DefaultValue = "Red")]
        public string DownColor { get; set; }

        [Parameter("Range up color", DefaultValue = "LightGray")]
        public string RangeUpColor { get; set; }

        [Parameter("Rangedown color", DefaultValue = "LightGray")]
        public string RangeDownColor { get; set; }


        private Colors _UpColor;
        private Colors _DownColor;
        private Colors _RangeUpColor;
        private Colors _RangeDownColor;
        private Colors color;


        private bool _incorrectColors;
        private Random _random = new Random();

        protected override void Initialize()
        {
            if (!Enum.TryParse<Colors>(UpColor, out _UpColor) || !Enum.TryParse<Colors>(DownColor, out _DownColor) || !Enum.TryParse<Colors>(RangeUpColor, out _RangeUpColor) || !Enum.TryParse<Colors>(RangeDownColor, out _RangeDownColor))
                _incorrectColors = true;
        }

        public override void Calculate(int index)
        {
            if (_incorrectColors)
            {
                var errorColor = _random.Next(2) == 0 ? Colors.Red : Colors.White;
                ChartObjects.DrawText("Error", "Incorrect colors", StaticPosition.Center, errorColor);
                return;
            }

            var open = MarketSeries.Open[index];
            var high = MarketSeries.High[index];
            var low = MarketSeries.Low[index];
            var close = MarketSeries.Close[index];

            var highest = MarketSeries.High[index - 1];
            var lowest = MarketSeries.Low[index - 1];
            for (int i = 2; i <= HowMany; i++)
            {
                if (highest < MarketSeries.High[index - i])
                    highest = MarketSeries.High[index - i];
                if (lowest > MarketSeries.Low[index - i])
                    lowest = MarketSeries.Low[index - i];
            }

            if (close > highest)
                color = _UpColor;
            else if (close < lowest)
                color = _DownColor;
            else if (close > open)
                color = _RangeUpColor;
            else if (close <= open)
                color = _RangeDownColor;

            ChartObjects.DrawLine("candle" + index, index, open, index, close, color, CandleWidth, LineStyle.Solid);
            ChartObjects.DrawLine("line" + index, index, high, index, low, color, WickWidth, LineStyle.Solid);

        }
    }
}

```

DI
dimiaverilla · 8 years ago

Foreman is there any chance we can get an alert option added with sound on when there is a breakout candle on candle close?

DI
dimiaverilla · 8 years ago

Incredible work mate. A must for any scalper.

KA
karlson · 9 years ago

Ok Foreman, thank you for all your work !!!

FO
foreman01 · 9 years ago

Karlson if you only want to see BO candles, then change the color of the other candles to the background color.  That's the best I can offer.  If you want a chart that makes the range candles disappear instead of being hidden, I do not know how to do that.

Sorry, but i Don't wish to be contacted.   I've posted 4 very similar candle coloring programs and that pretty much exhausts my very limited programming skills.

 

KA
karlson · 9 years ago

Foreman how can I contact you directly please?

KA
karlson · 9 years ago

I managed to get their own width, but how to get only "breakout candles" only, one by one?

KA
karlson · 9 years ago

If not, is it possible for "breakout candles" and "range candles" to have their own width (same way as they have their own colors) ?

KA
karlson · 9 years ago

Hello Foreman,
Actually I would like to see only breakout candles, without the non-breakout candles. Just breakout candles, one by one, without space between.
 

FO
foreman01 · 9 years ago

Actually I prefer Beige for the range-up and LightPink for the range-down.  The PaleGreen is too close in color to the LimeGreen breakout candle.

FO
foreman01 · 9 years ago

Karlson:  I think I understand your request.  You would like to know if the non-breakout candles (the "range candles") are up or down.

If you want to be able to distinguish the color of the range candles so that you know which is up and which is down, then change them to be Pink (or LightPink) and PaleGreen.  That way they look almost white, but have a very slight pinkness or greenness to them.  

That is what I do.  

KA
karlson · 9 years ago

How to get only "Break out" candles forming one after one without "Range" candles between them, please?

KA
karlson · 9 years ago

Thank you very much indeed! This is what I wanted from the beginning!!!