Category Trend  Published on 27/06/2015

Indicate the crossing betwin two moving

Description

indicator print buy/sell signal on the price graph windows when the fast line cross the slow line

Author : Abdallah HACID

Solution Visual studio


#region Licence
//The MIT License (MIT)
//Copyright (c) 2014 abdallah HACID, https://www.facebook.com/ab.hacid

//Permission is hereby granted, free of charge, to any person obtaining a copy of this software
//and associated documentation files (the "Software"), to deal in the Software without restriction,
//including without limitation the rights to use, copy, modify, merge, publish, distribute,
//sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
//is furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all copies or
//substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Project Hosting for Open Source Software on Codeplex : https://calgobots.codeplex.com/
#endregion

#region Indicator Infos
// This indicator print buy/sell signal on the price graph windows when the fast line cross the slow line
#endregion

#region Indicator Parameters Comments
// -------------------------------------------------------------------------------
//	
//			Symbol				=	All
//			TimeFrame			=	prefere h4
//
//
// -------------------------------------------------------------------------------

#endregion


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

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

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

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

        [Output("slowMa", Thickness = 2, Color = Colors.DeepSkyBlue)]
        public IndicatorDataSeries SlowMAResult { get; set; }

        [Output("fastMA", Thickness = 2, Color = Colors.Green)]
        public IndicatorDataSeries FastMAResult { get; set; }

        private string upArrow = "▲";
        private string downArrow = "▼";
        private double arrowOffset;

        MovingAverage slowMA;
        MovingAverage fastMA;
        protected override void Initialize()
        {
            fastMA = Indicators.MovingAverage(MarketSeries.Close, fastPeriod, MaType);
            slowMA = Indicators.MovingAverage(MarketSeries.Close, SlowPeriod, MaType);

            arrowOffset = Symbol.PipSize * 5;

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

            double high = MarketSeries.High[index];
            double low = MarketSeries.Low[index];

            if (isCrossAbove())
                ChartObjects.DrawText(string.Format("Buy {0}", index), upArrow, index - 1, low - arrowOffset, VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Green);

            if (isCrossBelow())
                ChartObjects.DrawText(string.Format("Sell {0}", index), downArrow, index - 1, high + arrowOffset, VerticalAlignment.Top, HorizontalAlignment.Center, Colors.Red);
        }

        #region Predicate
        public bool isCrossAbove()
        {
            return FastMAResult.HasCrossedAbove(SlowMAResult, 0);
        }
        public bool isCrossBelow()
        {
            return FastMAResult.HasCrossedBelow(SlowMAResult, 0);
        }
        #endregion

    }
}


AY
aysos75

Joined on 28.09.2013

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: FastCrossSlow.algo
  • Rating: 4.38
  • Installs: 8754
Comments
Log in to add a comment.
AL
alex.kun.sosa · 1 year ago

Hello, How could I add the displacement to the emas? for example I would like to take the slow ema with shift -3 Thank you

SE
sejdinimarkelian · 3 years ago

it does work very great , combine this with volum indicators, great

AZ
Azon · 4 years ago

Hello, one more vote for add window and sound alert! Thank you!

TE
tekASH · 5 years ago

Hey mate, thanks for this indicator. Can you add Alert function to this? A small window notification with sound when cross happens, would be great ;)

Disnalevel's avatar
Disnalevel · 8 years ago

In cAlgo there's a cBot called sample trend cBot, you can use the settings of this indicator for the cBot setting,

SH
sheepsky · 8 years ago

is there a bot with this indicator would be a good idea :)

SH
sheepsky · 8 years ago

did anyone try this in 1H ?  I use it in 1H and the results are good but anyone else

Spotware's avatar
Spotware · 9 years ago

You don't need to build it, just install it by double clicking on the downloaded file.

JB
jb1981 · 9 years ago

Indicator doesn't work "Error : Project C:\Users\Admin\Documents\cAlgo\Sources\Library\cAlgoLib\cAlgo.Lib.csproj doesn't exist."