set alarm for Set the alarm for when the four Ichimoku components are equal

Created at 14 Apr 2022, 08:13
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
SA

safaeianmohsen

Joined 14.04.2022

set alarm for Set the alarm for when the four Ichimoku components are equal
14 Apr 2022, 08:13


hi

can you help me ? 

i want to set alarm for ichimoku defaul indicator when : 4 Ichimoku components are equal . I want to give me  alarm in the live bar ( candle ).

sourse code is below :

using System;

using cAlgo.API;

using cAlgo.API.Indicators;

 

namespace cAlgo.Indicators

{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]

    public class IchimokuKinkoHyo : Indicator

    {

        [Parameter(DefaultValue = 9)]

        public int periodFast { get; set; }

 

        [Parameter(DefaultValue = 26)]

        public int periodMedium { get; set; }

 

        [Parameter(DefaultValue = 52)]

        public int periodSlow { get; set; }

 

        [Parameter(DefaultValue = 26)]

        public int DisplacementChikou { get; set; }

         

        [Parameter(DefaultValue = 26)]

        public int DisplacementCloud { get; set; }

 

        [Output("TenkanSen", Color = Colors.Red)]

        public IndicatorDataSeries TenkanSen { get; set; }

        [Output("Kijunsen", Color = Colors.Blue)]

        public IndicatorDataSeries KijunSen { get; set; }

        [Output("ChikouSpan", Color = Colors.DarkViolet)]

        public IndicatorDataSeries ChikouSpan { get; set; }

 

        [Output("SenkouSpanB", Color = Colors.Red, LineStyle=LineStyle.Lines)]

        public IndicatorDataSeries SenkouSpanB { get; set; }

        [Output("SenkouSpanA", Color = Colors.Green,LineStyle=LineStyle.Lines)]

        public IndicatorDataSeries SenkouSpanA { get; set; }

 

        double maxfast,minfast,maxmedium,minmedium,maxslow,minslow;

 

        public override void Calculate(int index)

        {

            if((index<periodFast)||(index<periodSlow)){return;}

             

            maxfast = MarketSeries.High[index];

            minfast = MarketSeries.Low[index];

            maxmedium = MarketSeries.High[index];

            minmedium = MarketSeries.Low[index];

            maxslow = MarketSeries.High[index];

            minslow = MarketSeries.Low[index];

             

            for(int i=0;i<periodFast;i++)

            {

                if(maxfast< MarketSeries.High[index-i]){maxfast = MarketSeries.High[index-i];}

                if(minfast> MarketSeries.Low[index-i]){minfast = MarketSeries.Low[index-i];}

            }

            for(int i=0;i<periodMedium;i++)

            {

                if(maxmedium< MarketSeries.High[index-i]){maxmedium = MarketSeries.High[index-i];}

                if(minmedium> MarketSeries.Low[index-i]){minmedium = MarketSeries.Low[index-i];}

            }

            for(int i=0;i<periodSlow;i++)

            {

                if(maxslow< MarketSeries.High[index-i]){maxslow = MarketSeries.High[index-i];}

                if(minslow> MarketSeries.Low[index-i]){minslow = MarketSeries.Low[index-i];}

            }

            TenkanSen[index] = (maxfast + minfast) /2;

            KijunSen[index] = (maxmedium + minmedium) /2;

            ChikouSpan[index-DisplacementChikou] = MarketSeries.Close[index];

             

            SenkouSpanA[index+DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2;

            SenkouSpanB[index+DisplacementCloud] = (maxslow + minslow) / 2;

        }

    }

}


@safaeianmohsen
Replies

amusleh
14 Apr 2022, 09:34

Hi,

What do you mean by "4 Ichimoku components are equal"?

Can you put a comment on your code where you want to get alerted?

What kind of alert you need? sound? email?

And please use code post option next time:

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

