Category Trend  Published on 27/08/2023

Colour changing MA's

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
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
VEI5S6C4OUNT0

Joined on 06.12.2022

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: MAL3.algo
  • Rating: 0
  • Installs: 558
  • Modified: 27/08/2023 19:17
Comments
Log in to add a comment.
No comments found.