Moving Average Cross Over free

by TraderExperto in category Trend at 25/10/2022
Description

This is a simple Indicator based on two Moving Averages, that you can choose between many of them made available natively from Ctrader.

The Indicator changes the colors of the Clouds depending on the Trend and it paints the Candles as well based on the Trend.

There was a little error in my code, and i just uploaded it without noticing it. The indicator was asked from some members our group

and i did it fast without having a better look into it. Here please delete the old one and install this one.

 

You can find me by joyining this Telegram Group http://t.me/cTraderCoders

Grupo de Telegram Para Brasileiros, Portugueses e todos aqueles que falam portugues:http://t.me/ComunidadeCtrader

Grupo CTrader en Español para Latinos:  http://t.me/ComunidadCtrader

 

 

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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Cloud("Fast MA", "Slow MA",  FirstColor = "LawnGreen")]

    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
    public class MovingAverageCrossOverExperto : Indicator
    {
        [Parameter("Fast Period", DefaultValue = "45")]
        public int fastPeriod{ get; set; }
        
        [Parameter("Slow Period", DefaultValue = "100")]
        public int slowPeriod{ get; set; }
        
        [Parameter("Moving Average Type", DefaultValue = MovingAverageType.WilderSmoothing)]
        public MovingAverageType MaType { get; set; }

        [Output("Fast MA", LineColor = "LawnGreen")]
        public IndicatorDataSeries Fast_MA { get; set; }
        
        [Output("Slow MA", LineColor = "Coral")]
        public IndicatorDataSeries Slow_MA { get; set; }
        
        public MovingAverage SlowMa;
        
        public MovingAverage FastMa;

        protected override void Initialize()
        {
            FastMa = Indicators.MovingAverage(Bars.ClosePrices, fastPeriod, MaType);
            
            SlowMa = Indicators.MovingAverage(Bars.ClosePrices, slowPeriod, MaType);
        }

        public override void Calculate(int index)
        {
            Fast_MA[index] = FastMa.Result[index];
            Slow_MA[index] = SlowMa.Result[index];
            
            if(Bars.ClosePrices[index] >= FastMa.Result[index])
            {
                if(Bars.ClosePrices[index] >= Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.LawnGreen);
                else if(Bars.ClosePrices[index] < Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.Green);
            }
             else if(Bars.ClosePrices[index] < FastMa.Result[index])
            {
                if(Bars.ClosePrices[index] <= Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.Red);
                else if(Bars.ClosePrices[index] > Bars.OpenPrices[index])
                    Chart.SetBarColor(index, Color.Coral);
            }
            
            
        }
    }
}
Comments

mfejza - October 25, 2022 @ 16:04

change rows 38 and 40, for full functionality

            FastMa = Indicators.MovingAverage(Bars.ClosePrices, fastPeriod, MaType);
             
            SlowMa = Indicators.MovingAverage(Bars.ClosePrices, slowPeriod, MaType);

TraderExperto - October 25, 2022 @ 22:17

Sorry for the error in the Code! Made it in a hurry some members of one of our groups were asking it.

So i just uploaded it without ckecking if it was everything all right

 

5