Description
It is useful with other indicator in reverse strategy, only visual help, where price is during last x period of time. I m not coder, but maybe this could be helpful for someone. For now there is options for width of the candle, colour and offset from the actual candle on the chart.
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator("Candle Of Time Period", IsOverlay = true, AccessRights = AccessRights.None)]
public class Candle : Indicator
{
//--------------------------------------------------------------------------------------------------------------------------------------------------
[Parameter("Width", DefaultValue = 10)]
public int CandleWidth { get; set; }
[Parameter("Offset", DefaultValue = 2)]
public int Offset { get; set; }
[Parameter("Period", DefaultValue = 50)]
public int Period { get; set; }
[Parameter("Down color", DefaultValue = "DarkGray")]
public string DownColor { get; set; }
[Parameter("Up color", DefaultValue = "White")]
public string UpColor { get; set; }
private Colors _upColor;
private Colors _downColor;
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))
_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 color = MarketSeries.Open[index - Period + 1] < MarketSeries.Close[index] ? _upColor : _downColor;
ChartObjects.DrawLine("Line", index + Offset, Functions.Minimum(MarketSeries.Low, Period), index + Offset, Functions.Maximum(MarketSeries.High, Period), color, 1, LineStyle.Solid);
ChartObjects.DrawLine("Body", index + Offset, MarketSeries.Open[index - Period + 1], index + Offset, MarketSeries.Close[index], color, CandleWidth, LineStyle.Solid);
}
}
}
HE
hedgehog
Joined on 24.04.2016
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Candle.algo
- Rating: 5
- Installs: 3509
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
Liked the idea, i think that is a good helper. I'll use it. Best,
Would you consider adding bar shift functionality?