Category Trend  Published on 25/10/2022

Two moving average crossover with Sound

Description

This is a simple Indicator based on two Moving Averages, base on Close Price 

when two moving average crossover the sound you selected will be played and uparrow/downarrow  icons displayed


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


namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TwoMovingCross : Indicator
    {
		[Parameter("MA Type", DefaultValue=6)]
		public MovingAverageType MaType { get; set; }

		[Parameter("Slow Period", DefaultValue = 60, MinValue = 1)]
		public int SlowPeriod { get; set; }

		[Parameter("Fast Period", DefaultValue = 30, MinValue = 1)]
		public int FastPeriod { get; set; }

		[Output("SlowMA",Thickness=2,LineColor ="Purple")]
        public IndicatorDataSeries SlowMAResult { get; set; }

		[Output("FastMA",Thickness=1,LineColor="Aqua")]
        public IndicatorDataSeries FastMAResult { get; set; }
        
        [Parameter("Play sound", DefaultValue="False")]
        public bool Playsound { get; set; }
        
        [Parameter("Sound Path", DefaultValue=@"C:\Windows\Media\notify.wav")]
        public string SoundPath { get; set; }

		MovingAverage slowMA;
		MovingAverage fastMA;
		private double arrowOffset;
		private int Cup=0;
		private int Cdown=0;
		
		protected override void Initialize()
		{
			fastMA = Indicators.MovingAverage(Bars.ClosePrices, FastPeriod, MaType);
			slowMA = Indicators.MovingAverage(Bars.ClosePrices, SlowPeriod, MaType);
			arrowOffset = Symbol.PipSize * 5;

		}
		public override void Calculate(int index)
        {
			FastMAResult[index] = fastMA.Result[index];
			SlowMAResult[index] = slowMA.Result[index];

			if(Functions.HasCrossedAbove(fastMA.Result, slowMA.Result, 0)){
		        Chart.DrawIcon("HasCrossedAbove",ChartIconType.UpTriangle,Bars[index].OpenTime,Bars[index].Low-arrowOffset,Color.GreenYellow);
				
				if (Playsound && Cup<2 ){
				    Notifications.PlaySound(SoundPath);
				    Cup++;
				    Cdown=0;
				    }
				
				}

			if (Functions.HasCrossedBelow(fastMA.Result, slowMA.Result, 0)){
			    
                Chart.DrawIcon("HasCrossedBelow",ChartIconType.DownTriangle,Bars[index].OpenTime,Bars[index].High+arrowOffset,Color.DarkRed);
				
                if (Playsound && Cdown<2 ){
                    Notifications.PlaySound(SoundPath);
                    Cdown++;
                    Cup=0;
                   
                    }
				
				}
		}

		

	}
}


MA
ma.norouzifar

Joined on 12.09.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: TwoMovingCross.algo
  • Rating: 0
  • Installs: 1524
  • Modified: 25/10/2022 09:05
Comments
Log in to add a comment.
mirk0's avatar
mirk0 · 1 year ago

I tried to compile this as is and it gives 207 errors and 3800 warnings?