popup alert for indicator

Created at 02 Oct 2021, 14:45
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!
IR

IRCtrader

Joined 17.06.2021

popup alert for indicator
02 Oct 2021, 14:45


i download ctrader alert library(from release) and add cAlgo.API.Alert.dll and Prism.dll to my project from ctrader. i don;t use visual studio because i don't have visual studio.

i wrote below code to identify mad histogram cross zero level. but i didn't get any pop up notification.

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class AlertTest : Indicator
    {
        public MacdHistogram _Macd;

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

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

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

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

        public IndicatorDataSeries Macdup { get; set; }
        [Output("Macd", LineColor = "Red", Thickness = 2, PlotType = PlotType.Histogram)]

        public IndicatorDataSeries Macd { get; set; }

        protected override void Initialize()
        {
            _Macd = Indicators.MacdHistogram(Source, LongCycle1, ShortCycle1, inpSingal1);
        }

        public override void Calculate(int index)
        {
            Macd[index] = _Macd.Histogram[index];

            if (Macd[-1] <= 0 && Macd[0] >= 0)
            {
                Notifications.ShowPopup(Bars.TimeFrame, Symbol, "sell", "AlertTest Indicator", Symbol.Bid, "Macd crosses", Server.Time);
            }
        }
    }
}

 

 


@IRCtrader
Replies

amusleh
03 Oct 2021, 09:58

Hi,

You should reference all DLL files inside Release zip file you downloaded, then it will work.

I strongly recommend you to use Visual Studio and install the alert library via Nuget.

Visual Studio is free, you can download it from here: Visual Studio - Visual Studio (microsoft.com)


@amusleh

IRCtrader
05 Oct 2021, 07:11

RE:

amusleh said:

Hi,

You should reference all DLL files inside Release zip file you downloaded, then it will work.

I strongly recommend you to use Visual Studio and install the alert library via Nuget.

Visual Studio is free, you can download it from here: Visual Studio - Visual Studio (microsoft.com)

is my code correct?

i do this even with visual studio but i didn't get any notification.


@IRCtrader

amusleh
05 Oct 2021, 18:44

RE: RE:

khoshroomahdi said:

amusleh said:

Hi,

You should reference all DLL files inside Release zip file you downloaded, then it will work.

I strongly recommend you to use Visual Studio and install the alert library via Nuget.

Visual Studio is free, you can download it from here: Visual Studio - Visual Studio (microsoft.com)

is my code correct?

i do this even with visual studio but i didn't get any notification.

Hi,

Your code was correct, I tested and the popup showed up.

Check the cTrader automate logs tab, if your code calls the ShowPopup method and the popup didn't showed up then you most probably will see an error message on logs tab.


@amusleh

IRCtrader
06 Oct 2021, 17:03 ( Updated at: 06 Oct 2021, 17:34 )

finally i get pop up notification in ctrader but with sample code in Github..

with my code i didn't get any pop up yet.

i need help to complete MACD alert indicator.

if you could give me a sample how cross over histogram with zero lever or cross signal line with histogram i could complete this indicator. and after that i could complete other alert indicator for community.

thank in advance


@IRCtrader

IRCtrader
06 Oct 2021, 18:03 ( Updated at: 06 Oct 2021, 18:26 )

using cAlgo.API;
using cAlgo.API.Alert;
using System;
using cAlgo.API.Alert.Utility;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class AlertTest : Indicator
    {
        public MacdHistogram _Macd;

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

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

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

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

        public IndicatorDataSeries Macdup { get; set; }
        [Output("Macd", LineColor = "Red", Thickness = 2, PlotType = PlotType.Histogram)]

        public IndicatorDataSeries Macd { get; set; }

        protected override void Initialize()
        {
            _Macd = Indicators.MacdHistogram(Source, LongCycle1, ShortCycle1, inpSingal1);
        }


        public override void Calculate(int index)
        {

            Macd[index] = _Macd.Histogram[index];
            if (_Macd.Histogram.Last(1) > 0 && _Macd.Histogram.Last(2) <= 0)
            {
                Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, TradeType.Buy, "AcademyWave.com", Symbol.Bid, "Macd cross Above zero", Server.Time);
            }

            if (_Macd.Histogram.Last(1) < 0 && _Macd.Histogram.Last(2) >= 0)
            {
                Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, TradeType.Sell, "AcademyWave.com", Symbol.Bid, "Macd cross Below zero", Server.Time);
            }
        }
    }
}

i write this code. but it has lag and show many pop ups.

how could i use close indicator data. not last value.


@IRCtrader

amusleh
07 Oct 2021, 19:56

Ho,

Try this:

using cAlgo.API;
using cAlgo.API.Alert;
using System;
using cAlgo.API.Alert.Utility;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class AlertTest : Indicator
    {
        public MacdHistogram _Macd;
        
        private int _lastAlertBar;

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

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

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

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

        public IndicatorDataSeries Macdup { get; set; }
        [Output("Macd", LineColor = "Red", Thickness = 2, PlotType = PlotType.Histogram)]

        public IndicatorDataSeries Macd { get; set; }

        protected override void Initialize()
        {
            _Macd = Indicators.MacdHistogram(Source, LongCycle1, ShortCycle1, inpSingal1);
        }


        public override void Calculate(int index)
        {

            Macd[index] = _Macd.Histogram[index];
            
            if (index == _lastAlertBar) return;
            
            _lastAlertBar = index;
            
            if (_Macd.Histogram[index - 1] > 0 && _Macd.Histogram[index - 2] <= 0)
            {
                Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, TradeType.Buy, "AcademyWave.com", Symbol.Bid, "Macd cross Above zero", Server.Time);
            }

            if (_Macd.Histogram[index - 1] < 0 && _Macd.Histogram[index - 2] >= 0)
            {
                Notifications.ShowPopup(MarketSeries.TimeFrame, Symbol, TradeType.Sell, "AcademyWave.com", Symbol.Bid, "Macd cross Below zero", Server.Time);
            }
        }
    }
}

It uses the last closed bar MACD value not the current open bar.


@amusleh

IRCtrader
08 Oct 2021, 10:40 ( Updated at: 21 Dec 2023, 09:22 )

ctrader crashed

tanks for your help

but now when i add this indicator to ctrader. when it want shows pop up trader crash.


@IRCtrader

amusleh
09 Oct 2021, 08:41

RE: ctrader crashed

Hi,

Something is wrong with alert XML configuration files, it located at cAlgo folder.

There is an Alerts folder inside cAlgo folder, delete it and retry.

Also please copy and post the full log of exception so I will be able to find the exact issue.


@amusleh