Category Trend  Published on 16/12/2013

SwingHighLow

Description

I edited the indicator was in cTDN.
This is the indicator to display the rate of highs and lows.

The indicator of SwingHigh, please select the High source.
The indicator of SwingLow, please select the Low sources.

If you can, I would like to put a line on the rate of High Low ...

 

When it was English that hard to understand, I'm sorry ...

 


u

ST
st0424

Joined on 23.09.2013

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: SwingHighLow.algo
  • Rating: 5
  • Installs: 7869
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
CU
cuervo53 · 2 years ago

Hello. Excellent indicator. I would like to be able to print in the Registry of my Cbot the maximum and minimum values ​​that they calculate. I can't do it. Please help?

Hola. Excelente indicador. Me gustaría poder imprimir en el Registro de mi Cbot los valores máximos y mínimos que calculan. No logro hacerlo. ¿Ayuda por favor?

EM
emeeder1 · 5 years ago

The above has a couple corrections to the one EARL posted. It works.

But it could be cleaned up a bit and updated to newer API.

also, both high and low show in pink because red and green dont show well with my chart colors. You have to change colurs in the code with whatever color you prefer.

Maybe someone else want to modify that so color con be selected in settings.  The current selection for color in setting does not work.

But at least now it shows both highs and lows correctly

EM
emeeder1 · 5 years ago

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SwingHighLowText : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Period", DefaultValue = 13, MinValue = 3)]
        public int Period { get; set; }

        [Parameter("Scale Precision", DefaultValue = 5)]
        public int ScalePrecision { get; set; }

        [Parameter("Text Color", DefaultValue = "Pink")]
        public string TextColor { get; set; }



        private Colors color = Colors.White;
        private Colors colorSell = Colors.Pink;
        private Colors colorBuy = Colors.Pink;
        private string format;

        protected override void Initialize()
        {
            // Parse color from string, e.g. "Yellow", "Green", "Red". string must start with large letter, "Red" is valid, "red" - not.
            Enum.TryParse(TextColor, out color);

            // create string format based on scale precision, e.g "0.000" for scale precision = 3
            format = "0." + new string('0', ScalePrecision);

            UpdateLabels(true);
        }

        public override void Calculate(int index)
        {
            if (IsRealTime)
                UpdateLabels(false);
        }

        private void UpdateLabels(bool fastUpdate)
        {
            ChartObjects.RemoveAllObjects();

            int startIndex = fastUpdate ? Source.Count - 350 : 0;
            int index;
            int index2;

            index = Source.Count - 2;

            while (index >= startIndex)
            {
                if (IsLocalExtremum(index, true))
                {
                    ChartObjects.DrawText("max_" + index, Source[index].ToString(format), index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, colorSell);
                    index = index - Period;
                }
                else
                    index--;
            }
            index2 = Source.Count - 2;
            while (index2 >= startIndex)
            {
                if (IsLocalExtremumM(index2, true))
                {
                    ChartObjects.DrawText("min_" + index2, Source[index2].ToString(format), index2, Source[index2], VerticalAlignment.Bottom, HorizontalAlignment.Center, colorBuy);
                    index2 = index2 - Period;
                }
                else

                    index2--;
            }
            var lastIndex = Source.Count - 1;

        }

        private bool IsLocalExtremum(int index, bool findMax)
        {
            int end = Math.Min(index + Period, Source.Count - 1);
            int start = Math.Max(index - Period, 0);

            double value = Source[index];

            for (int i = start; i <= end; i++)
            {
                if (findMax && value < Source[i])
                    return false;

                if (!findMax && value > Source[i])
                    return false;
            }
            return true;
        }
        private bool IsLocalExtremumM(int index2, bool findMin)
        {
            int end = Math.Min(index2 + Period, Source.Count - 1);
            int start = Math.Max(index2 - Period, 0);

            double value = Source[index2];

            for (int i = start; i <= end; i++)
            {
                if (findMin && value > Source[i])
                    return false;

                if (!findMin && value < Source[i])
                    return false;
            }
            return true;
        }
    }
}

LE
leohermoso · 5 years ago

"hi

the low part is not working" 

Read the description 

 

"eu gostaria de saber como que coloca esse indicador com a posição de compra pois ele só marca como venda"

Leia a descricao companheiro

"The indicator of SwingHigh, please select the High source.
The indicator of SwingLow, please select the Low sources."

 

The programmer writes a really nice indicator and the user here is so lazy that can't even read the description.

VA
vanessaguillaume89 · 8 years ago

hi

the low part is not working

AU
Augustinas_Mk · 8 years ago

