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.
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);
}
}
}
foreman01
Joined on 04.07.2014
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Break Out Candles.algo
- Rating: 5
- Installs: 7337
- Modified: 13/10/2021 09:54
Comments
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!.
Hi. Could someone add black wicks and border to Above version ?
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)
{
}
}
}
}
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);
}
}
}
```
Foreman is there any chance we can get an alert option added with sound on when there is a breakout candle on candle close?
Incredible work mate. A must for any scalper.
Ok Foreman, thank you for all your work !!!
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.
Foreman how can I contact you directly please?
I managed to get their own width, but how to get only "breakout candles" only, one by one?
If not, is it possible for "breakout candles" and "range candles" to have their own width (same way as they have their own colors) ?
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.
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.
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.
How to get only "Break out" candles forming one after one without "Range" candles between them, please?
Thank you very much indeed! This is what I wanted from the beginning!!!
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 ?