Please Help how to craete fractals indicator with alarm.

Created at 08 Mar 2019, 17:44
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!
afrimqahili1's avatar

afrimqahili1

Joined 08.03.2019

Please Help how to craete fractals indicator with alarm.
08 Mar 2019, 17:44


Hi.

Can help me some body to create fractals indicator with alarm , when show icon ( Fractals ) on chart shuld  be notified  becouse is very important.​

 

Best Regards

Afrim Qahili


@afrimqahili1
Replies

PanagiotisCharalampous
12 Mar 2019, 11:25

Hi Afrim,

If you need professional assistance, you can post a Job or contact a Consultant.

Best Regards,

Panagiotis


@PanagiotisCharalampous

afhacker
12 Mar 2019, 12:04

Fractals indicator with Alert

Here is the Fractals indicator which I implemented my alert library on it: https://drive.google.com/open?id=11btllj6A4-HV04SEDKvofvdA7F3Cy9YD

using cAlgo.API;
using cAlgo.API.Alert;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.FullAccess)]
    public class Fractals : Indicator
    {
        #region Fields

        private int _lastAlertBar;

        #endregion Fields

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

        [Parameter("Alert", DefaultValue = true)]
        public bool Alert { get; set; }

        [Output("Up Fractal", Color = Colors.Red, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries UpFractal { get; set; }

        [Output("Down Fractal", Color = Colors.Blue, PlotType = PlotType.Points, Thickness = 5)]
        public IndicatorDataSeries DownFractal { get; set; }

        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            DrawUpFractal(index);
            DrawDownFractal(index);

            cAlgo.API.Alert.Models.Configuration.Current.Tracer = Print;
        }

        private void DrawUpFractal(int index)
        {
            int period = Period % 2 == 0 ? Period - 1 : Period;
            int middleIndex = index - period / 2;
            double middleValue = MarketSeries.High[middleIndex];

            bool up = true;

            for (int i = 0; i < period; i++)
            {
                if (middleValue < MarketSeries.High[index - i])
                {
                    up = false;
                    break;
                }
            }
            if (up)
            {
                UpFractal[middleIndex] = middleValue;

                TriggerAlert(index, TradeType.Sell);
            }
        }

        private void DrawDownFractal(int index)
        {
            int period = Period % 2 == 0 ? Period - 1 : Period;
            int middleIndex = index - period / 2;
            double middleValue = MarketSeries.Low[middleIndex];
            bool down = true;

            for (int i = 0; i < period; i++)
            {
                if (middleValue > MarketSeries.Low[index - i])
                {
                    down = false;
                    break;
                }
            }
            if (down)
            {
                DownFractal[middleIndex] = middleValue;

                TriggerAlert(index, TradeType.Buy);
            }
        }

        private void TriggerAlert(int index, TradeType tradeType)
        {
            if (!IsLastBar || index == _lastAlertBar || !Alert)
            {
                return;
            }

            _lastAlertBar = index;

            string comment = tradeType == TradeType.Buy ? "Up" : "Down";

            Notifications.ShowPopup(TimeFrame, Symbol, tradeType, "Fractals");
        }
    }
}

The code isn't written by me, I just added the alerting part.


@afhacker