Category Trend  Published on 19/08/2024

CMA

Description

new version

four moving average for 

open low high close in a candle

 

 

 

 

 




////////////////////////////////////////////////////////////////////////////////////////
///                                     CMA                                          ///
///                                                                                  ///
///         Publish date  18-DEC-2023                                                ///
///         Version  1.1.0                                                           ///
///         By  mohamadreza chaji                                                    ///
///         License  MIT                                                             ///
///         Contact  mr.ch1371@gmail.com                                             ///
///                                                                                  ///
////////////////////////////////////////////////////////////////////////////////////////

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
    [Cloud("OMain", "CMain", Opacity = 0.4)]
    [Cloud("LMain", "HMain", Opacity = 0.2)]
    public class CMA : Indicator
    {  
        [Parameter("MA length", DefaultValue = 38, MinValue = 1, Group = "Period")]
        public int SMA_Period { get; set; }
        [Parameter("MA shift", DefaultValue = 0, Group = "Period")]
        public int mas { get; set; }
        [Parameter("vertical shift", DefaultValue = 0, Group = "Period")]
        public double vs { get; set; }
        [Parameter("history", DefaultValue =618, MinValue = 23, Group = "Extra lines")]
        public int his { get; set; }
        [Parameter("Show", Group = "Extra lines", DefaultValue = false)]
        public bool CSHOW { get; set; } 
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAType { get; set; }        
        [Output("CMain", LineStyle = LineStyle.Solid, LineColor = "green")]
        public IndicatorDataSeries CResult { get; set; }
        [Output("OMain", LineStyle = LineStyle.Solid, LineColor = "green")]
        public IndicatorDataSeries OResult { get; set; }
        [Output("LMain", LineStyle = LineStyle.Solid, LineColor = "gray")]
        public IndicatorDataSeries LResult { get; set; }
        [Output("HMain", LineStyle = LineStyle.Solid, LineColor = "gray")]
        public IndicatorDataSeries HResult { get; set; }
        [Output("upline", LineStyle = LineStyle.Solid, LineColor = "gray")]
        public IndicatorDataSeries upl { get; set; }
        [Output("downline", LineStyle = LineStyle.Solid, LineColor = "gray")]
        public IndicatorDataSeries downl { get; set; }
        private MovingAverage OmovingAverage;
        private MovingAverage CmovingAverage;
        private MovingAverage LmovingAverage;
        private MovingAverage HmovingAverage;
          public IndicatorDataSeries DI_Result { get; set; }
          public IndicatorDataSeries UI_Result { get; set; }
        protected override void Initialize()
        {
           UI_Result=CreateDataSeries();
           DI_Result=CreateDataSeries();
           OmovingAverage = Indicators.MovingAverage(MarketSeries.Open, SMA_Period, MAType);
           CmovingAverage = Indicators.MovingAverage(MarketSeries.Close, SMA_Period, MAType);
           LmovingAverage = Indicators.MovingAverage(MarketSeries.Low, SMA_Period, MAType);
           HmovingAverage = Indicators.MovingAverage(MarketSeries.High, SMA_Period, MAType);
        }
        public override void Calculate(int index)
        {
            CResult[index+mas]=CmovingAverage.Result[index]+vs;
            OResult[index+mas]=OmovingAverage.Result[index]+vs;
            LResult[index+mas]=LmovingAverage.Result[index]+vs;
            HResult[index+mas]=HmovingAverage.Result[index]+vs;
            if(CSHOW){
                UI_Result[index+mas]=Bars.HighPrices[index] - HResult[index+mas];
                DI_Result[index+mas]= LResult[index+mas]-Bars.LowPrices[index];
                double vmax = Functions.Maximum(UI_Result,his);
                double vmin = Functions.Maximum(DI_Result,his);
                upl[index+mas]=(HResult[index+mas] + vmax)+vs;
                downl[index+mas]=(LResult[index+mas]-vmin)+vs;
            }
        }
    }
}

mr.ch1371's avatar
mr.ch1371

Joined on 11.08.2024

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: CMA_1.1.algo
  • Rating: 5
  • Installs: 242
  • Modified: 13/09/2024 04:37
Comments
Log in to add a comment.
VI
vittochimo · 3 months ago

https://ctrader.com/users/profile/61141