Adding a Crossover alert

Created at 27 Nov 2018, 11:08
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!
JJ

jjcolacicco

Joined 08.08.2018

Adding a Crossover alert
27 Nov 2018, 11:08


Hello all.

I downloaded a Macd Indicator from this forum a couple of weeks ago which is visually great to work with but it would be so much better if it had a pop up box when the centre line is crossed by the histogram.  I have looked at many posts here but it is beyond me on how i would code it.  Is there anyone here that could add the allert for me?  

The code i am using for the macd is this below.

Thanks in advance.

 

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

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

        public MacdHistogram MacdHistogram;

        [Parameter()]

        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        [Parameter("Signal Periods", DefaultValue = 9)]
        public int Periods { get; set; }


        [Output("Histogram > 0", PlotType = PlotType.Histogram, Color = Colors.Green, Thickness = 2)]
        public IndicatorDataSeries HistogramPositive { get; set; }


        [Output("Histogram < 0", PlotType = PlotType.Histogram, Color = Colors.Red, Thickness = 2)]
        public IndicatorDataSeries HistogramNegative { get; set; }

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

        protected override void Initialize()
        {

            MacdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
        }

        public override void Calculate(int index)
        {

            if (MacdHistogram.Histogram[index] > 0)
            {
                HistogramPositive[index] = MacdHistogram.Histogram[index];
            }

            if (MacdHistogram.Histogram[index] < 0)
            {
                HistogramNegative[index] = MacdHistogram.Histogram[index];
            }

            Signal[index] = MacdHistogram.Signal[index];
        }
    }
}


@jjcolacicco
Replies

afhacker
27 Nov 2018, 13:30

Try my alert popup window library, you can add popup, sound, email, and telegram alert on your indicator/cBot with just one line of code!

https://ctrader.com/algos/indicators/show/1692

Check the documentation for full example.


@afhacker

jjcolacicco
27 Nov 2018, 13:43

Thanks for the Link and the hard work.  I am assuming that i need to follow the directions posted on the October 14, 2018 @ 08:36

 


@jjcolacicco

afhacker
27 Nov 2018, 14:01

First install the library by following this instruction: https://github.com/afhacker/ctrader-alert_popup/wiki/Installation

Then for showing popup follow this instruction: https://github.com/afhacker/ctrader-alert_popup/wiki/Show-Popup

Don't forget to set your indicator access rights to full access otherwise, it will not work.


@afhacker

jjcolacicco
27 Nov 2018, 15:49

RE:

afhacker said:

First install the library by following this instruction: https://github.com/afhacker/ctrader-alert_popup/wiki/Installation

Then for showing popup follow this instruction: https://github.com/afhacker/ctrader-alert_popup/wiki/Show-Popup

Don't forget to set your indicator access rights to full access otherwise, it will not work.

I think i am missing something.  i have downloaded and installed the Visual editor so i am ready to go with that but i can not find the download for the indicator at your link, https://github.com/afhacker/ctrader-alert_popup/wiki/Installation

Do i need to sign up to GitHub to see the library you mention?

 


@jjcolacicco

afhacker
27 Nov 2018, 15:54

RE: RE:

jjcolacicco said:

afhacker said:

First install the library by following this instruction: https://github.com/afhacker/ctrader-alert_popup/wiki/Installation

Then for showing popup follow this instruction: https://github.com/afhacker/ctrader-alert_popup/wiki/Show-Popup

Don't forget to set your indicator access rights to full access otherwise, it will not work.

I think i am missing something.  i have downloaded and installed the Visual editor so i am ready to go with that but i can not find the download for the indicator at your link, https://github.com/afhacker/ctrader-alert_popup/wiki/Installation

Do i need to sign up to GitHub to see the library you mention?

 

Did you installed the library too? I have written two installation method which one you followed? Nuget or manual?


@afhacker

jjcolacicco
27 Nov 2018, 16:00

Did you installed the library too?  This is what I am not seeing.  Where is the libruary?  I will follow the Nuget method once i have managed to download the libruary.


@jjcolacicco

afhacker
27 Nov 2018, 17:20

The library is available in Nuget, you can install it via Nuget package manager or console.

If you don't have Visual Studio you can download the library from Google Drive link and reference it manually via cTrader reference manager.

Did you read the installation instruction?


@afhacker

jjcolacicco
27 Nov 2018, 18:54

This is all a little beyone me...  I have downloaded the file at Nuget 18.68kb but i dont think i have the correct extension to install it with visual studio.  I then Tried the Google drive but i do not see the indicator there just a load of Dill files. 

I will keep trying but i am missing something.  Coding is not my thing...

Thanks for your help today though.

 

 


@jjcolacicco

afhacker
27 Nov 2018, 19:32

I made the indicator.

Download the compiled ".algo" file from here: https://drive.google.com/open?id=1hImBUaSvwPiUQOEmm0BRk9OtvcRPOQmR

Install the indicator file on your cTrader, once it successfully installed check your custom indicators for "MACD Histogram Alert"

The indicator code:

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class MacdHistogramAlert : Indicator
    {
        #region Fields

        private MacdHistogram _macdHistogram;

        private int _lastAlertBarIndex;

        #endregion Fields

        #region Parameters

        [Parameter()]
        public DataSeries Source { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        [Parameter("Signal Periods", DefaultValue = 9)]
        public int Periods { get; set; }

        #endregion Parameters

        #region Outputs

        [Output("Histogram > 0", PlotType = PlotType.Histogram, Color = Colors.Green, Thickness = 2)]
        public IndicatorDataSeries HistogramPositive { get; set; }

        [Output("Histogram < 0", PlotType = PlotType.Histogram, Color = Colors.Red, Thickness = 2)]
        public IndicatorDataSeries HistogramNegative { get; set; }

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

        #endregion Outputs

        #region Methods

        protected override void Initialize()
        {
            _macdHistogram = Indicators.MacdHistogram(Source, LongCycle, ShortCycle, Periods);
        }

        public override void Calculate(int index)
        {
            if (_macdHistogram.Histogram[index] > 0)
            {
                HistogramPositive[index] = _macdHistogram.Histogram[index];
            }

            if (_macdHistogram.Histogram[index] < 0)
            {
                HistogramNegative[index] = _macdHistogram.Histogram[index];
            }

            Signal[index] = _macdHistogram.Signal[index];

            if (_macdHistogram.Histogram[index - 2] <= 0 && _macdHistogram.Histogram[index - 1] > 0)
            {
                TriggerAlert(TradeType.Buy, index);
            }
            else if (_macdHistogram.Histogram[index - 2] >= 0 && _macdHistogram.Histogram[index - 1] < 0)
            {
                TriggerAlert(TradeType.Sell, index);
            }
        }

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

            string comment = tradeType == TradeType.Buy ? "Histogram is above 0" : "Histogram is below 0";

            Notifications.ShowPopup(TimeFrame, Symbol, MarketSeries.Close[index], "MACD Histogram Alert", tradeType, comment);
        }

        #endregion Methods
    }
}

 


@afhacker

jjcolacicco
27 Nov 2018, 23:20

Sorry for the late reply but thanks so much for the indiator  i will have it st up for open tomorow morning

 

Thanks again

James


@jjcolacicco

jjcolacicco
29 Nov 2018, 12:17

Yesterday worked a treat.  thanks for this indicator.


@jjcolacicco