Category Other  Published on 27/07/2024

Pivot Point for Scanner

Description

Many pivot points are available on cTrader, but this one is necessary for the Telegram alert scanner. =)

Scanner here : https://ctrader.com/algos/cbots/show/4404/

Enjoy for Free =) 


Previous account here : https://ctrader.com/users/profile/70920
Contact telegram :  https://t.me/nimi012 

 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

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

        [Parameter("Mode", DefaultValue = ModeType.FibonacciHighLowOnClose)]
        public ModeType Mode { get; set; }

        [Parameter("Time Frame", DefaultValue = "Month1")]
        public TimeFrame TF { get; set; }


        [Output("High", LineColor = "8EFFA500", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries h { get; set; }
        [Output("Low", LineColor = "8EFFA500", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries l { get; set; }

        [Output("Pivot", LineColor = "7200FFFF", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries p { get; set; }
        [Output("M", LineColor = "8EFFA500", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries m { get; set; }
        [Output("MH", LineColor = "6CFFFFFF", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries mh { get; set; }
        [Output("ML", LineColor = "6CFFFFFF", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries ml { get; set; }
        [Output("R1", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r1 { get; set; }
        [Output("R2", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r2 { get; set; }
        [Output("R3", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r3 { get; set; }
        [Output("R4", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r4 { get; set; }
        [Output("R5", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r5 { get; set; }
        [Output("R6", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r6 { get; set; }
        [Output("R7", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r7 { get; set; }
        [Output("R8", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r8 { get; set; }
        [Output("R9", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r9 { get; set; }
        [Output("R10", LineColor = "66008000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries r10 { get; set; }
        [Output("S1", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s1 { get; set; }
        [Output("S2", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s2 { get; set; }
        [Output("S3", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s3 { get; set; }
        [Output("S4", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s4 { get; set; }
        [Output("S5", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s5 { get; set; }
        [Output("S6", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s6 { get; set; }
        [Output("S7", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s7 { get; set; }
        [Output("S8", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s8 { get; set; }
        [Output("S9", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s9 { get; set; }
        [Output("S10", LineColor = "47FF0000", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries s10 { get; set; }

        public IndicatorDataSeries NextHighPriceFibo, NextLowPriceFibo, NextHighPctFibo, NextLowPctFibo;

        public string HighPivot, LowPivot;
        private Bars pivotBars;

        public IndicatorDataSeries[] res;
        public IndicatorDataSeries[] breakPlus;
        public IndicatorDataSeries[] breakMinus;
        public IndicatorDataSeries[] gapPlus;
        public IndicatorDataSeries[] gapMinus;
        public IndicatorDataSeries[] rejectPlus;
        public IndicatorDataSeries[] rejectMinus;

        public enum ModeType
        {
            Standard,
            Fibonacci,
            FibonacciOpenClose,
            FibonacciHighLow,
            FibonacciHighLowOnClose,
            Camarilla,
            Woodie,
            DeMark
        }

        public enum LevelType
        {
            MH,
            M,
            ML,
            R1,
            R2,
            R3,
            R4,
            R5,
            R6,
            R7,
            R8,
            S1,
            S2,
            S3,
            S4,
            S5,
            S6,
            S7,
            S8,
            None
        }

        protected override void Initialize()
        {

            NextHighPriceFibo = CreateDataSeries();
            NextLowPriceFibo = CreateDataSeries();
            NextHighPctFibo = CreateDataSeries();
            NextLowPctFibo = CreateDataSeries();
            HighPivot = "";
            LowPivot = "";

            pivotBars = MarketData.GetBars(TF);

            res = new IndicatorDataSeries[19];
            res[0] = r8;
            res[1] = r7;
            res[2] = r6;
            res[3] = r5;
            res[4] = r4;
            res[5] = r3;
            res[6] = r2;
            res[7] = r1;
            res[8] = mh;
            res[9] = m;
            res[10] = ml;
            res[11] = s1;
            res[12] = s2;
            res[13] = s3;
            res[14] = s4;
            res[15] = s5;
            res[16] = s6;
            res[17] = s7;
            res[18] = s8;

            breakPlus = new IndicatorDataSeries[19];
            breakMinus = new IndicatorDataSeries[19];
            gapPlus = new IndicatorDataSeries[19];
            gapMinus = new IndicatorDataSeries[19];
            rejectPlus = new IndicatorDataSeries[19];
            rejectMinus = new IndicatorDataSeries[19];
            for (int i = 0; i < res.Length; i++)
            {
                breakPlus[i] = CreateDataSeries();
                breakMinus[i] = CreateDataSeries();
                gapPlus[i] = CreateDataSeries();
                gapMinus[i] = CreateDataSeries();
                rejectPlus[i] = CreateDataSeries();
                rejectMinus[i] = CreateDataSeries();
            }
        }

        public override void Calculate(int index)
        {
            int pivotIndex = pivotBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) - 1;

            if (index > 0)
            {
                CalculatePivots(index, pivotIndex);
            }

            for (int i = 0; i < res.Length; i++)
            {
                breakPlus[i][index] = 0;
                breakMinus[i][index] = 0;
                gapPlus[i][index] = 0;
                gapMinus[i][index] = 0;
                rejectPlus[i][index] = 0;
                rejectMinus[i][index] = 0;

                if (!double.IsNaN(res[i][index]))
                {

                    // Break Pus: Gap-up or close above pivot line and open below
                    if ((Bars.ClosePrices[index] > res[i][index] && Bars.OpenPrices[index] < res[i][index]))
                    {
                        breakPlus[i][index] = 1;
                    }

                    // Break Mins: Gap-down or close below pivot line and open above
                    if ((Bars.ClosePrices[index] < res[i][index] && Bars.OpenPrices[index] > res[i][index]))
                    {
                        breakMinus[i][index] = 1;
                    }

                    if ((Bars.ClosePrices[index - 2] < res[i][index - 1] && Bars.OpenPrices[index - 1] > res[i][index]))
                    {
                        gapPlus[i][index] = 1;
                    }

                    // Break Mins: Gap-down or close below pivot line and open above
                    if (Bars.ClosePrices[index - 2] > res[i][index - 1] && Bars.OpenPrices[index - 1] < res[i][index])
                    {
                        gapMinus[i][index] = 1;
                    }

                    // Rejection Plus: low below pivot line but open and close above
                    if (Bars.LowPrices[index] < res[i][index] && Bars.ClosePrices[index] > res[i][index] && Bars.OpenPrices[index] > res[i][index])
                    {
                        rejectPlus[i][index] = 1;
                    }

                    // Rejection Minus: high above pivot line but open and close below
                    if (Bars.HighPrices[index] > res[i][index] && Bars.ClosePrices[index] < res[i][index] && Bars.OpenPrices[index] < res[i][index])
                    {
                        rejectMinus[i][index] = 1;
                    }
                }

            }
        }

        public void CalculatePivots(int index, int pivotIndex)
        {
            double high = pivotBars.HighPrices[pivotIndex];
            double low = pivotBars.LowPrices[pivotIndex];
            double close = pivotBars.ClosePrices[pivotIndex];
            double open1 = pivotBars.OpenPrices[pivotIndex];

            switch (Mode)
            {
                default:
                case ModeType.Standard:
                    if (Mode == ModeType.Standard || Mode == ModeType.Woodie)
                    {
                        if (Mode == ModeType.Woodie)
                            p[index] = (high + low + 2 * close) / 4;
                        else
                            p[index] = (high + low + close) / 3;

                        h[index] = high;
                        l[index] = low;

                        m[index] = close;

                        ml[index] = close;
                        mh[index] = open1;

                        r1[index] = 2 * p[index] - low;
                        r2[index] = p[index] + high - low;

                        s1[index] = 2 * p[index] - high;
                        s2[index] = p[index] - high + low;

                        r3[index] = high + 2 * (p[index] - low);
                        s3[index] = low - 2 * (high - p[index]);

                        r4[index] = p[index] + 2 * (high - low);
                        s4[index] = p[index] - 2 * (high - low);

                        r5[index] = (r1[index] + r2[index]) / 2;
                        s5[index] = (s1[index] + s2[index]) / 2;

                        r6[index] = (r2[index] + r3[index]) / 2;
                        s6[index] = (s2[index] + s3[index]) / 2;

                        r7[index] = (r3[index] + r4[index]) / 2;
                        s7[index] = (s3[index] + s4[index]) / 2;

                        r8[index] = (p[index] + r1[index]) / 2;
                        s8[index] = (p[index] + s1[index]) / 2;
                    }
                    break;

                case ModeType.Fibonacci:

                    p[index] = (high + low + close) / 3.0;

                    h[index] = high;
                    l[index] = low;

                    m[index] = close;

                    ml[index] = close;
                    mh[index] = open1;

                    r1[index] = p[index] + (high - low) * 0.382;
                    s1[index] = p[index] - (high - low) * 0.382;

                    r2[index] = p[index] + (high - low) * 0.618;
                    s2[index] = p[index] - (high - low) * 0.618;

                    r3[index] = p[index] + (high - low) * 0.886;
                    s3[index] = p[index] - (high - low) * 0.886;

                    r3[index] = p[index] + (high - low) * 1.0;
                    s3[index] = p[index] - (high - low) * 1.0;

                    r4[index] = p[index] + (high - low) * 1.27;
                    s4[index] = p[index] - (high - low) * 1.27;

                    r5[index] = p[index] + (high - low) * 1.618;
                    s5[index] = p[index] - (high - low) * 1.618;

                    r6[index] = p[index] + (high - low) * 2.0;
                    s6[index] = p[index] - (high - low) * 2.0;

                    r7[index] = p[index] + (high - low) * 2.618;
                    s7[index] = p[index] - (high - low) * 2.618;

                    r8[index] = double.NaN;
                    s8[index] = double.NaN;

                    r9[index] = double.NaN;
                    s9[index] = double.NaN;

                    r10[index] = double.NaN;
                    s10[index] = double.NaN;

                    break;

                case ModeType.FibonacciOpenClose:

                    if (Mode == ModeType.FibonacciOpenClose)
                    {

                        if (open1 > close)
                        {
                            p[index] = close;

                            h[index] = high;
                            l[index] = low;

                            ml[index] = close;
                            mh[index] = open1;


                            r1[index] = close + ((open1 - close) * 0.114);
                            s1[index] = close - ((open1 - close) * 0.114);

                            r2[index] = close + ((open1 - close) * 0.146);
                            s2[index] = close - ((open1 - close) * 0.146);

                            r3[index] = close + ((open1 - close) * 0.236);
                            s3[index] = close - ((open1 - close) * 0.236);

                            r4[index] = close + ((open1 - close) * 0.382);
                            s4[index] = close - ((open1 - close) * 0.382);

                            r5[index] = close + ((open1 - close) * 0.5);
                            s5[index] = close - ((open1 - close) * 0.5);

                            r6[index] = close + ((open1 - close) * 0.618);
                            s6[index] = close - ((open1 - close) * 0.618);

                            r7[index] = close + ((open1 - close) * 0.707);
                            s7[index] = close - ((open1 - close) * 0.707);

                            r8[index] = close + ((open1 - close) * 0.763);
                            s8[index] = close - ((open1 - close) * 0.763);

                            r9[index] = close + ((open1 - close) * 0.886);
                            s9[index] = close - ((open1 - close) * 0.886);

                            r10[index] = close + (open1 - close);
                            s10[index] = close - (open1 - close);
                        }

                        if (open1 < close)
                        {
                            p[index] = close;

                            h[index] = high;
                            l[index] = low;

                            ml[index] = close;
                            mh[index] = open1;

                            s1[index] = close + ((open1 - close) * 0.114);
                            r1[index] = close - ((open1 - close) * 0.114);

                            s2[index] = close + ((open1 - close) * 0.146);
                            r2[index] = close - ((open1 - close) * 0.146);

                            s3[index] = close + ((open1 - close) * 0.236);
                            r3[index] = close - ((open1 - close) * 0.236);

                            s4[index] = close + ((open1 - close) * 0.382);
                            r4[index] = close - ((open1 - close) * 0.382);

                            s5[index] = close + ((open1 - close) * 0.5);
                            r5[index] = close - ((open1 - close) * 0.5);

                            s6[index] = close + ((open1 - close) * 0.618);
                            r6[index] = close - ((open1 - close) * 0.618);

                            s7[index] = close + ((open1 - close) * 0.707);
                            r7[index] = close - ((open1 - close) * 0.707);

                            s8[index] = close + ((open1 - close) * 0.763);
                            r8[index] = close - ((open1 - close) * 0.763);

                            s9[index] = close + ((open1 - close) * 0.886);
                            r9[index] = close - ((open1 - close) * 0.886);

                            s10[index] = close + (open1 - close);
                            r10[index] = close - (open1 - close);
                        }
                    }
                    break;
                case ModeType.FibonacciHighLow:

                    if (open1 < close)
                    {
                        p[index] = high;

                        h[index] = high;
                        l[index] = low;

                        m[index] = close;

                        ml[index] = close;
                        mh[index] = open1;

                        r1[index] = high + ((high - low) * 0.114);
                        s1[index] = high - ((high - low) * 0.114);

                        r2[index] = high + ((high - low) * 0.146);
                        s2[index] = high - ((high - low) * 0.146);

                        r3[index] = high + ((high - low) * 0.236);
                        s3[index] = high - ((high - low) * 0.236);

                        r4[index] = high + ((high - low) * 0.382);
                        s4[index] = high - ((high - low) * 0.382);

                        r5[index] = high + ((high - low) * 0.5);
                        s5[index] = high - ((high - low) * 0.5);

                        r6[index] = high + ((high - low) * 0.618);
                        s6[index] = high - ((high - low) * 0.618);

                        r7[index] = high + ((high - low) * 0.707);
                        s7[index] = high - ((high - low) * 0.707);

                        r8[index] = high + ((high - low) * 0.763);
                        s8[index] = high - ((high - low) * 0.763);

                        r9[index] = high + ((high - low) * 0.886);
                        s9[index] = high - ((high - low) * 0.886);

                        r10[index] = high + (high - low);
                        s10[index] = high - (high - low);

                    }

                    else if (open1 > close)
                    {
                        p[index] = low;

                        h[index] = high;
                        l[index] = low;

                        ml[index] = close;
                        mh[index] = open1;

                        m[index] = close;

                        mh[index] = close + (open1 - close);
                        ml[index] = close - (open1 - close);

                        r1[index] = low - ((low - high) * 0.114);
                        s1[index] = low + ((low - high) * 0.114);

                        r2[index] = low - ((low - high) * 0.146);
                        s2[index] = low + ((low - high) * 0.146);

                        r3[index] = low - ((low - high) * 0.236);
                        s3[index] = low + ((low - high) * 0.236);

                        r4[index] = low - ((low - high) * 0.382);
                        s4[index] = low + ((low - high) * 0.382);

                        r5[index] = low - ((low - high) * 0.5);
                        s5[index] = low + ((low - high) * 0.5);

                        r6[index] = low - ((low - high) * 0.618);
                        s6[index] = low + ((low - high) * 0.618);

                        r7[index] = low - ((low - high) * 0.707);
                        s7[index] = low + ((low - high) * 0.707);

                        r8[index] = low - ((low - high) * 0.763);
                        s8[index] = low + ((low - high) * 0.763);

                        r9[index] = low - ((low - high) * 0.886);
                        s9[index] = low + ((low - high) * 0.886);

                        r10[index] = low - (low - high);
                        s10[index] = low + (low - high);

                    }

                    break;
                case ModeType.FibonacciHighLowOnClose:

                    if (open1 < close)
                    {
                        p[index] = close;

                        h[index] = high;
                        l[index] = low;

                        m[index] = close;

                        ml[index] = close;
                        mh[index] = open1;

                        r1[index] = close + ((high - low) * 0.114);
                        s1[index] = close - ((high - low) * 0.114);

                        r2[index] = close + ((high - low) * 0.146);
                        s2[index] = close - ((high - low) * 0.146);

                        r3[index] = close + ((high - low) * 0.236);
                        s3[index] = close - ((high - low) * 0.236);

                        r4[index] = close + ((high - low) * 0.382);
                        s4[index] = close - ((high - low) * 0.382);

                        r5[index] = close + ((high - low) * 0.5);
                        s5[index] = close - ((high - low) * 0.5);

                        r6[index] = close + ((high - low) * 0.618);
                        s6[index] = close - ((high - low) * 0.618);

                        r7[index] = close + ((high - low) * 0.707);
                        s7[index] = close - ((high - low) * 0.707);

                        r8[index] = close + ((high - low) * 0.763);
                        s8[index] = close - ((high - low) * 0.763);

                        r9[index] = close + ((high - low) * 0.886);
                        s9[index] = close - ((high - low) * 0.886);

                        r10[index] = close + (high - low);
                        s10[index] = close - (high - low);

                    }

                    else if (open1 > close)
                    {
                        p[index] = close;

                        h[index] = high;
                        l[index] = low;

                        m[index] = close;

                        ml[index] = close;
                        mh[index] = open1;

                        r1[index] = close - ((low - high) * 0.114);
                        s1[index] = close + ((low - high) * 0.114);

                        r2[index] = close - ((low - high) * 0.146);
                        s2[index] = close + ((low - high) * 0.146);

                        r3[index] = close - ((low - high) * 0.236);
                        s3[index] = close + ((low - high) * 0.236);

                        r4[index] = close - ((low - high) * 0.382);
                        s4[index] = close + ((low - high) * 0.382);

                        r5[index] = close - ((low - high) * 0.5);
                        s5[index] = close + ((low - high) * 0.5);

                        r6[index] = close - ((low - high) * 0.618);
                        s6[index] = close + ((low - high) * 0.618);

                        r7[index] = close - ((low - high) * 0.707);
                        s7[index] = close + ((low - high) * 0.707);

                        r8[index] = close - ((low - high) * 0.763);
                        s8[index] = close + ((low - high) * 0.763);

                        r9[index] = close - ((low - high) * 0.886);
                        s9[index] = close + ((low - high) * 0.886);

                        r10[index] = close - (low - high);
                        s10[index] = close + (low - high);

                    }

                    break;
                case ModeType.Camarilla:

                    p[index] = (high + low + close) / 3.0;

                    m[index] = close;

                    h[index] = close;
                    l[index] = open1;

                    ml[index] = close - (high - low) * 1.1 / 24;
                    mh[index] = close + (high - low) * 1.1 / 24;

                    r1[index] = close + (high - low) * 1.1 / 12.0;
                    s1[index] = close - (high - low) * 1.1 / 12.0;

                    r2[index] = close + (high - low) * 1.1 / 6.0;
                    s2[index] = close - (high - low) * 1.1 / 6.0;

                    r3[index] = close + (high - low) * 1.1 / 4.0;
                    s3[index] = close - (high - low) * 1.1 / 4.0;

                    r4[index] = close + (high - low) * 1.1 / 2.0;
                    s4[index] = close - (high - low) * 1.1 / 2.0;

                    r5[index] = close + (high - low) * 1.1 * 3.0 / 4.0;
                    s5[index] = close - (high - low) * 1.1 * 3.0 / 4.0;

                    r6[index] = close + (high - low) * 1.1;
                    s6[index] = close - (high - low) * 1.1;

                    r7[index] = close + (high - low) * 1.1 * 5.0 / 4.0;
                    s7[index] = close - (high - low) * 1.1 * 5.0 / 4.0;

                    r8[index] = close + (high - low) * 1.1 * 3.0 / 2.0;
                    s8[index] = close - (high - low) * 1.1 * 3.0 / 2.0;

                    r9[index] = double.NaN;
                    s9[index] = double.NaN;

                    r10[index] = double.NaN;
                    s10[index] = double.NaN;



                    break;
                case ModeType.DeMark:

                    double open = Bars.OpenPrices[index - 1];
                    double X = close < open ? (high + 2.0 * low + close) : close > open ? (2.0 * high + low + close) : (high + low + 2.0 * close);

                    p[index] = X / 4.0;

                    h[index] = high;
                    l[index] = low;

                    m[index] = close;

                    ml[index] = close;
                    mh[index] = open1;

                    r1[index] = X / 2.0 - low;
                    s1[index] = X / 2.0 - high;

                    r2[index] = double.NaN;
                    s2[index] = double.NaN;

                    r3[index] = double.NaN;
                    s3[index] = double.NaN;

                    r4[index] = double.NaN;
                    s4[index] = double.NaN;

                    r5[index] = double.NaN;
                    s5[index] = double.NaN;

                    r6[index] = double.NaN;
                    s6[index] = double.NaN;

                    r7[index] = double.NaN;
                    s7[index] = double.NaN;

                    r8[index] = double.NaN;
                    s8[index] = double.NaN;

                    r9[index] = double.NaN;
                    s9[index] = double.NaN;

                    r10[index] = double.NaN;
                    s10[index] = double.NaN;


                    break;

            }


            var range = GetLevel(GetNextHigherLevel(Bars.ClosePrices.Last(0)), 0) - GetLevel(GetNextLowerLevel(Bars.ClosePrices.Last(0)), 0);
            var rangeBars = GetLevel(GetNextHigherLevel(Bars.ClosePrices.Last(0)), 0) - Bars.ClosePrices.Last(0);


            HighPivot = (GetNextHigherLevel(Bars.ClosePrices.Last(0))).ToString();
            LowPivot = (GetNextLowerLevel(Bars.ClosePrices.Last(0))).ToString();

            NextHighPctFibo[index] = rangeBars / range * 100;
            NextLowPctFibo[index] = (100 - (rangeBars / range * 100));

            NextHighPriceFibo[index] = GetLevel(GetNextHigherLevel(Bars.ClosePrices.Last(0)), 0);
            NextLowPriceFibo[index] = GetLevel(GetNextLowerLevel(Bars.ClosePrices.Last(0)), 0);

//            Print("Time :  " + Bars.OpenTimes.Last(0) + " Price :  " + Bars.ClosePrices.Last(0).ToString("F4") + " NextHighPrice " + GetNextHigherLevel(Bars.ClosePrices.Last(0)) + " : " + NextHighPriceFibo[index].ToString("F4") + "(" + NextHighPctFibo[index].ToString("F0") + ") NextLowPrice " + GetNextLowerLevel(Bars.ClosePrices.Last(0)) + " : " + NextLowPriceFibo[index].ToString("F4") + "(" + NextLowPctFibo[index].ToString("F0") + ")");

        }
        public double GetLevel(LevelType level, int barsAgo)
        {
            if (level == LevelType.MH)
                return mh.Last(barsAgo);
            else if (level == LevelType.M)
                return m.Last(barsAgo);
            else if (level == LevelType.ML)
                return ml.Last(barsAgo);
            else if (level == LevelType.R1)
                return r1.Last(barsAgo);
            else if (level == LevelType.R2)
                return r2.Last(barsAgo);
            else if (level == LevelType.R3)
                return r3.Last(barsAgo);
            else if (level == LevelType.R4)
                return r4.Last(barsAgo);
            else if (level == LevelType.R5)
                return r5.Last(barsAgo);
            else if (level == LevelType.R6)
                return r6.Last(barsAgo);
            else if (level == LevelType.R7)
                return r7.Last(barsAgo);
            else if (level == LevelType.R8)
                return r8.Last(barsAgo);
            else if (level == LevelType.S1)
                return s1.Last(barsAgo);
            else if (level == LevelType.S2)
                return s2.Last(barsAgo);
            else if (level == LevelType.S3)
                return s3.Last(barsAgo);
            else if (level == LevelType.S4)
                return s4.Last(barsAgo);
            else if (level == LevelType.S5)
                return s5.Last(barsAgo);
            else if (level == LevelType.S6)
                return s6.Last(barsAgo);
            else if (level == LevelType.S7)
                return s7.Last(barsAgo);
            else if (level == LevelType.S8)
                return s8.Last(barsAgo);
            else
                return double.NaN;
        }

        // Get next higher level
        public LevelType GetNextHigherLevel(LevelType level)
        {
            if (level == LevelType.MH)
                return LevelType.R1;
            else if (level == LevelType.M)
                return LevelType.MH;
            else if (level == LevelType.ML)
                return LevelType.M;
            else if (level == LevelType.R1)
                return LevelType.R2;
            else if (level == LevelType.R2)
                return LevelType.R3;
            else if (level == LevelType.R3)
                return LevelType.R4;
            else if (level == LevelType.R4)
                return LevelType.R5;
            else if (level == LevelType.R5)
                return LevelType.R6;
            else if (level == LevelType.R6)
                return LevelType.R7;
            else if (level == LevelType.R7)
                return LevelType.R8;
            else if (level == LevelType.R8)
                return LevelType.None;
            else if (level == LevelType.S1)
                return LevelType.ML;
            else if (level == LevelType.S2)
                return LevelType.S1;
            else if (level == LevelType.S3)
                return LevelType.S2;
            else if (level == LevelType.S4)
                return LevelType.S3;
            else if (level == LevelType.S5)
                return LevelType.S4;
            else if (level == LevelType.S6)
                return LevelType.S5;
            else if (level == LevelType.S7)
                return LevelType.S6;
            else if (level == LevelType.S8)
                return LevelType.S7;
            else
                return LevelType.None;
        }

        // Get next higher level
        public LevelType GetNextLowerLevel(LevelType level)
        {
            if (level == LevelType.MH)
                return LevelType.M;
            else if (level == LevelType.M)
                return LevelType.ML;
            else if (level == LevelType.ML)
                return LevelType.S1;
            else if (level == LevelType.R1)
                return LevelType.MH;
            else if (level == LevelType.R2)
                return LevelType.R1;
            else if (level == LevelType.R3)
                return LevelType.R2;
            else if (level == LevelType.R4)
                return LevelType.R3;
            else if (level == LevelType.R5)
                return LevelType.R4;
            else if (level == LevelType.R6)
                return LevelType.R5;
            else if (level == LevelType.R7)
                return LevelType.R6;
            else if (level == LevelType.R8)
                return LevelType.R7;
            else if (level == LevelType.S1)
                return LevelType.S2;
            else if (level == LevelType.S2)
                return LevelType.S3;
            else if (level == LevelType.S3)
                return LevelType.S4;
            else if (level == LevelType.S4)
                return LevelType.S5;
            else if (level == LevelType.S5)
                return LevelType.S6;
            else if (level == LevelType.S6)
                return LevelType.S7;
            else if (level == LevelType.S7)
                return LevelType.S8;
            else if (level == LevelType.S8)
                return LevelType.None;
            else
                return LevelType.None;
        }

        // Get next higher level from price
        public LevelType GetNextHigherLevel(double price)
        {
            if (price >= GetLevel(LevelType.R7, 0) && price < GetLevel(LevelType.R8, 0))
                return LevelType.R8;
            if (price >= GetLevel(LevelType.R6, 0) && price < GetLevel(LevelType.R7, 0))
                return LevelType.R7;
            if (price >= GetLevel(LevelType.R5, 0) && price < GetLevel(LevelType.R6, 0))
                return LevelType.R6;
            if (price >= GetLevel(LevelType.R4, 0) && price < GetLevel(LevelType.R5, 0))
                return LevelType.R5;
            if (price >= GetLevel(LevelType.R3, 0) && price < GetLevel(LevelType.R4, 0))
                return LevelType.R4;
            if (price >= GetLevel(LevelType.R2, 0) && price < GetLevel(LevelType.R3, 0))
                return LevelType.R3;
            if (price >= GetLevel(LevelType.R1, 0) && price < GetLevel(LevelType.R2, 0))
                return LevelType.R2;
            if (price >= GetLevel(LevelType.MH, 0) && price < GetLevel(LevelType.R1, 0))
                return LevelType.R1;
            if (price >= GetLevel(LevelType.M, 0) && price < GetLevel(LevelType.MH, 0))
                return LevelType.MH;
            if (price >= GetLevel(LevelType.ML, 0) && price < GetLevel(LevelType.M, 0))
                return LevelType.M;
            if (price >= GetLevel(LevelType.S1, 0) && price < GetLevel(LevelType.ML, 0))
                return LevelType.ML;
            if (price >= GetLevel(LevelType.S2, 0) && price < GetLevel(LevelType.S1, 0))
                return LevelType.S1;
            if (price >= GetLevel(LevelType.S3, 0) && price < GetLevel(LevelType.S2, 0))
                return LevelType.S2;
            if (price >= GetLevel(LevelType.S4, 0) && price < GetLevel(LevelType.S3, 0))
                return LevelType.S3;
            if (price >= GetLevel(LevelType.S5, 0) && price < GetLevel(LevelType.S4, 0))
                return LevelType.S4;
            if (price >= GetLevel(LevelType.S6, 0) && price < GetLevel(LevelType.S5, 0))
                return LevelType.S5;
            if (price >= GetLevel(LevelType.S7, 0) && price < GetLevel(LevelType.S6, 0))
                return LevelType.S6;
            if (price >= GetLevel(LevelType.S8, 0) && price < GetLevel(LevelType.S7, 0))
                return LevelType.S7;
            if (price < GetLevel(LevelType.S8, 0))
                return LevelType.S8;
            else
                return LevelType.None;
        }

        // Get next lower level from price
        public LevelType GetNextLowerLevel(double price)
        {
            if (price > GetLevel(LevelType.R8, 0))
                return LevelType.R8;
            if (price > GetLevel(LevelType.R7, 0) && price <= GetLevel(LevelType.R8, 0))
                return LevelType.R7;
            if (price > GetLevel(LevelType.R6, 0) && price <= GetLevel(LevelType.R7, 0))
                return LevelType.R6;
            if (price > GetLevel(LevelType.R5, 0) && price <= GetLevel(LevelType.R6, 0))
                return LevelType.R5;
            if (price > GetLevel(LevelType.R4, 0) && price <= GetLevel(LevelType.R5, 0))
                return LevelType.R4;
            if (price > GetLevel(LevelType.R3, 0) && price <= GetLevel(LevelType.R4, 0))
                return LevelType.R3;
            if (price > GetLevel(LevelType.R2, 0) && price <= GetLevel(LevelType.R3, 0))
                return LevelType.R2;
            if (price > GetLevel(LevelType.R1, 0) && price <= GetLevel(LevelType.R2, 0))
                return LevelType.R1;
            if (price > GetLevel(LevelType.MH, 0) && price <= GetLevel(LevelType.R1, 0))
                return LevelType.MH;
            if (price > GetLevel(LevelType.M, 0) && price <= GetLevel(LevelType.MH, 0))
                return LevelType.M;
            if (price > GetLevel(LevelType.ML, 0) && price <= GetLevel(LevelType.M, 0))
                return LevelType.ML;
            if (price > GetLevel(LevelType.S1, 0) && price <= GetLevel(LevelType.ML, 0))
                return LevelType.S1;
            if (price > GetLevel(LevelType.S2, 0) && price <= GetLevel(LevelType.S1, 0))
                return LevelType.S2;
            if (price > GetLevel(LevelType.S3, 0) && price <= GetLevel(LevelType.S2, 0))
                return LevelType.S3;
            if (price > GetLevel(LevelType.S4, 0) && price <= GetLevel(LevelType.S3, 0))
                return LevelType.S4;
            if (price > GetLevel(LevelType.S5, 0) && price <= GetLevel(LevelType.S4, 0))
                return LevelType.S5;
            if (price > GetLevel(LevelType.S6, 0) && price <= GetLevel(LevelType.S5, 0))
                return LevelType.S6;
            if (price > GetLevel(LevelType.S7, 0) && price <= GetLevel(LevelType.S6, 0))
                return LevelType.S7;
            if (price > GetLevel(LevelType.S8, 0) && price <= GetLevel(LevelType.S7, 0))
                return LevelType.S8;
            else
                return LevelType.None;
        }
    }
}


YE
YesOrNot2

Joined on 17.05.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: PivotPointAIO.algo
  • Rating: 3.33
  • Installs: 455
  • Modified: 27/07/2024 12:16
Comments
Log in to add a comment.
No comments found.