Description
The Stoch
You are already familiar with the limitations of the traditional stochastic. So, here's 'The Stoch':
- It analyzes candlesticks using HighPrice and LowPrice, providing an optimal reading of new highs and lows.
- A new concept that dynamically increases the stochastic calculation periods at each bar once a specific threshold is crossed.
This Stochastique indicator provides advanced stochastic analysis by combining two sets of calculations: an initial stochastic indicator with user-defined periods, and a more accurate stochastic indicator that dynamically adjusts its periods based on detected trends. Here's what the different results display:
Initial Stochastic (ResultInit and SignalInit):
- ResultInit: Shows the %K line, representing the primary stochastic value.
- SignalInit: Shows the %D signal line, which is a moving average of %K.
- These lines provide a classic stochastic representation based on the periods defined in the initial parameters.
Accurate Stochastic (StochAccuRes, StochAccuUp, StochAccuDown, SignalAccu):
- StochAccuRes: Displays the %K line for the dynamically adjusted accurate stochastic.
- StochAccuUp and StochAccuDown: Show the adjusted %K lines, depending on the upward or downward trend.
- SignalAccu: Displays the corresponding %D signal line, based on a moving average of %K.
Overbought and Oversold Levels (LevelUp and LevelDown):
- LevelUp: Plots a fixed level (default: 70) indicating the overbought threshold.
- LevelDown: Plots another fixed level (default: 30) indicating the oversold threshold.
Interpretation of Results:
- If the %K line (initial or accurate) crosses above the overbought level (LevelUp) for the first time, it signals the birth of an upward trend.
- If %K drops below the oversold level (LevelDown) for the first time, it signals the birth of a downward trend.
- The accurate stochastic adjusts periods to capture trend changes more effectively.
In summary, the indicator provides both traditional and dynamic stochastic analysis, offering better adaptability to market conditions.
On telegram : https://t.me/nimi012 (direct messaging)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class TheStochv10 : Indicator
{
[Parameter(DefaultValue = 255, Group = "Initial Stoch")]
public int KPeriodInit { get; set; }
[Parameter(DefaultValue = 3, Group = "Initial Stoch")]
public int KSlowingInit { get; set; }
[Parameter(DefaultValue = 34, Group = "Initial Stoch")]
public int DPeriodInit { get; set; }
[Parameter(DefaultValue = MovingAverageType.Weighted, Group = "Initial Stoch")]
public MovingAverageType MaTypeInit { get; set; }
[Parameter(DefaultValue = 9, Group = "Accurate Stoch")]
public int MinPeriodAccu { get; set; }
[Parameter(DefaultValue = 3, Group = "Accurate Stoch")]
public int KSlowingAccu { get; set; }
[Parameter(DefaultValue = 21, Group = "Accurate Stoch")]
public int DPeriodAccu { get; set; }
[Parameter(DefaultValue = MovingAverageType.Weighted, Group = "Accurate Stoch")]
public MovingAverageType MaTypeAccu { get; set; }
[Parameter(DefaultValue = 98, Group = "Start Trend Level Stoch")]
public int TrendStartLevelUp { get; set; }
[Parameter(DefaultValue = 2, Group = "Start Trend Level Stoch")]
public int TrendStartLevelDown { get; set; }
[Parameter(DefaultValue = 70, Group = "OverBuy/Sell Level")]
public int OverBuy { get; set; }
[Parameter(DefaultValue = 30, Group = "OverBuy/Sell Level")]
public int OverSell { get; set; }
[Output("LevelUp", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Solid)]
public IndicatorDataSeries LevelUp { get; set; }
[Output("LevelDown", LineColor = "Lime", PlotType = PlotType.Line, LineStyle = LineStyle.Solid)]
public IndicatorDataSeries LevelDown { get; set; }
[Output("Stoch Init", LineColor = "Lime", PlotType = PlotType.Line, LineStyle = LineStyle.Dots)]
public IndicatorDataSeries ResultInit { get; set; }
[Output("Signal Init", LineColor = "Red", PlotType = PlotType.Line, LineStyle = LineStyle.Dots)]
public IndicatorDataSeries SingalInit { get; set; }
[Output("StochAccu", LineColor = "Gray", PlotType = PlotType.Line)]
public IndicatorDataSeries StochAccuRes { get; set; }
[Output("StochAccuUp", LineColor = "Lime", PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries StochAccuUp { get; set; }
[Output("StochAccuDown", LineColor = "Red", PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries StochAccuDown { get; set; }
[Output("SiganlAccu", LineColor = "Gold", PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries SignalAccu { get; set; }
private IndicatorDataSeries highData, medData, lowData, res1, res2;
private IndicatorDataSeries highData2, medData2, lowData2;
private MovingAverage kslowInit, dslowInit, kslowAccu, dslowAccu;
private int CountUp;
private int CountDown;
private int indexUp;
private int indexDown;
private bool StartCountUp;
private bool StartCountDown;
protected override void Initialize()
{
highData = CreateDataSeries();
medData = CreateDataSeries();
lowData = CreateDataSeries();
res1 = CreateDataSeries();
res2 = CreateDataSeries();
kslowInit = Indicators.MovingAverage(res1, KSlowingInit, MaTypeInit);
dslowInit = Indicators.MovingAverage(kslowInit.Result, DPeriodInit, MaTypeInit);
kslowAccu = Indicators.MovingAverage(res2, KSlowingAccu, MaTypeAccu);
dslowAccu = Indicators.MovingAverage(kslowAccu.Result, DPeriodAccu, MaTypeAccu);
highData2 = CreateDataSeries();
medData2 = CreateDataSeries();
lowData2 = CreateDataSeries();
CountUp = 0;
CountDown = 0;
StartCountUp = false;
StartCountDown = false;
}
public override void Calculate(int index)
{
highData[index] = (Bars.HighPrices.Last(0) - Bars.LowPrices.Minimum(KPeriodInit)) / (Bars.HighPrices.Maximum(KPeriodInit) - Bars.LowPrices.Minimum(KPeriodInit)) * 100;
medData[index] = (Bars.MedianPrices.Last(0) - Bars.LowPrices.Minimum(KPeriodInit)) / (Bars.HighPrices.Maximum(KPeriodInit) - Bars.LowPrices.Minimum(KPeriodInit)) * 100;
lowData[index] = (Bars.LowPrices.Last(0) - Bars.LowPrices.Minimum(KPeriodInit)) / (Bars.HighPrices.Maximum(KPeriodInit) - Bars.LowPrices.Minimum(KPeriodInit)) * 100;
res1[index] = medData[index];
ResultInit[index] = kslowInit.Result.Last(0);
SingalInit[index] = dslowInit.Result.Last(0);
LevelUp[index] = OverBuy;
LevelDown[index] = OverSell;
if (medData[index] > TrendStartLevelUp)
{
StartCountDown = false;
StartCountUp = true;
}
else if (medData[index] < TrendStartLevelDown)
{
StartCountUp = false;
StartCountDown = true;
}
if (StartCountUp && indexUp < index)
{
CountUp++;
CountDown = 0;
var period = MinPeriodAccu >= CountUp ? MinPeriodAccu : CountUp;
highData2[index] = (Bars.HighPrices.Last(0) - Bars.LowPrices.Minimum(period)) / (Bars.HighPrices.Maximum(period) - Bars.LowPrices.Minimum(period)) * 100;
medData2[index] = (Bars.MedianPrices.Last(0) - Bars.LowPrices.Minimum(period)) / (Bars.HighPrices.Maximum(period) - Bars.LowPrices.Minimum(period)) * 100;
lowData2[index] = (Bars.LowPrices.Last(0) - Bars.LowPrices.Minimum(period)) / (Bars.HighPrices.Maximum(period) - Bars.LowPrices.Minimum(period)) * 100;
res2[index] = lowData2[index];
StochAccuUp[index] = kslowAccu.Result.Last(0);
indexUp = index;
}
else if (StartCountDown && indexDown < index)
{
CountDown++;
CountUp = 0;
var period = MinPeriodAccu >= CountDown ? MinPeriodAccu : CountDown;
highData2[index] = (Bars.HighPrices.Last(0) - Bars.LowPrices.Minimum(period)) / (Bars.HighPrices.Maximum(period) - Bars.LowPrices.Minimum(period)) * 100;
medData2[index] = (Bars.MedianPrices.Last(0) - Bars.LowPrices.Minimum(period)) / (Bars.HighPrices.Maximum(period) - Bars.LowPrices.Minimum(period)) * 100;
lowData2[index] = (Bars.LowPrices.Last(0) - Bars.LowPrices.Minimum(period)) / (Bars.HighPrices.Maximum(period) - Bars.LowPrices.Minimum(period)) * 100;
res2[index] = highData2[index];
StochAccuDown[index] = kslowAccu.Result.Last(0);
indexDown = index;
}
StochAccuRes[index] = kslowAccu.Result.Last(0);
SignalAccu[index] = dslowAccu.Result.Last(0);
}
}
}
YesOrNot
Joined on 10.10.2022 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: The Stoch v1.0.algo
- Rating: 0
- Installs: 110
- Modified: 08/05/2024 20:27