It took me 6 nonstop hours to figure out something you could have told me in 6 minutes because I don't understand C# lol. I don't even understand the HasCrossedAbove method so I axed it entirely in favor of something simpler. This was my solution and it works to a degree I'm okay with but I'd like to see what your solution would have been. It's extremely crude I'm sure, but it's all I could come up with after pouring through material I didn't understand. Thanks again for the help.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, ScalePrecision = 0, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class StochasticCrossAlert : Indicator
{
private StochasticOscillator stoc;
bool b = true;
bool a = true;
[Parameter("Sound ON", DefaultValue = true)]
public bool PlaySound { get; set; }
[Parameter("Media File", DefaultValue = "c:\\windows\\media\\reaction.mp3")]
public string MediaFile { get; set; }
[Parameter("K_Periods", DefaultValue = 8, MinValue = 1)]
public int K_Period { get; set; }
[Parameter("Slow_K", DefaultValue = 3, MinValue = 2)]
public int Slow_K { get; set; }
[Parameter("D_Period", DefaultValue = 3, MinValue = 0)]
public int D_Period { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
public MovingAverageType MAType { get; set; }
[Output("%D", Color = Colors.Blue, PlotType = PlotType.Line, LineStyle = LineStyle.Lines)]
public IndicatorDataSeries Percent_D { get; set; }
[Output("%K", Color = Colors.Red)]
public IndicatorDataSeries Percent_K { get; set; }
protected override void Initialize()
{
// Initialize and create nested indicators
stoc = Indicators.StochasticOscillator(K_Period, Slow_K, D_Period, MAType);
}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] = ...
Percent_K[index] = stoc.PercentK.LastValue;
Percent_D[index] = stoc.PercentD.LastValue;
if (stoc.PercentK.LastValue > stoc.PercentD.LastValue && a == true && PlaySound == true)
{
Notifications.PlaySound(MediaFile);
a = false;
b = true;
}
if (stoc.PercentD.LastValue > stoc.PercentK.LastValue && b == true && PlaySound == true)
{
Notifications.PlaySound(MediaFile);
b = false;
a = true;
}
}
}
}
silverslasher_13
13 Feb 2016, 00:04
It took me 6 nonstop hours to figure out something you could have told me in 6 minutes because I don't understand C# lol. I don't even understand the HasCrossedAbove method so I axed it entirely in favor of something simpler. This was my solution and it works to a degree I'm okay with but I'd like to see what your solution would have been. It's extremely crude I'm sure, but it's all I could come up with after pouring through material I didn't understand. Thanks again for the help.
@silverslasher_13