Description
The Stochastic Oscillator in the form of a histogram.
- Buy when it moves from negative to positive in the uptrend
- Sell when it moves from positive to negative in the downtrend
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Indicators
{
[Levels(0.0)]
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class StochasticHistogram : Indicator
{
[Parameter("%K Periods", DefaultValue = 14)]
public int kPeriods { get; set; }
[Parameter("%K Slowing", DefaultValue = 3)]
public int kSlowing { get; set; }
[Parameter("%D Periods", DefaultValue = 3)]
public int dPeriods { get; set; }
[Parameter("MA Type")]
public MovingAverageType maType { get; set; }
[Output("Histogram > 0", PlotType = PlotType.Histogram, Color = Colors.Green, Thickness = 1)]
public IndicatorDataSeries HistogramPositive { get; set; }
[Output("Histogram < 0", PlotType = PlotType.Histogram, Color = Colors.Green, Thickness = 1)]
public IndicatorDataSeries HistogramNegative { get; set; }
[Output("%K", PlotType = PlotType.Line, Color = Colors.Green, Thickness = 1)]
public IndicatorDataSeries K { get; set; }
[Output("%D", PlotType = PlotType.Line, LineStyle = LineStyle.Lines, Color = Colors.Red, Thickness = 1)]
public IndicatorDataSeries D { get; set; }
StochasticOscillator stochastic;
protected override void Initialize()
{
stochastic = Indicators.StochasticOscillator(kPeriods, kSlowing, dPeriods, maType);
}
public override void Calculate(int index)
{
if (stochastic.PercentK[index] - 50 > 0)
HistogramPositive[index] = stochastic.PercentK[index] - 50;
if (stochastic.PercentK[index] - 50 < 0)
HistogramNegative[index] = stochastic.PercentK[index] - 50;
K[index] = stochastic.PercentK[index] - 50;
D[index] = stochastic.PercentD[index] - 50;
}
}
}
AL
alphafx
Joined on 02.08.2016
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Stochastic Histogram.algo
- Rating: 5
- Installs: 4442
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.