RSI with Sound

Created at 29 Mar 2021, 16:46
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!
RO

ronnjinn

Joined 05.10.2020

RSI with Sound
29 Mar 2021, 16:46


I coded rsi with sound indicator but it doesn't work. My code is below. Please someone help.

 

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

namespace cAlgo
{
    [Levels(30, 65)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class RSISound : Indicator
    {
        // Condition for sound alert
        bool AlertFlag = false;


        [Parameter("Sound ON", DefaultValue = 1, MaxValue = 1, MinValue = 0)]
        public bool PlaySound { get; set; }

        [Parameter("Media File", DefaultValue = "C:\\windows\\media\\Alarm02.mp3")]
        public string MediaFile { get; set; }

        [Parameter("Source", Group = "RSI")]
        public DataSeries Source { get; set; }

        [Parameter("Period", Group = "RSI", DefaultValue = 14)]
        public int Period { get; set; }

        [Parameter(DefaultValue = 65)]
        public int MaxLevel { get; set; }

        [Parameter(DefaultValue = 30)]
        public int MinLevel { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private RelativeStrengthIndex rsi;


        protected override void Initialize()
        {
            // Initialize and create nested indicators
            rsi = Indicators.RelativeStrengthIndex(Source, Period);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
            Result[index] = rsi.Result[index];

            if (rsi.Result.Last(2) < MaxLevel && rsi.Result.Last(1) > MaxLevel)
            {
                if (AlertFlag == false)
                {
                    // Alert
                    Notifications.PlaySound(MediaFile);
                    // Flag
                    AlertFlag = true;
                }
            }
            else if (rsi.Result.Last(2) > MinLevel && rsi.Result.Last(1) < MinLevel)
            {
                if (AlertFlag == false)
                {
                    // Alert
                    Notifications.PlaySound(MediaFile);
                    // Flag
                    AlertFlag = true;
                }
            }
            else
            {
                AlertFlag = false;
            }
        }
    }
}

 


@ronnjinn
Replies

ronnjinn
29 Mar 2021, 19:07

Sorry, it works! Could you please close this thread?


@ronnjinn