New condition to Stochastic

Created at 29 Oct 2020, 18:30
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
BU

bursonik

Joined 17.05.2016

New condition to Stochastic
29 Oct 2020, 18:30


Hi,
please help me add a new condition to this indicator. I would like the arrow to form if the conditions that are present are met, plus one more - when the candle closes below/above the set average EMA.

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
 
namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class StochasticEntryMarkerDax : 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("UP Level", DefaultValue = 80)]
        public int Up_Level { get; set; }
 
        [Parameter("Down Level", DefaultValue = 20)]
        public int Down_Level { get; set; }
 
        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }
 
        private StochasticOscillator _stochastic;
 
        private double offset = 25;
 
        protected override void Initialize()
        {
            // Initialize and create nested indicators
            _stochastic = Indicators.StochasticOscillator(kPeriods, kSlowing, dPeriods, maType);
 
        }
 
        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...
            var bars = MarketData.GetBars(Chart.TimeFrame);
 
            //dedcloss
            if (_stochastic.PercentK.Last(2) > _stochastic.PercentD.Last(2) && _stochastic.PercentK.Last(1) < _stochastic.PercentD.Last(1))
            {
                Print("_stochastic.PercentD.Last(1) {0}", _stochastic.PercentD.Last(1));
                Print("_stochastic.PercentD.Last(2) {0}", _stochastic.PercentD.Last(2));
                if (_stochastic.PercentK.Last(2) > Up_Level)
                {
                    Chart.DrawIcon("test" + bars.OpenTimes.Last(1).ToString(), ChartIconType.DownArrow, bars.OpenTimes.Last(1), bars.HighPrices.Last(1) + (offset * Symbol.PipSize), "Red");
                }
 
            }
 
            //goldencloss
            if (_stochastic.PercentK.Last(2) < _stochastic.PercentD.Last(2) && _stochastic.PercentK.Last(1) > _stochastic.PercentD.Last(1))
            {
 
                Print("_stochastic.PercentD.Last(1) {0}", _stochastic.PercentD.Last(1));
                Print("_stochastic.PercentD.Last(2) {0}", _stochastic.PercentD.Last(2));
                if (_stochastic.PercentK.Last(2) < Down_Level)
                {
                    Chart.DrawIcon("test" + bars.OpenTimes.Last(1).ToString(), ChartIconType.UpArrow, bars.OpenTimes.Last(1), bars.LowPrices.Last(1) - (offset * Symbol.PipSize), "Yellow");
                }
 
            }
        }
    }
}

 


@bursonik