Category Trend  at 31/03/2022

Multi Timeframe Stochastic Oscillator


Simply Stochastic Oscillator with multi timeframe functionality.

Looks interesting to see how H1's 5, 3, 3 Stochastic gives an early signal for reversal on 5 minutes timeframe.

*Actually I never use Stochastic on my trades (hmm I used it anyway..., when I started to learn about forex trading years ago). So if you have a profitable strategy using Stochastic please share your thoughts!





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

namespace cAlgo
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    [Levels(20, 50, 80)]

    public class MultiTimeframeStochasticOscillator : Indicator
        private StochasticOscillator _Stochastic;
        private Bars _Series;
        private int _TimeframeIndex;

        [Parameter("%K Periods", DefaultValue = 5, MinValue = 1)]
        public int _KPeriods { get; set; }

        [Parameter("%K Slowing", DefaultValue = 3, MinValue = 1)]
        public int _KSlowing { get; set; }

        [Parameter("%D Periods", DefaultValue = 3, MinValue = 0)]
        public int _DPeriods { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType _MAType { get; set; }

        [Parameter("Timeframe", DefaultValue = "hour1")]
        public TimeFrame _Timeframe { get; set; }

        [Parameter("Smoothing", DefaultValue = _Smoothing.No)]
        public _Smoothing _SmoothLine { get; set; }
        public enum _Smoothing

        [Output("%D", LineColor = "Red", LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries _PercentD { get; set; }

        [Output("%K", LineColor = "Green")]
        public IndicatorDataSeries _PercentK { get; set; }

        protected override void Initialize()
            _Series = MarketData.GetBars(_Timeframe);
            _Stochastic = Indicators.StochasticOscillator(_Series, _KPeriods, _KSlowing, _DPeriods, _MAType);

        public override void Calculate(int index)
            switch (_SmoothLine)
                case _Smoothing.No:
                    _TimeframeIndex = _Series.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
                    _TimeframeIndex = GetIndexByDate(_Series, Bars.OpenTimes[index]);

            _PercentD[index] = _Stochastic.PercentD[_TimeframeIndex];
            _PercentK[index] = _Stochastic.PercentK[_TimeframeIndex];

        private int GetIndexByDate(Bars series, DateTime time)
            for (int i = series.ClosePrices.Count - 1; i > 0; i--)
                if (series.OpenTimes[i] == time)
                    return i;
            return -1;



Joined 17.10.2020

  • Type: Free
  • Language: C#
  • Trading Platform: cTrader Automate
  • Filename: Multi Timeframe Stochastic Oscillator.algo
  • Rating: 5
  • Downloads: 1378
Only logged in users can post a comment
o6h58zs's avatar
o6h58zs · 1 year ago

Very elegant solution for the multiple timeframes dadi, I've been trying to find a way to do this. Nice work! ????

Also, regarding strategies, I often use the crossovers between the K% and D% lines as entry confirmations. When in an uptrend, I wait for the K% to crossover the D% before entering a trade, and the reverse in a downtrend. I also use a volume indicator (MFI) or oscillator (RSI, etc.) to confirm the momentum in that direction (above or below the 50 line on each).

I never use overbought and oversold areas and in my opinion, it is unwise to - like the indicators mentioned above, the stochastic is a momentum indicator, and a market can remain overbought or oversold for a long time, depending on the period you're using. Hope that helps. ☺

mabellindda · 1 year ago

These are complex pieces of code. How can I apply it to the pages of this fnf online wordle 2 website?