MaVe-PivotPoints

by MaVe in category Other at 21/09/2017
Description

Final Version. This indicator displays the pivot points of the previous candle, according to the PivotTimeFrame.

Released: 21/09/2017

Latest update: 29/09/2017

Notifications: You can display the different pivot points individually.

Example:

Download
229 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
// This indicator displays the pivot points of the previous candle, 
// according to the PivotTimeFrame.
// The indicator renews its data every candle closing.
// You can display the different pivot points individually.
//
// ---- Latest Update: Friday29September2017
//                                                  -----------------
//                                                       Author          
//                                                    Mario Verheye
//                                                  -----------------
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator("MaVe-PivotPoints", IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MaVePivotPoints : Indicator
    {
        [Parameter("Pivot TimeFrame", DefaultValue = "Daily")]
        public TimeFrame PivotTimeFrame { get; set; }
        [Parameter("Shift", DefaultValue = -200, MinValue = -500, MaxValue = -20, Step = 30)]
        public int Shift { get; set; }
        [Parameter("Show S/R Pivots", DefaultValue = true)]
        public bool ShowSupportResistancePivots { get; set; }
        [Parameter("Show Middle Pivots", DefaultValue = true)]
        public bool ShowMiddlePivots { get; set; }
        [Parameter("Show Previous Pivots", DefaultValue = true)]
        public bool ShowPreviousPivots { get; set; }
        [Parameter("Thickness", DefaultValue = 1, Step = 0.5)]
        public double Thickness { get; set; }
        private MarketSeries T;
// ----- 
        Colors Rc = Colors.DarkGreen;
        Colors PP1c = Colors.Yellow;
        Colors PPc = Colors.DarkSlateGray;
        Colors Sc = Colors.DarkRed;
        Colors Mc = Colors.DarkBlue;
// ------------------------------------------------------        
        protected override void Initialize()
        {
            T = MarketData.GetSeries(Symbol, PivotTimeFrame);
        }
// ------------------------------------------------------ 
        public override void Calculate(int index)
        {
            var Text = GetTimeFrameText();
// ----- Previous candle pivot values according to PivotTimeFrame
            var pivot1 = ((T.High.Last(1) + T.Low.Last(1) + T.Close.Last(1)) / 3);
            var pivot2 = ((T.High.Last(2) + T.Low.Last(2) + T.Close.Last(2)) / 3);
            var pivot3 = ((T.High.Last(3) + T.Low.Last(3) + T.Close.Last(3)) / 3);
            var pivot4 = ((T.High.Last(4) + T.Low.Last(4) + T.Close.Last(4)) / 3);
            var pivot5 = ((T.High.Last(5) + T.Low.Last(5) + T.Close.Last(5)) / 3);
            var pivot6 = ((T.High.Last(6) + T.Low.Last(6) + T.Close.Last(6)) / 3);
// -----
            var r1 = 2 * pivot1 - T.Low.Last(1);
            var s1 = 2 * pivot1 - T.High.Last(1);
            var r2 = pivot1 + T.High.Last(1) - T.Low.Last(1);
            var s2 = pivot1 - T.High.Last(1) + T.Low.Last(1);
            var r3 = T.High.Last(1) + 2 * (pivot1 - T.Low.Last(1));
            var s3 = T.Low.Last(1) - 2 * (T.High.Last(1) - pivot1);

            var m0 = (s3 + s2) / 2.0;
            var m1 = (s2 + s1) / 2.0;
            var m2 = (s1 + pivot1) / 2.0;
            var m3 = (pivot1 + r1) / 2.0;
            var m4 = (r1 + r2) / 2.0;
            var m5 = (r2 + r3) / 2.0;
// -----     
            ChartObjects.DrawVerticalLine("PPLine", index + Shift, PP1c, 1, LineStyle.DotsVeryRare);

            ChartObjects.DrawText("PP1", Text + " PP", index + Shift, pivot1, VerticalAlignment.Top, HorizontalAlignment.Right, PP1c);
            ChartObjects.DrawLine("PP1-Line", index + Shift, pivot1, index + 1, pivot1, PP1c, Thickness);
// -----
            if (ShowSupportResistancePivots)
            {
                ChartObjects.DrawText("R3", Text + " R3", index + Shift, r3, VerticalAlignment.Top, HorizontalAlignment.Right, Rc);
                ChartObjects.DrawText("R2", Text + " R2", index + Shift, r2, VerticalAlignment.Top, HorizontalAlignment.Right, Rc);
                ChartObjects.DrawText("R1", Text + " R1", index + Shift, r1, VerticalAlignment.Top, HorizontalAlignment.Right, Rc);
                ChartObjects.DrawText("S1", Text + " S1", index + Shift, s1, VerticalAlignment.Top, HorizontalAlignment.Right, Sc);
                ChartObjects.DrawText("S2", Text + " S2", index + Shift, s2, VerticalAlignment.Top, HorizontalAlignment.Right, Sc);
                ChartObjects.DrawText("S3", Text + " S3", index + Shift, s3, VerticalAlignment.Top, HorizontalAlignment.Right, Sc);

                ChartObjects.DrawLine("R3-Line", index + Shift, r3, index + 1, r3, Rc, Thickness);
                ChartObjects.DrawLine("R2-Line", index + Shift, r2, index + 1, r2, Rc, Thickness);
                ChartObjects.DrawLine("R1-Line", index + Shift, r1, index + 1, r1, Rc, Thickness);
                ChartObjects.DrawLine("S1-Line", index + Shift, s1, index + 1, s1, Sc, Thickness);
                ChartObjects.DrawLine("S2-Line", index + Shift, s2, index + 1, s2, Sc, Thickness);
                ChartObjects.DrawLine("S3-Line", index + Shift, s3, index + 1, s3, Sc, Thickness);
            }
// -----
            if (ShowMiddlePivots)
            {
                ChartObjects.DrawText("M5", Text + " M5", index + Shift, m5, VerticalAlignment.Top, HorizontalAlignment.Right, Mc);
                ChartObjects.DrawText("M4", Text + " M4", index + Shift, m4, VerticalAlignment.Top, HorizontalAlignment.Right, Mc);
                ChartObjects.DrawText("M3", Text + " M3", index + Shift, m3, VerticalAlignment.Top, HorizontalAlignment.Right, Mc);
                ChartObjects.DrawText("M2", Text + " M2", index + Shift, m2, VerticalAlignment.Top, HorizontalAlignment.Right, Mc);
                ChartObjects.DrawText("M1", Text + " M1", index + Shift, m1, VerticalAlignment.Top, HorizontalAlignment.Right, Mc);
                ChartObjects.DrawText("M0", Text + " M0", index + Shift, m0, VerticalAlignment.Top, HorizontalAlignment.Right, Mc);

                ChartObjects.DrawLine("M5-Line", index + Shift, m5, index + 1, m5, Mc, Thickness);
                ChartObjects.DrawLine("M4-Line", index + Shift, m4, index + 1, m4, Mc, Thickness);
                ChartObjects.DrawLine("M3-Line", index + Shift, m3, index + 1, m3, Mc, Thickness);
                ChartObjects.DrawLine("M2-Line", index + Shift, m2, index + 1, m2, Mc, Thickness);
                ChartObjects.DrawLine("M1-Line", index + Shift, m1, index + 1, m1, Mc, Thickness);
                ChartObjects.DrawLine("M0-Line", index + Shift, m0, index + 1, m0, Mc, Thickness);
            }
// -----
            if (ShowPreviousPivots)
            {
                ChartObjects.DrawText("PP2", Text + " PP -02", index + Shift, pivot2, VerticalAlignment.Top, HorizontalAlignment.Left, PPc);
                ChartObjects.DrawText("PP3", Text + " PP -03", index + Shift, pivot3, VerticalAlignment.Top, HorizontalAlignment.Left, PPc);
                ChartObjects.DrawText("PP4", Text + " PP -04", index + Shift, pivot4, VerticalAlignment.Top, HorizontalAlignment.Left, PPc);
                ChartObjects.DrawText("PP5", Text + " PP -05", index + Shift, pivot5, VerticalAlignment.Top, HorizontalAlignment.Left, PPc);
                ChartObjects.DrawText("PP6", Text + " PP -06", index + Shift, pivot6, VerticalAlignment.Top, HorizontalAlignment.Left, PPc);

                ChartObjects.DrawLine("PP2-Line", index + Shift, pivot2, index + 1, pivot2, PPc, 1);
                ChartObjects.DrawLine("PP3-Line", index + Shift, pivot3, index + 1, pivot3, PPc, 1);
                ChartObjects.DrawLine("PP4-Line", index + Shift, pivot4, index + 1, pivot4, PPc, 1);
                ChartObjects.DrawLine("PP5-Line", index + Shift, pivot5, index + 1, pivot5, PPc, 1);
                ChartObjects.DrawLine("PP6-Line", index + Shift, pivot6, index + 1, pivot6, PPc, 1);
            }
        }
        private string GetTimeFrameText()
        {
            if (PivotTimeFrame == TimeFrame.Monthly)
            {
                return "M1";
            }
            if (PivotTimeFrame == TimeFrame.Weekly)
            {
                return "W1";
            }
            if (PivotTimeFrame == TimeFrame.Day3)
            {
                return "D3";
            }
            if (PivotTimeFrame == TimeFrame.Day2)
            {
                return "D2";
            }
            if (PivotTimeFrame == TimeFrame.Daily)
            {
                return "D1";
            }
            if (PivotTimeFrame == TimeFrame.Hour12)
            {
                return "H12";
            }
            if (PivotTimeFrame == TimeFrame.Hour8)
            {
                return "H8";
            }
            if (PivotTimeFrame == TimeFrame.Hour6)
            {
                return "H6";
            }
            if (PivotTimeFrame == TimeFrame.Hour4)
            {
                return "H4";
            }
            if (PivotTimeFrame == TimeFrame.Hour2)
            {
                return "H2";
            }
            if (PivotTimeFrame == TimeFrame.Hour)
            {
                return "H1";
            }
            if (PivotTimeFrame == TimeFrame.Minute45)
            {
                return "m45";
            }
            if (PivotTimeFrame == TimeFrame.Minute30)
            {
                return "m30";
            }
            if (PivotTimeFrame == TimeFrame.Minute20)
            {
                return "m20";
            }
            if (PivotTimeFrame == TimeFrame.Minute15)
            {
                return "m15";
            }
            if (PivotTimeFrame == TimeFrame.Minute10)
            {
                return "m10";
            }
            if (PivotTimeFrame == TimeFrame.Minute9)
            {
                return "m9";
            }
            if (PivotTimeFrame == TimeFrame.Minute8)
            {
                return "m8";
            }
            if (PivotTimeFrame == TimeFrame.Minute9)
            {
                return "m9";
            }
            if (PivotTimeFrame == TimeFrame.Minute8)
            {
                return "m8";
            }
            if (PivotTimeFrame == TimeFrame.Minute7)
            {
                return "m7";
            }
            if (PivotTimeFrame == TimeFrame.Minute6)
            {
                return "m6";
            }
            if (PivotTimeFrame == TimeFrame.Minute5)
            {
                return "m5";
            }
            if (PivotTimeFrame == TimeFrame.Minute4)
            {
                return "m4";
            }
            if (PivotTimeFrame == TimeFrame.Minute3)
            {
                return "m3";
            }
            if (PivotTimeFrame == TimeFrame.Minute2)
            {
                return "m2";
            }
            if (PivotTimeFrame == TimeFrame.Minute)
            {
                return "m1";
            }
            return PivotTimeFrame.ToString();
        }
    }
}



Comments

jcr1818@gmail.com - September 26, 2017 @ 10:40

Hello and thanks for update. But what do I wrong ved the settings? My pivot points don not look like the picture here? http://peecee.dk/upload/view/469534/full. (4 hour chart).

Best regards Jcr1818

MaVe - September 26, 2017 @ 10:58

The main pivot point (PP) is calculated on the last closed bar. You are looking at a H4 chart with H4 PivotTimeFrame. Use a lower Chart Timeframe...

If you want to see the monthly, weekly, daily pivots on one chart: use the indicator multiple times and shift them next to each other...

MaVe

0