Custom Period Separator

by tmc. in category Other at 21/06/2016
Description

Description:

  • Plots custom period separator.

 

Updates:

  • 21/06/2016 - Version 1.0
    • Released.

 

Screenshot:

 

Notes:

  • Works on tick charts as well.

 

Make a Donation:

  • If you like my work and effort then please consider to make a kind donation thru PayPal or any Credit Card via this link.
Download
461 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;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AutoRescale = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CustomPeriodSeparator : Indicator
    {
        [Parameter(DefaultValue = 60)]
        public int Minutes { get; set; }

        [Output("Separator", PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Separator { get; set; }

        private IndicatorDataSeries totalMinutes;
        private double lastSeparatorMinutes;

        protected override void Initialize()
        {
            totalMinutes = CreateDataSeries();
            lastSeparatorMinutes = TotalMinutes(MarketSeries.OpenTime[0]);
            lastSeparatorMinutes -= lastSeparatorMinutes % Minutes;
        }

        public override void Calculate(int index)
        {
            totalMinutes[index] = TotalMinutes(MarketSeries.OpenTime[index]);

            if (totalMinutes[index] >= lastSeparatorMinutes + Minutes)
            {
                lastSeparatorMinutes = totalMinutes[index];
                lastSeparatorMinutes -= lastSeparatorMinutes % Minutes;
                Separator[index] = MarketSeries.High.Maximum(MarketSeries.Open.Count) * 1.2;
            }

            if (MarketSeries.OpenTime[index].Day != MarketSeries.OpenTime[index - 1].Day)
            {
                lastSeparatorMinutes = 0;
                Separator[index] = MarketSeries.High.Maximum(MarketSeries.Open.Count) * 1.2;
            }
        }

        private double TotalMinutes(DateTime dt)
        {
            var delta = dt.Ticks % TimeSpan.FromMinutes(1).Ticks;
            var dateTime = new DateTime(dt.Ticks - delta, dt.Kind);
            return dateTime.Subtract(dateTime.Date).TotalMinutes;
        }
    }
}

Comments

pipsmatter - November 07, 2016 @ 20:08

I am trying to searate days but the algo only allows up to 60minutes.. is there a way I can add days? i.e 100 day seperator?

tmc. - November 11, 2016 @ 19:49

This indicator is meant to be used for intraday trading and it's limited to 1440 minutes (1 day) because it resets on each new day. How would you want to seperate 100 days? Where should it start counting days? On first bar on the chart or first day of the year?

FXFortitude - November 24, 2016 @ 09:42

Great Stuff TMC!.

I was wondering if its possible to have a period seperator set to any time on my charts, but more specifically for mine id like a period separator on 05:00 UTC+0 of each day?

Any help is much appreciated thankyou!

tmc. - November 24, 2016 @ 20:14

Hi, here you go. http://pastebin.com/embed_iframe/EAk442yZ

0