Candle

by msforex in category Volatility at 13/09/2017
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.

 

Download
164 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
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);
        }
    }
}
Comments

burakbirer - September 25, 2017 @ 01:08

Liked the idea, i think that is a good helper. I'll use it. Best,

burakbirer - September 25, 2017 @ 02:39

Would you consider adding bar shift functionality?

0