Category Trend  Published on 31/03/2022

Multi Timeframe Stochastic Oscillator

Description

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!

 

Cheers.

 

 


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
        {
            Yes,
            No
        }

        [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]);
                    break;
                default:
                    _TimeframeIndex = GetIndexByDate(_Series, Bars.OpenTimes[index]);
                    break;
            }

            _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;
        }

    }
}


DA
dadi

Joined on 17.10.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Multi Timeframe Stochastic Oscillator.algo
  • Rating: 5
  • Installs: 1833
  • Modified: 31/03/2022 14:02
Comments
Log in to add a comment.
CA
carpentersophia497 · 3 months ago

Hello! The topic your friend is exploring sounds quite interesting. The Simply Stochastic Oscillator with multi-timeframe functionality can indeed be a valuable tool. For instance, using the 5, 3, 3 settings on the H1 timeframe can provide an early signal for a reversal on the 5-minute timeframe. This approach allows for more precise signals on a smaller interval while being guided by the broader trend. It might also be beneficial to experiment with different settings and combine them with other indicators to confirm signals. Do you think this could be helpful for them?

o6h58zs's avatar
o6h58zs · 2 years 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. ☺

MA
mabellindda · 2 years ago

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