This SHOWS HIGHER AND LOWER MAX POSITIONS

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SwingHigh : Indicator
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Period", DefaultValue = 13, MinValue = 3)]
        public int Period { get; set; }

        [Parameter("Scale Precision", DefaultValue = 5)]
        public int ScalePrecision { get; set; }

        [Parameter("Text Color", DefaultValue = "Pink")]
        public string TextColor { get; set; }

        private Colors color = Colors.White;
        private Colors colorSell = Colors.Red;
        private Colors colorBuy = Colors.Green;
        private string format;

        protected override void Initialize()
        {
            // Parse color from string, e.g. "Yellow", "Green", "Red". string must start with large letter, "Red" is valid, "red" - not.
            Enum.TryParse(TextColor, out color);

            // create string format based on scale precision, e.g "0.000" for scale precision = 3
            format = "0." + new string('0', ScalePrecision);

            UpdateLabels(true);
        }

        public override void Calculate(int index)
        {
            if (IsRealTime)
                UpdateLabels(false);
        }

        private void UpdateLabels(bool fastUpdate)
        {
            ChartObjects.RemoveAllObjects();

            int startIndex = fastUpdate ? Source.Count - 350 : 0;
            int index;
            int index2;

            index = Source.Count - 2;

            while (index >= startIndex)
            {
                if (IsLocalExtremum(index, true))
                {
                    ChartObjects.DrawText("max_" + index, Source[index].ToString(format), index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, colorSell);
                    index = index - Period;
                }
                else
                    index--;
            }
            index2 = Source.Count - 2;
            while (index2 >= startIndex)
            {
                if (IsLocalExtremumM(index2, true))
                {
                    ChartObjects.DrawText("min_" + index2, Source[index2].ToString(format), index2, Source[index2], VerticalAlignment.Bottom, HorizontalAlignment.Center, colorBuy);
                    index2 = index2 - Period;
                }
                else

                    index2--;
            }
            var lastIndex = Source.Count - 1;

        }

        private bool IsLocalExtremum(int index, bool findMax)
        {
            int end = Math.Min(index + Period, Source.Count - 1);
            int start = Math.Max(index - Period, 0);

            double value = Source[index];

            for (int i = start; i <= end; i++)
            {
                if (findMax && value < Source[i])
                    return false;

                if (!findMax && value > Source[i])
                    return false;
            }
            return true;
        }
        private bool IsLocalExtremumM(int index2, bool findMin)
        {
            int start = Math.Min(index2 + Period, Source.Count - 1);
            int end = Math.Max(index2 - Period, 0);

            double value = Source[index2];

            for (int i = start; i <= end; i++)
            {
                if (findMin && value < Source[i])
                    return false;

                if (!findMin && value > Source[i])
                    return false;
            }
            return true;
        }
    }
}

ED
EDENEM · 8 years ago

I would like to have support for the swinghighlow indicator
if anyone know who please him the developer
Mende an e-mail to eletronica23@gmail.com
because it does not work for me as high as only low
someone please help me

I would like to have support for the indicator SwingLowHigh

I wonder how that puts this indicator with buying position, since only brand as sale
ie only from the top down but from the bottom up not score anything?

GK
gkbria46 · 8 years ago

Sorry, how do you get the low values ? it is not working any more for low source.

Is there any error on the code ? or willingly done so that normal user should not use this indicator any more !!!

 

 

ED
Edivaldo C Azevedo · 9 years ago

I would like to have support for the swinghighlow indicator
if anyone know who please him the developer
Mende an e-mail to eletronica23@gmail.com
because it does not work for me as high as only low
someone please help me

gostaria de ter suporte para o indicador swinghighlow
se alguém saber quem é do desenvolvedor  dele por favor 
mende um E-mail para eletronica23@gmail.com
porque ele não funciona para mim como alta só como baixa 
alguém por favor mim ajude 

ED
EDENEM · 9 years ago

I would like to know what support for indicator
swinghighlow cTrade.
in need of support for indicator
swinghighlow
if you know where and support please send me an email
eleletronica23@gmail.com

ED
EDENEM · 9 years ago

I wonder how that puts this indicator with buying position as it only marks as sale

ie only from the top down but from the bottom up it does not mark anything?

ED
EDENEM · 9 years ago

ola boa noite  

eu gostaria de saber como que coloca esse indicador com a posição de compra pois ele só marca como venda 

ou seja só de cima para baixo mas de baixo para cima ele não marca nada ?

TR
trknmt · 10 years ago

Hi, st0424,

I have been looking for this kind of indicator and am very happy to find it.

Can you kindly advise me how to modify the code in order to change the font type and size, I will like to make it "arial" and size in 6.

Thank you very much.