combine Rsi, Macd, Obv & Mfi indicators

Created at 28 Sep 2024, 01:02
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MA

Masoud7Z

Joined 28.09.2024

combine Rsi, Macd, Obv & Mfi indicators
28 Sep 2024, 01:02


I want to combine Rsi, Macd, Obv & Mfi indicators in one window but I have a problem that they do not work with each other. What is the best? This is the code.

 Is it correct or needs modification?

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
    public class CombinedIndicators : Indicator
    {
        private RelativeStrengthIndex _rsi;
        private MoneyFlowIndex _mfi;
        private MacdHistogram _macdHistogram;
        private MacdCrossOver _macdCrossOver;

        [Parameter("RSI Period", DefaultValue = 14)]
        public int RsiPeriod { get; set; }

        [Parameter("MFI Period", DefaultValue = 14)]
        public int MfiPeriod { get; set; }

        [Parameter("MACD Long Cycle", DefaultValue = 26)]
        public int MacdLongCycle { get; set; }

        [Parameter("MACD Short Cycle", DefaultValue = 12)]
        public int MacdShortCycle { get; set; }

        [Parameter("MACD Signal Period", DefaultValue = 9)]
        public int MacdSignalPeriod { get; set; }

        [Output("RSI", LineColor = "Red")]
        public IndicatorDataSeries RsiResult { get; set; }

        [Output("MFI", LineColor = "Green")]
        public IndicatorDataSeries MfiResult { get; set; }

        [Output("MACD Histogram", LineColor = "Gray")]
        public IndicatorDataSeries MacdHistogramResult { get; set; }

        [Output("MACD Signal", LineColor = "Orange")]
        public IndicatorDataSeries MacdSignalResult { get; set; }

        [Output("MACD Crossover", LineColor = "Purple")]
        public IndicatorDataSeries MacdCrossoverResult { get; set; }

        protected override void Initialize()
        {
            // تهيئة المؤشرات الجاهزة
            _rsi = Indicators.RelativeStrengthIndex(Bars.ClosePrices, RsiPeriod);
            _mfi = Indicators.MoneyFlowIndex(MfiPeriod);
            _macdHistogram = Indicators.MacdHistogram(Bars.ClosePrices, MacdLongCycle, MacdShortCycle, MacdSignalPeriod);
            _macdCrossOver = Indicators.MacdCrossOver(Bars.ClosePrices, MacdLongCycle, MacdShortCycle, MacdSignalPeriod);

            // إضافة خطوط 70 و 30 لمؤشر RSI
            Chart.DrawHorizontalLine("RSI_70", 70, Color.Gray, 1, LineStyle.Dots);
            Chart.DrawHorizontalLine("RSI_30", 30, Color.Gray, 1, LineStyle.Dots);

            // ضبط نطاق عرض مؤشر RSI
            Chart.DrawText("RSI_10", "10", Bars.OpenTimes[0], 10, Color.Gray);
            Chart.DrawText("RSI_90", "90", Bars.OpenTimes[0], 90, Color.Gray);
        }

        public override void Calculate(int index)
        {
            // حساب القيم وعرضها على نافذة واحدة
            RsiResult[index] = _rsi.Result[index];
            MfiResult[index] = _mfi.Result[index];
            MacdHistogramResult[index] = _macdHistogram.Histogram[index];
            MacdSignalResult[index] = _macdHistogram.Signal[index];
            MacdCrossoverResult[index] = _macdCrossOver.MACD[index];
        }
    }
}


@Masoud7Z
Replies

PanagiotisCharalampous
30 Sep 2024, 06:06

Hi there,

Can you explain what the problem is?

Best regards

Panagiotis


@PanagiotisCharalampous