Information

Username: paul.williams125
Member since: 03 Dec 2019
Last login: 08 Mar 2023
Status: Active

Activity

Where Created Comments
Algorithms 1 5
Forum Topics 1 3
Jobs 0 0

Last Algorithm Comments

PA
paul.williams125 · 4 years ago

Now on Revision 4

1. This code makes the slope angle - more stable.

I have found that recently, some currencies have had large "gap ups" or "gaps down", in the prices. This messes up the slopemax.

 I have added, limiter code.  This stops any Bar / Gap, that is too large, adding to slopemax.

PA
paul.williams125 · 4 years ago

Revision 3

1. Secondary smoothing deleted - not needed

2. Clearer interface.

3. More sensitivity with the correction Factor.

4. Easier to use.

5. Parameter guild notes updated.

PA
paul.williams125 · 4 years ago

Revision 2

1. Minor improvements to the code.

2. Ive added a setup feature.  To setup the guild Moving Average.

PA
paul.williams125 · 4 years ago

// This Just puts an Icon above the price, on the chart.

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

//                   AutoRescale = true
namespace cAlgo
{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class SO : Indicator
    {


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

        [Parameter("K Slowing", DefaultValue = 3)]
        public int kSlowing { get; set; }

        [Parameter("D Periods", DefaultValue = 3)]
        public int dPeriods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Triangular)]
        public MovingAverageType maType { get; set; }

        [Parameter("UP Level", DefaultValue = 90, MinValue = 80, MaxValue = 100, Step = 1)]
        public int Up_Level { get; set; }

        [Parameter("Down Level", DefaultValue = 10, MinValue = 0, MaxValue = 20, Step = 1)]
        public int Down_Level { get; set; }


        private StochasticOscillator so;

        private double Extremum_Value = 0.0;
        private int Extremum_Index = 0;
        private int Last_Up_Index = 0;
        private int Last_Down_Index = 0;
        private int direction = 0;


        protected override void Initialize()
        {
            so = Indicators.StochasticOscillator(kPeriods, kSlowing, dPeriods, maType);
        }

        public override void Calculate(int index)
        {


//----------                                                                      K value is Stockastic value ( purple) , D is MA3 of it.
//-----------                                                                     if ( K is now < 90% and the previous K >= 90% )
//-----------                                                                     this is our setup for upper entry
//UP LEVEL

            if (so.PercentK[index] < Up_Level && so.PercentK[index - 1] >= Up_Level)
            {
                var high = MarketSeries.High[index];
                var highPlus2Pip = high + (5 * Symbol.PipSize);
                ChartObjects.DrawText("Info " + index, "▼", index, highPlus2Pip, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.White);
            }
//DOWN lEVEL

            if (so.PercentK[index] > Down_Level && so.PercentK[index - 1] <= Down_Level)
            {
                var low = MarketSeries.Low[index];
                var lowPlus2Pip = low - (5 * Symbol.PipSize);
                ChartObjects.DrawText("Info " + index, "▲", index, lowPlus2Pip, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.White);


            }


        }
    }
}

PA
paul.williams125 · 4 years ago

// This has been modified, to be more easily understandable.

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

namespace cAlgo
{
    [Levels(10, 20, 50, 80, 90)]

    [Indicator(IsOverlay = false, AutoRescale = true, AccessRights = AccessRights.None)]
    public class SO : Indicator
    {


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

        [Parameter("K Slowing", DefaultValue = 3)]
        public int kSlowing { get; set; }

