category Trend  at 27/08/2023

Colour changing MA's

Notice. There is an update for this algorithm which is awaiting moderation. Please check back soon to view the latest version of this algorithm.
Description

Can anyone tell my why this has a gap in the lines?

Moving averages with colour changing lines to show up or down movement

 

 

 

 

using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MAL3 : Indicator
      { 
        public DataSeries Source { get; set; }
        
        [Parameter("P 1", DefaultValue = 8)]
        public int P1 { get; set; }
        [Parameter("P 2", DefaultValue = 34)]
        public int P2 { get; set; }
        [Parameter("P 3", DefaultValue = 96)]
        public int P3 { get; set; }
        [Parameter("P 4", DefaultValue = 408)]
        public int P4 { get; set; }
        [Parameter("M A")]
        public MovingAverageType MAType { get; set; }
        
        [Output("Up1", LineColor = "8800FF00", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Up1 { get; set; }
        
        [Output("Dn1", LineColor = "88FF0000", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Dn1 { get; set; }
        
        [Output("Up2", LineColor = "8800FF00", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Up2 { get; set; }
        
        [Output("Dn2", LineColor = "88FF0000", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Dn2 { get; set; }
        
        [Output("Up3", LineColor = "8800FF00", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Up3 { get; set; }
        
        [Output("Dn3", LineColor = "88FF0000", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Dn3 { get; set; }
        
        [Output("Up4", LineColor = "8800FF00", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Up4 { get; set; }
        
        [Output("Dn4", LineColor = "88FF0000", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
        public IndicatorDataSeries Dn4 { get; set; }
        
        MovingAverage M1;
        MovingAverage M2;
        MovingAverage M3;
        MovingAverage M4;
        
        protected override void Initialize()
        {
        M1 = Indicators.MovingAverage(Source,P1,MAType);
        M2 = Indicators.MovingAverage(Source,P2,MAType);
        M3 = Indicators.MovingAverage(Source,P3,MAType);
        M4 = Indicators.MovingAverage(Source,P4,MAType);
        
        
        }
        public override void Calculate(int index)
        {
            
      
            if (M1.Result.Last(0) >= M1.Result.Last(1))
            {
                Up1[index] = M1.Result[index];
            }
            if (M1.Result.Last(0) <= M1.Result.Last(1))
            {
                Dn1[index] = M1.Result[index];
            }
            
            if (M2.Result.Last(0) >= M2.Result.Last(1))
            {
                Up2[index] = M2.Result[index];
            }
            if (M2.Result.Last(0) <= M2.Result.Last(1))
            {
                Dn2[index] = M2.Result[index];
            }
            
            if (M3.Result.Last(0) >= M3.Result.Last(1))
            {
                Up3[index] = M3.Result[index];
            }
            if (M3.Result.Last(0) <= M3.Result.Last(1))
            {
                Dn3[index] = M3.Result[index];
            }
            
            if (M4.Result.Last(0) >= M4.Result.Last(1))
            {
                Up4[index] = M4.Result[index];
            }
            if (M4.Result.Last(0) <= M4.Result.Last(1))
            {
                Dn4[index] = M4.Result[index];
            }
                  }
             }
        }
   




VE
Splash The

Joined 06.12.2022

  • Type: free
  • Language: C#
  • Trading Platform: cTrader Automate
  • Filename: MAL3.algo
  • Rating: 0
  • Downloads: 113
Comments
Only logged in users can post a comment
Comments not found