Indicate the crossing betwin two moving

by abdalah hacid in category Trend at 08/08/2014
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

Download
4736 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
#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

    }
}
Comments

jb1981 - March 21, 2015 @ 14:56

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

Spotware Team - March 27, 2015 @ 17:44

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

sheepsky - July 15, 2015 @ 10:42

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

sheepsky - July 15, 2015 @ 11:06

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

Tamunosiki Bamson - July 18, 2015 @ 19:30

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

4.17