namespace cAlgo.Indicators

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

    {
        [Parameter(DefaultValue = 9)]
        public int periodFast { get; set; }

        [Parameter(DefaultValue = 26)]
        public int periodMedium { get; set; }

        [Parameter(DefaultValue = 52)]
        public int periodSlow { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementChikou { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementCloud { get; set; }

        [Output("TenkanSen", Color = Colors.Red)]
        public IndicatorDataSeries TenkanSen { get; set; }

        [Output("Kijunsen", Color = Colors.Blue)]
        public IndicatorDataSeries KijunSen { get; set; }

        [Output("ChikouSpan", Color = Colors.DarkViolet)]
        public IndicatorDataSeries ChikouSpan { get; set; }

        [Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanB { get; set; }

        [Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanA { get; set; }

        private double maxfast, minfast, maxmedium, minmedium, maxslow, minslow;

        public override void Calculate(int index)

        {
            if ((index < periodFast) || (index < periodSlow)) { return; }

            maxfast = MarketSeries.High[index];

            minfast = MarketSeries.Low[index];

            maxmedium = MarketSeries.High[index];

            minmedium = MarketSeries.Low[index];

            maxslow = MarketSeries.High[index];

            minslow = MarketSeries.Low[index];

            for (int i = 0; i < periodFast; i++)

            {
                if (maxfast < MarketSeries.High[index - i]) { maxfast = MarketSeries.High[index - i]; }

                if (minfast > MarketSeries.Low[index - i]) { minfast = MarketSeries.Low[index - i]; }
            }

            for (int i = 0; i < periodMedium; i++)

            {
                if (maxmedium < MarketSeries.High[index - i]) { maxmedium = MarketSeries.High[index - i]; }

                if (minmedium > MarketSeries.Low[index - i]) { minmedium = MarketSeries.Low[index - i]; }
            }

            for (int i = 0; i < periodSlow; i++)

            {
                if (maxslow < MarketSeries.High[index - i]) { maxslow = MarketSeries.High[index - i]; }

                if (minslow > MarketSeries.Low[index - i]) { minslow = MarketSeries.Low[index - i]; }
            }

            TenkanSen[index] = (maxfast + minfast) / 2;

            KijunSen[index] = (maxmedium + minmedium) / 2;

            ChikouSpan[index - DisplacementChikou] = MarketSeries.Close[index];

            SenkouSpanA[index + DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2;

            SenkouSpanB[index + DisplacementCloud] = (maxslow + minslow) / 2;
        }
    }
}

 


@amusleh

safaeianmohsen
14 Apr 2022, 10:02 ( Updated at: 21 Dec 2023, 09:22 )

RE: cod post option 37939

amusleh said:hi 1-Equivalence of 4 components means when Tenkansen and Kijunsen and each span a, b are exactly equal in quantity.  

2- I have marked the desired point in the image.

  3-I want to have sound alert .

Hi,

What do you mean by "4 Ichimoku components are equal"?

Can you put a comment on your code where you want to get alerted?

What kind of alert you need? sound? email?

And please use code post option next time:

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

namespace cAlgo.Indicators

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

    {
        [Parameter(DefaultValue = 9)]
        public int periodFast { get; set; }

        [Parameter(DefaultValue = 26)]
        public int periodMedium { get; set; }

        [Parameter(DefaultValue = 52)]
        public int periodSlow { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementChikou { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementCloud { get; set; }

        [Output("TenkanSen", Color = Colors.Red)]
        public IndicatorDataSeries TenkanSen { get; set; }

        [Output("Kijunsen", Color = Colors.Blue)]
        public IndicatorDataSeries KijunSen { get; set; }

        [Output("ChikouSpan", Color = Colors.DarkViolet)]
        public IndicatorDataSeries ChikouSpan { get; set; }

        [Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanB { get; set; }

        [Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanA { get; set; }

        private double maxfast, minfast, maxmedium, minmedium, maxslow, minslow;

        public override void Calculate(int index)

        {
            if ((index < periodFast) || (index < periodSlow)) { return; }

            maxfast = MarketSeries.High[index];

            minfast = MarketSeries.Low[index];

            maxmedium = MarketSeries.High[index];

            minmedium = MarketSeries.Low[index];

            maxslow = MarketSeries.High[index];

            minslow = MarketSeries.Low[index];

            for (int i = 0; i < periodFast; i++)

            {
                if (maxfast < MarketSeries.High[index - i]) { maxfast = MarketSeries.High[index - i]; }

                if (minfast > MarketSeries.Low[index - i]) { minfast = MarketSeries.Low[index - i]; }
            }

            for (int i = 0; i < periodMedium; i++)

            {
                if (maxmedium < MarketSeries.High[index - i]) { maxmedium = MarketSeries.High[index - i]; }

                if (minmedium > MarketSeries.Low[index - i]) { minmedium = MarketSeries.Low[index - i]; }
            }

            for (int i = 0; i < periodSlow; i++)

            {
                if (maxslow < MarketSeries.High[index - i]) { maxslow = MarketSeries.High[index - i]; }

                if (minslow > MarketSeries.Low[index - i]) { minslow = MarketSeries.Low[index - i]; }
            }

            TenkanSen[index] = (maxfast + minfast) / 2;

            KijunSen[index] = (maxmedium + minmedium) / 2;

            ChikouSpan[index - DisplacementChikou] = MarketSeries.Close[index];

            SenkouSpanA[index + DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2;

            SenkouSpanB[index + DisplacementCloud] = (maxslow + minslow) / 2;
        }
    }
}

 

 


@safaeianmohsen

amusleh
14 Apr 2022, 11:12

Hi,

It would be very rare for all of them to be exactly equal, you have to use some kind of threshold.

Here is the code with alert:

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

namespace cAlgo.Indicators

{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.FullAccess)]
    public class IchimokuKinkoHyo : Indicator

    {
        [Parameter(DefaultValue = 9)]
        public int periodFast { get; set; }

        [Parameter(DefaultValue = 26)]
        public int periodMedium { get; set; }

        [Parameter(DefaultValue = 52)]
        public int periodSlow { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementChikou { get; set; }

        [Parameter(DefaultValue = 26)]
        public int DisplacementCloud { get; set; }

        [Parameter("Threshold (Pips)", DefaultValue = 1, MinValue = 0, Group = "Alert")]
        public double AlertThreshold { get; set; }

        [Parameter("Sound File Path", Group = "Alert")]
        public string AlertSoundFile { get; set; }

        [Output("TenkanSen", Color = Colors.Red)]
        public IndicatorDataSeries TenkanSen { get; set; }

        [Output("Kijunsen", Color = Colors.Blue)]
        public IndicatorDataSeries KijunSen { get; set; }

        [Output("ChikouSpan", Color = Colors.DarkViolet)]
        public IndicatorDataSeries ChikouSpan { get; set; }

        [Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanB { get; set; }

        [Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanA { get; set; }

        private double maxfast, minfast, maxmedium, minmedium, maxslow, minslow;

        protected override void Initialize()
        {
            AlertThreshold *= Symbol.PipSize;
        }

        public override void Calculate(int index)

        {
            if ((index < periodFast) || (index < periodSlow)) { return; }

            maxfast = MarketSeries.High[index];

            minfast = MarketSeries.Low[index];

            maxmedium = MarketSeries.High[index];

            minmedium = MarketSeries.Low[index];

            maxslow = MarketSeries.High[index];

            minslow = MarketSeries.Low[index];

            for (int i = 0; i < periodFast; i++)

            {
                if (maxfast < MarketSeries.High[index - i]) { maxfast = MarketSeries.High[index - i]; }

                if (minfast > MarketSeries.Low[index - i]) { minfast = MarketSeries.Low[index - i]; }
            }

            for (int i = 0; i < periodMedium; i++)

            {
                if (maxmedium < MarketSeries.High[index - i]) { maxmedium = MarketSeries.High[index - i]; }

                if (minmedium > MarketSeries.Low[index - i]) { minmedium = MarketSeries.Low[index - i]; }
            }

            for (int i = 0; i < periodSlow; i++)

            {
                if (maxslow < MarketSeries.High[index - i]) { maxslow = MarketSeries.High[index - i]; }

                if (minslow > MarketSeries.Low[index - i]) { minslow = MarketSeries.Low[index - i]; }
            }

            TenkanSen[index] = (maxfast + minfast) / 2;

            KijunSen[index] = (maxmedium + minmedium) / 2;

            ChikouSpan[index - DisplacementChikou] = MarketSeries.Close[index];

            SenkouSpanA[index + DisplacementCloud] = (TenkanSen[index] + KijunSen[index]) / 2;

            SenkouSpanB[index + DisplacementCloud] = (maxslow + minslow) / 2;

            if (IsLastBar && Math.Abs(TenkanSen[index] - KijunSen[index]) <= AlertThreshold && Math.Abs(KijunSen[index] - SenkouSpanA[index]) <= AlertThreshold && Math.Abs(SenkouSpanA[index] - SenkouSpanB[index]) <= AlertThreshold)
            {
                Notifications.PlaySound(AlertSoundFile);
            }
        }
    }
}

Changed the threshold to 0 if you want to get alerted only if they were exactly equal, otherwise set some few pips as your tolerance level.

The values of them are in double, 99.99% of the time they will not be exactly equal as some decimal place might have different value.


@amusleh