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 17.10.2020
- Type: Free
- Language: C#
- Trading Platform: cTrader Automate
- Filename: Multi Timeframe Stochastic Oscillator.algo
- Rating: 5
- Downloads: 1378
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Comments
Only logged in users can post a comment
MA
These are complex pieces of code. How can I apply it to the pages of this fnf online wordle 2 website?
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. ☺