Category Other  Published on 16/12/2021

Camarilla Pivot Points

Description

Camarilla Pivot Points is a modified version of the classic Pivot Point.

Camarilla Pivot Points were introduced in 1989 by Nick Scott, a successful bond trader.

The basic idea behind Camarilla Pivot Points is that price has a tendency to revert to its mean until it doesn’t.

What makes it different than the classic pivot point formula is the use of Fibonacci numbers in its calculation of pivot levels.

Camarilla Pivot Points is a math-based price action analysis tool that generates potential intraday support and resistance levels. 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.GTBStandardTime, AccessRights = AccessRights.None)]
    public class CamarillaPivotPoints : Indicator
    {

        [Parameter(DefaultValue = 200)]
        public int Periods { get; set; }

        [Output("Daily R1", LineStyle = LineStyle.DotsVeryRare, LineColor = "Blue")]
        public IndicatorDataSeries dR1 { get; set; }

        [Output("Daily R2", LineStyle = LineStyle.DotsVeryRare, LineColor = "Blue")]
        public IndicatorDataSeries dR2 { get; set; }

        [Output("Daily R3", LineStyle = LineStyle.DotsVeryRare, LineColor = "Blue")]
        public IndicatorDataSeries dR3 { get; set; }

        [Output("Daily R4", LineStyle = LineStyle.DotsVeryRare, LineColor = "Blue")]
        public IndicatorDataSeries dR4 { get; set; }

        [Output("Daily S1", LineStyle = LineStyle.DotsVeryRare, LineColor = "Red")]
        public IndicatorDataSeries dS1 { get; set; }

        [Output("Daily S2", LineStyle = LineStyle.DotsVeryRare, LineColor = "Red")]
        public IndicatorDataSeries dS2 { get; set; }

        [Output("Daily S3", LineStyle = LineStyle.DotsVeryRare, LineColor = "Red")]
        public IndicatorDataSeries dS3 { get; set; }

        [Output("Daily S4", LineStyle = LineStyle.DotsVeryRare, LineColor = "Red")]
        public IndicatorDataSeries dS4 { get; set; }

        [Output("Weekly R1", LineStyle = LineStyle.DotsVeryRare, LineColor = "Cyan")]
        public IndicatorDataSeries wR1 { get; set; }

        [Output("Weekly R2", LineStyle = LineStyle.DotsVeryRare, LineColor = "Cyan")]
        public IndicatorDataSeries wR2 { get; set; }

        [Output("Weekly R3", LineStyle = LineStyle.DotsVeryRare, LineColor = "Cyan")]
        public IndicatorDataSeries wR3 { get; set; }

        [Output("Weekly R4", LineStyle = LineStyle.DotsVeryRare, LineColor = "Cyan")]
        public IndicatorDataSeries wR4 { get; set; }

        [Output("Weekly S1", LineStyle = LineStyle.DotsVeryRare, LineColor = "Magenta")]
        public IndicatorDataSeries wS1 { get; set; }

        [Output("Weekly S2", LineStyle = LineStyle.DotsVeryRare, LineColor = "Magenta")]
        public IndicatorDataSeries wS2 { get; set; }

        [Output("Weekly S3", LineStyle = LineStyle.DotsVeryRare, LineColor = "Magenta")]
        public IndicatorDataSeries wS3 { get; set; }

        [Output("Weekly S4", LineStyle = LineStyle.DotsVeryRare, LineColor = "Magenta")]
        public IndicatorDataSeries wS4 { get; set; }

        private Bars dailyBars;
        private Bars weeklyBars;

        protected override void Initialize()
        {
            dailyBars = MarketData.GetBars(TimeFrame.Daily, SymbolName);
            weeklyBars = MarketData.GetBars(TimeFrame.Weekly, SymbolName);

            while (dailyBars.Count < Periods)
            {
                int loadedCount = dailyBars.LoadMoreHistory();
                if (loadedCount == 0)
                    break;
            }

            while (weeklyBars.Count < Periods / 5 + 1)
            {
                int loadedCount = weeklyBars.LoadMoreHistory();
                if (loadedCount == 0)
                    break;
            }
        }

        public override void Calculate(int index)
        {
            if (index < Bars.Count - Periods)
                return;
            DateTime date = Bars.OpenTimes[index].Date;
            int d = 0;
            while (dailyBars.OpenTimes[d].Date.CompareTo(date) < 0)
                d++;
            Bar previousDayBar = dailyBars[d - 1];

            double c, h, l;
            c = previousDayBar.Close;
            h = previousDayBar.High;
            l = previousDayBar.Low;

            dR4[index] = (h - l) * 1.1 / 2 + c;
            dR3[index] = (h - l) * 1.1 / 4 + c;
            dR2[index] = (h - l) * 1.1 / 6 + c;
            dR1[index] = (h - l) * 1.1 / 12 + c;
            dS1[index] = c - (h - l) * 1.1 / 12;
            dS2[index] = c - (h - l) * 1.1 / 6;
            dS3[index] = c - (h - l) * 1.1 / 4;
            dS4[index] = c - (h - l) * 1.1 / 2;


            int diff = (7 + (date.DayOfWeek - DayOfWeek.Monday)) % 7;
            DateTime startOfWeek = date.AddDays(-diff);
            int w = 0;
            while (weeklyBars.OpenTimes[w].Date.CompareTo(startOfWeek) < 0)
                w++;
            Bar previousWeekBar = weeklyBars[w - 1];

            c = previousWeekBar.Close;
            h = previousWeekBar.High;
            l = previousWeekBar.Low;

            wR4[index] = (h - l) * 1.1 / 2 + c;
            wR3[index] = (h - l) * 1.1 / 4 + c;
            wR2[index] = (h - l) * 1.1 / 6 + c;
            wR1[index] = (h - l) * 1.1 / 12 + c;
            wS1[index] = c - (h - l) * 1.1 / 12;
            wS2[index] = c - (h - l) * 1.1 / 6;
            wS3[index] = c - (h - l) * 1.1 / 4;
            wS4[index] = c - (h - l) * 1.1 / 2;
        }
    }
}


TR
TradeHawk

Joined on 15.10.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Camarilla Pivot Points.algo
  • Rating: 0
  • Installs: 1624
Comments
Log in to add a comment.
No comments found.