Information

Username: opit78
Member since: 17 Mar 2020
Last login: 08 Mar 2023
Status: Active

Activity

Where Created Comments
Algorithms 0 3
Forum Topics 0 1
Jobs 0 0

Last Algorithm Comments

OP
opit78 · 2 years ago

@khoshroomahdi of course you can use it

OP
opit78 · 2 years ago

Hi.

You made this code too complicated.

Yes, you can change cloud's color without need of changing the code.

Just analize mine:

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

namespace cAlgo
{
    [Cloud("1st MA Color", "2nd MA Color", Opacity = 0.3)]
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BartMACloud : Indicator
    {
        [Parameter("1st MA Source", Group = "1st Moving Average")]
        public DataSeries ASource { get; set; }

        [Parameter("1st MA Type", Group = "1st Moving Average", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType AMAType { get; set; }

        [Parameter("1st MA Period", Group = "1st Moving Average", DefaultValue = 5)]
        public int AMAPeriod { get; set; }

        [Parameter("2st MA Source", Group = "2nd Moving Average")]
        public DataSeries BSource { get; set; }

        [Parameter("2nd MA Type", Group = "2nd Moving Average", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType BMAType { get; set; }

        [Parameter("2nd MA Period", Group = "2nd Moving Average", DefaultValue = 34)]
        public int BMAPeriod { get; set; }

        [Parameter("Show arrows", Group = "Arrows", DefaultValue = false)]
        public bool ShowArrows { get; set; }

        [Parameter("Arrows offset", Group = "Arrows", DefaultValue = 10, MinValue = 1)]
        public int Offset { get; set; }

        [Output("1st MA Color", LineColor = "Lime", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries AMaResult { get; set; }

        [Output("2nd MA Color", LineColor = "Red", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries BMaResult { get; set; }

        MovingAverage AMa;
        MovingAverage BMa;

        private double arrowOffset;


        protected override void Initialize()
        {
            AMa = Indicators.MovingAverage(ASource, AMAPeriod, AMAType);
            BMa = Indicators.MovingAverage(BSource, BMAPeriod, BMAType);

            arrowOffset = Symbol.PipSize * Offset;
        }

        public override void Calculate(int index)
        {
            AMaResult[index] = AMa.Result[index];
            BMaResult[index] = BMa.Result[index];

            if (ShowArrows)
            {
                double high = Bars.HighPrices[index];
                double low = Bars.LowPrices[index];

                if (AMa.Result.Last(1) > BMa.Result.Last(1) && AMa.Result.Last(2) < BMa.Result.Last(2))
                {
                    Chart.DrawIcon("Up" + index, ChartIconType.UpArrow, index - 1, low - arrowOffset, Color.Green);
                }

                if (AMa.Result.Last(1) < BMa.Result.Last(1) && AMa.Result.Last(2) > BMa.Result.Last(2))
                {
                    Chart.DrawIcon("Down" + index, ChartIconType.DownArrow, index - 1, high + arrowOffset, Color.Red);
                }
            }
        }
    }
}

OP
opit78 · 3 years ago

What reference should be added for it co compile ? Thanks