Description
Stochastic lovers:
Here's an indicator that super-imposes a maximum of 3 Stochastic indicators (each of a different timeframe) onto the current chart
In the screen shot below, we can see the Stochastics of the H1 timeframe and also of the H4 both placed on a M5 chart
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class KF_Mtf_Stochastics_v2 : Indicator
{
#region Settings
[Parameter("S1_Enabled", DefaultValue = true, Group = "Stoch1")]
public bool S1_Enabled { get; set; }
[Parameter("S1_KPeriods", DefaultValue = 9, Group = "Stoch1")]
public int S1_KPeriods { get; set; }
[Parameter("S1_KSlowing", DefaultValue = 3, Group = "Stoch1")]
public int S1_KSlowing { get; set; }
[Parameter("S1_DPeriods", DefaultValue = 9, Group = "Stoch1")]
public int S1_DPeriods { get; set; }
[Parameter("S1_MAType", DefaultValue = MovingAverageType.Simple, Group = "Stoch1")]
public MovingAverageType S1_MaType { get; set; }
[Parameter("S2_Enabled", DefaultValue = true, Group = "Stoch2")]
public bool S2_Enabled { get; set; }
[Parameter("S2_TF", DefaultValue = "Hour", Group = "Stoch2")]
public TimeFrame S2_TF { get; set; }
[Parameter("S2_KPeriods", DefaultValue = 5, Group = "Stoch2")]
public int S2_KPeriods { get; set; }
[Parameter("S2_KSlowing", DefaultValue = 3, Group = "Stoch2")]
public int S2_KSlowing { get; set; }
[Parameter("S2_DPeriods", DefaultValue = 3, Group = "Stoch2")]
public int S2_DPeriods { get; set; }
[Parameter("S2_MAType", DefaultValue = MovingAverageType.Simple, Group = "Stoch2")]
public MovingAverageType S2_MaType { get; set; }
[Parameter("S3_Enabled", DefaultValue = true, Group = "Stoch3")]
public bool S3_Enabled { get; set; }
[Parameter("S3_TF", DefaultValue = "Hour4", Group = "Stoch3")]
public TimeFrame S3_TF { get; set; }
[Parameter("S3_KPeriods", DefaultValue = 5, Group = "Stoch3")]
public int S3_KPeriods { get; set; }
[Parameter("S3_KSlowing", DefaultValue = 3, Group = "Stoch3")]
public int S3_KSlowing { get; set; }
[Parameter("S3_DPeriods", DefaultValue = 3, Group = "Stoch3")]
public int S3_DPeriods { get; set; }
[Parameter("S3_MAType", DefaultValue = MovingAverageType.Simple, Group = "Stoch3")]
public MovingAverageType S3_MaType { get; set; }
[Parameter("Signalling_ON", DefaultValue = false, Group = "Signalling")]
public bool Signalling_ON { get; set; }
[Parameter("Signal_Arrows_ON", DefaultValue = false, Group = "Signalling")]
public bool Signal_Arrows_ON { get; set; }
[Parameter("Signal_Audio_ON", DefaultValue = false, Group = "Signalling")]
public bool Signal_Audio_ON { get; set; }
[Parameter("Signal_MediaFile", DefaultValue = "C:\\windows\\media\\reaction.mp3", Group = "Signalling")]
public string Signal_MediaFile { get; set; }
#endregion
#region Output lines
[Output("Lv1U", LineColor = "Gray")]
public IndicatorDataSeries Lv1U { get; set; }
[Output("Lv1D", LineColor = "Gray")]
public IndicatorDataSeries Lv1D { get; set; }
[Output("Lv2U", LineColor = "LightGray")]
public IndicatorDataSeries Lv2U { get; set; }
[Output("Lv2D", LineColor = "LightGray")]
public IndicatorDataSeries Lv2D { get; set; }
[Output("S1_K", LineColor = "Green", LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries S1_K { get; set; }
[Output("S1_D", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 1)]
public IndicatorDataSeries S1_D { get; set; }
[Output("S2_K", LineColor = "Aqua", LineStyle = LineStyle.DotsRare, Thickness = 1)]
public IndicatorDataSeries S2_K { get; set; }
[Output(" S2_D", LineColor = "Magenta", LineStyle = LineStyle.DotsRare, Thickness = 1)]
public IndicatorDataSeries S2_D { get; set; }
[Output("S3_K", LineColor = "Cyan", LineStyle = LineStyle.Lines, Thickness = 1)]
public IndicatorDataSeries S3_K { get; set; }
[Output(" S3_D", LineColor = "Orange", LineStyle = LineStyle.Lines, Thickness = 1)]
public IndicatorDataSeries S3_D { get; set; }
#endregion
private StochasticOscillator st1, st2, st3;
private Bars Bars_st2, Bars_st3;
private double offset = 1;
private bool a, b;
public int lv1u = 80, lv1d = 20, lv2u = 60, lv2d = 40, MARGIN = 3;
protected override void Initialize()
{
this.RefreshData();
st1 = null; st2 = null; st3 = null;
if (S1_Enabled) st1 = Indicators.StochasticOscillator(S1_KPeriods, S1_KSlowing, S1_DPeriods, S1_MaType);
if (S2_Enabled)
{
Bars_st2 = Chart.TimeFrame == S2_TF ? Bars : MarketData.GetBars(S2_TF);
while (Bars_st2.LoadMoreHistory() > 0) { };
st2 = Indicators.StochasticOscillator(Bars_st2, S2_KPeriods, S2_KSlowing, S2_DPeriods, S2_MaType);
}
if (S3_Enabled)
{
Bars_st3 = Chart.TimeFrame == S3_TF ? Bars : MarketData.GetBars(S3_TF);
while (Bars_st3.LoadMoreHistory() > 0) { };
st3 = Indicators.StochasticOscillator(Bars_st3, S3_KPeriods, S3_KSlowing, S3_DPeriods, S3_MaType);
}
}
public override void Calculate(int index)
{
Lv1U[index] = lv1u;
Lv1D[index] = lv1d;
Lv2U[index] = lv2u;
Lv2D[index] = lv2d;
if (S1_Enabled)
{
S1_K[index] = st1.PercentK[index];
S1_D[index] = st1.PercentD[index];
}
if (S2_Enabled)
{
var index2 = Bars_st2.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index]);
index2 = index2 == -1 ? Bars_st2.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) : index2;
if (index2 != -1)
{
S2_K[index] = st2.PercentK[index2];
S2_D[index] = st2.PercentD[index2];
}
}
if (S3_Enabled)
{
var index3 = Bars_st3.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index]);
index3 = index3 == -1 ? Bars_st3.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]) : index3;
if (index3 != -1)
{
S3_K[index] = st3.PercentK[index3];
S3_D[index] = st3.PercentD[index3];
}
}
if (S1_Enabled && Signalling_ON)
{
//deathX - BE
if (st1.PercentK.Last(2) > st1.PercentD.Last(2) && st1.PercentK.Last(1) < st1.PercentD.Last(1))
{
Print("Lst.PercentD.Last(1) {0}", st1.PercentD.Last(1));
Print("Lst.PercentD.Last(2) {0}", st1.PercentD.Last(2));
if (st1.PercentK.Last(2) > lv1u)
{
if (Signal_Arrows_ON)
Chart.DrawIcon("test" + Bars.OpenTimes.Last(1).ToString(), ChartIconType.DownArrow, Bars.OpenTimes.Last(1), Bars.HighPrices.Last(1) + (offset * Symbol.PipSize), "Tomato");
if (b == true && Signal_Audio_ON == true)
{
Notifications.PlaySound(Signal_MediaFile);
b = false;
a = true;
}
}
}
//goldenX - BU
if (st1.PercentK.Last(2) < st1.PercentD.Last(2) && st1.PercentK.Last(1) > st1.PercentD.Last(1))
{
Print("Lst.PercentD.Last(1) {0}", st1.PercentD.Last(1));
Print("Lst.PercentD.Last(2) {0}", st1.PercentD.Last(2));
if (st1.PercentK.Last(2) < lv1d)
{
if (Signal_Arrows_ON)
Chart.DrawIcon("test" + Bars.OpenTimes.Last(1).ToString(), ChartIconType.UpArrow, Bars.OpenTimes.Last(1), Bars.LowPrices.Last(1) - (offset * Symbol.PipSize), "Cyan");
if (a == true && Signal_Audio_ON == true)
{
Notifications.PlaySound(Signal_MediaFile);
a = false;
b = true;
}
}
}
}
}
}
}
GM
gmkenneyy
Joined on 20.03.2020 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: KF_Mtf_Stochastics_v2.algo
- Rating: 0
- Installs: 737
- Modified: 09/11/2022 22:59
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.