Category Other  Published on 04/02/2016

Show larger timeframe candles on chart

Description

Sometimes it's easy to lose track of the bigger picture.   This indicator draws candle boxes based on high and low around the current price action.    For example, if I'm trading M1, I like to add H1 and H20 so that I don't get lost.  These levels also work as S/R zones.

 

example


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 ShowCandles : Indicator
    {
        [Parameter()]
        public TimeFrame CandleTimeFrame { get; set; }

        [Output("H1 CandleHigh", Color = Colors.Teal, LineStyle = LineStyle.Solid, PlotType = PlotType.Line)]
        public IndicatorDataSeries H1CandleHigh { get; set; }

        [Output("H1 CandleLow", Color = Colors.Teal, LineStyle = LineStyle.Solid, PlotType = PlotType.Line)]
        public IndicatorDataSeries H1CandleLow { get; set; }

        MarketSeries h1;

        protected override void Initialize()
        {
            h1 = this.MarketData.GetSeries(CandleTimeFrame);
        }

        int lastH1Index = 0;
        public override void Calculate(int index)
        {
            var h1Index = h1.OpenTime.GetIndexByTime(this.MarketSeries.OpenTime[index]);
            if (lastH1Index != h1Index)
            {
                H1CandleHigh[index] = h1.High[h1Index];
                H1CandleLow[index] = h1.Low[h1Index];
                lastH1Index = h1Index;
            }
            else
            {
                // Update current candle when High/Lows move
                var startOfBar = this.MarketSeries.OpenTime.GetIndexByTime(h1.OpenTime[lastH1Index]);
                while (startOfBar <= index)
                {
                    H1CandleHigh[startOfBar] = h1.High[h1Index];
                    H1CandleLow[startOfBar] = h1.Low[h1Index];
                    startOfBar++;
                }
            }
        }
    }
}


PE
pennyfx

Joined on 27.09.2012

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: ShowCandles.algo
  • Rating: 0
  • Installs: 4422
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
CH
chay · 4 years ago

Hi pennyfx, I found a bug in your indicator. Could you please see https://ctrader.com/forum/ctrader-support/23492 for more details?

Would it be possible for you to enhance the indicator to work in back-testing as it does in live markets?

thanks

DE
DEPESH MOHINDRA · 8 years ago

Thankyou sir , this made my job easier :)