Topics

Forum Topics not found

Replies

K3Charts
06 Nov 2024, 15:00

I've never seen a bug like this, with so much time without solving it.

I've been using cTrader for over 6 years. I've never seen a bug like this, with so much time without solving it.

Doesn't work:

Alarm

Custom indicators

Doesn't save WorkSpace

Works poorly:

Backtest cbot

Intent connection drops out for no reason

Ctrader has no respect and doesn't say anything.

Many things are at stake: money, dreams and lives.


@K3Charts

K3Charts
19 Oct 2024, 17:26 ( Updated at: 20 Oct 2024, 05:18 )

atualized in 10/2024. naw wich histogram change color above and below level =0

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MTFMACD : Indicator
    {
        private MacdCrossOver _macd;

        private Bars _baseTimeFrameBars;

        [Output("Histogram Up", LineColor = "Green", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries MACD_Histogram_Up { get; set; }

        [Output("Histogram Down", LineColor = "Red", PlotType = PlotType.Histogram, Thickness = 5)]
        public IndicatorDataSeries MACD_Histogram_Down { get; set; }

        [Output("MACD Line", LineColor = "Gold", PlotType = PlotType.Line, LineStyle = LineStyle.Solid, Thickness = 1)]
        public IndicatorDataSeries MACD_Line { get; set; }

        [Output("Signal Line", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Lines, Thickness = 1)]
        public IndicatorDataSeries Signal_Line { get; set; }

        [Parameter("Base Timeframe", DefaultValue = "Daily")]
        public TimeFrame BaseTimeFrame { get; set; }

        [Parameter("Applied price", DefaultValue = Price.Close)]
        public Price Source { get; set; }

        [Parameter("Long Period", DefaultValue = 10)]
        public int LongPeriod { get; set; }

        [Parameter("Short Period", DefaultValue = 3)]
        public int ShortPeriod { get; set; }

        [Parameter("Signal Period", DefaultValue = 16)]
        public int SignalPeriod { get; set; }

        protected override void Initialize()
        {
            _baseTimeFrameBars = MarketData.GetBars(BaseTimeFrame);

            var baseSeries = GetBaseSeries();

            _macd = Indicators.MacdCrossOver(baseSeries, LongPeriod, ShortPeriod, SignalPeriod);
        }

        public override void Calculate(int index)
        {
            var baseSeriesIndex = _baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            // MACD histogram logic with color change based on value
            double macdHistogramValue = _macd.Histogram[baseSeriesIndex];

            if (macdHistogramValue >= 0)
            {
                MACD_Histogram_Up[index] = macdHistogramValue;   // Histogram Up (green)
                MACD_Histogram_Down[index] = double.NaN;         // NaN to hide the down histogram
            }
            else
            {
                MACD_Histogram_Up[index] = double.NaN;           // NaN to hide the up histogram
                MACD_Histogram_Down[index] = macdHistogramValue; // Histogram Down (red)
            }

            // MACD line and signal line
            MACD_Line[index] = _macd.MACD[baseSeriesIndex];
            Signal_Line[index] = _macd.Signal[baseSeriesIndex];
        }

        private DataSeries GetBaseSeries()
        {
            switch (Source)
            {
                case Price.Open:
                    return _baseTimeFrameBars.OpenPrices;

                case Price.Close:
                    return _baseTimeFrameBars.ClosePrices;

                case Price.High:
                    return _baseTimeFrameBars.HighPrices;

                case Price.Low:
                    return _baseTimeFrameBars.LowPrices;

                case Price.Median:
                    return _baseTimeFrameBars.MedianPrices;

                case Price.Typical:
                    return _baseTimeFrameBars.TypicalPrices;

                case Price.Weighted:
                    return _baseTimeFrameBars.WeightedPrices;

                default:
                    return _baseTimeFrameBars.ClosePrices;
            }
        }
    }

    public enum Price
    {
        Open,
        Close,
        High,
        Low,
        Median,
        Typical,
        Weighted
    }
}


@K3Charts