        [Parameter("D Periods", DefaultValue = 3)]
        public int dPeriods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Triangular)]
        public MovingAverageType maType { get; set; }

        [Parameter("UP Level", DefaultValue = 90, MinValue = 80, MaxValue = 100, Step = 1)]
        public int Up_Level { get; set; }

        [Parameter("Down Level", DefaultValue = 10, MinValue = 0, MaxValue = 20, Step = 1)]
        public int Down_Level { get; set; }

        [Output("% D", Color = Colors.Aquamarine, Thickness = 2)]
        public IndicatorDataSeries Percent_D { get; set; }

        [Output("% K", Color = Colors.Purple, Thickness = 2)]
        public IndicatorDataSeries Percent_K { get; set; }

        [Output("Trend", Color = Colors.Yellow, Thickness = 1)]
        public IndicatorDataSeries Value { get; set; }


        private StochasticOscillator so;

        private double Extremum_Value = 0.0;
        private int Extremum_Index = 0;
        private int Last_Up_Index = 0;
        private int Last_Down_Index = 0;
        private int direction = 0;


        protected override void Initialize()
        {
            so = Indicators.StochasticOscillator(kPeriods, kSlowing, dPeriods, maType);
        }

        public override void Calculate(int index)
        {
            Percent_K[index] = so.PercentK[index];
            Percent_D[index] = so.PercentD[index];

//----------                                                                      K value is Stockastic value ( purple) , D is MA3 of it.
//-----------                                                                     if ( K is now < 90% and D < 90%  ) and  (the previous K >= 90%   or the Previous D is >= 90%)
//-----------                                                                     this is to get the position for the dot.
//UP LEVEL

            if ((Percent_K[index] < Up_Level && Percent_D[index] < Up_Level) && (Percent_K[index - 1] >= Up_Level || Percent_D[index - 1] >= Up_Level))
            {
                if (direction == 1)
                {
                    direction = 0;
                    Last_Up_Index = index;

                    Extremum_Index = index;
                    Extremum_Value = Up_Level;
                    Value[Extremum_Index] = Extremum_Value;

                    ChartObjects.DrawText("Direction " + index, "•", index, Up_Level, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);

                    double Low = MarketSeries.Low[Last_Down_Index];
                    double High = MarketSeries.High[Last_Up_Index];
                    double Trend_Value = (High - Low) / Symbol.TickSize;
                    string Dir = direction == 0 ? "▲" : "▼";
                    string Info = Dir + " " + Trend_Value.ToString("N0");

                    ChartObjects.DrawText("Info " + index, Info, index, Up_Level >= 50 ? Up_Level - 10 : Up_Level + 10, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);

                }

                if (direction == 0 && Extremum_Value == Up_Level)
                {
                    Last_Up_Index = index;
                    Value[Extremum_Index] = Double.NaN;
                    ChartObjects.RemoveObject("Info " + Extremum_Index);
                    Extremum_Index = index;
                    Extremum_Value = Up_Level;
                    Value[Extremum_Index] = Extremum_Value;

                    ChartObjects.DrawText("Direction " + index, "•", index, Up_Level, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);

                    double Low = MarketSeries.Low[Last_Down_Index];
                    double High = MarketSeries.High[Last_Up_Index];
                    double Trend_Value = (High - Low) / Symbol.TickSize;
                    string Dir = direction == 0 ? "▲" : "▼";
                    string Info = Dir + " " + Trend_Value.ToString("N0");
                    ChartObjects.DrawText("Info " + index, Info, index, Up_Level >= 50 ? Up_Level - 10 : Up_Level + 10, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);
                }
            }
//---------------------------------------------------------------------------------



            /// Down Level
            if ((Percent_K[index] > Down_Level && Percent_D[index] > Down_Level) && (Percent_K[index - 1] <= Down_Level || Percent_D[index - 1] <= Down_Level))
            {
                if (direction == 0)
                {
                    direction = 1;
                    Last_Down_Index = index;

                    Extremum_Index = index;
                    Extremum_Value = Down_Level;
                    Value[Extremum_Index] = Extremum_Value;

                    ChartObjects.DrawText("Direction " + index, "•", index, Down_Level, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);

                    double Low = MarketSeries.Low[Last_Down_Index];
                    double High = MarketSeries.High[Last_Up_Index];
                    double Trend_Value = (High - Low) / Symbol.TickSize;
                    string Dir = direction == 0 ? "▲" : "▼";
                    string Info = Dir + " " + Trend_Value.ToString("N0");
                    ChartObjects.DrawText("Info " + index, Info, index, Down_Level >= 50 ? Down_Level - 10 : Down_Level + 10, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);
                }

                if (direction == 1 && Extremum_Value == Down_Level)
                {
                    Last_Down_Index = index;
                    Value[Extremum_Index] = Double.NaN;
                    ChartObjects.RemoveObject("Info " + Extremum_Index);
                    Extremum_Index = index;
                    Extremum_Value = Down_Level;
                    Value[Extremum_Index] = Extremum_Value;

                    ChartObjects.DrawText("Direction " + index, "•", index, Down_Level, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);

                    double Low = MarketSeries.Low[Last_Down_Index];
                    double High = MarketSeries.High[Last_Up_Index];
                    double Trend_Value = (High - Low) / Symbol.TickSize;
                    string Dir = direction == 0 ? "▲" : "▼";
                    string Info = Dir + " " + Trend_Value.ToString("N0");
                    ChartObjects.DrawText("Info " + index, Info, index, Down_Level >= 50 ? Down_Level - 10 : Down_Level + 10, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Yellow);
                }

            }

            if (index - 1 != Extremum_Index)
            {
                Value[index - 1] = Double.NaN;
                Value[index] = Percent_D[index];
            }
        }
    }
}