Category Other  Published on 19/06/2016

Scalper Signal

Description

A visual way to help determine whether to buy or sell against a pivot level (indicator does not repaint). Gold painted bars mark a “pivot high” or “pivot low.” Signal is confirmed after 3 higher closes or 3 lower closes.

The faster the time frame, the faster the confirmation. Red dots indicate a continuing downtrend confirmation while Green dots mark a continuing uptrend confirmation.

The indicator measures price action when you trade. It is mainly used for trading stocks and futures, but it can also be used for currency crosses.

Available Inputs

  • Sensitivity (High <-[1...3]-> Low) - sets the sensitivity of the generated signals. Higher sensitivity generates more signals.
  • Signal Bar Color

Referencing the indicator from an cAlgo robot is as simple as referencing other standard cTrader indicators. The reference points are as follows:

  • Buy
  • Sell
  • SignalBarHigh
  • SignalBarLow

Please give me feedback, if you find it useful and/or have any suggestions for further development.


Also check out my MedianRenko Ultimate indicator for cTrader & cAlgo:


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 ScalperSignal : Indicator
    {
        [Parameter("Sensitivity", DefaultValue = 2, MinValue = 1, MaxValue = 3, Step = 1)]
        public int Sensitivity { get; set; }

        [Parameter("Signal Bar Color", DefaultValue = "Gold")]
        public string SignalBarColor { get; set; }

        [Output("Buy", Color = Colors.LimeGreen, Thickness = 7, PlotType = PlotType.Points)]
        public IndicatorDataSeries BuyIndicator { get; set; }

        [Output("Sell", Color = Colors.Red, Thickness = 7, PlotType = PlotType.Points)]
        public IndicatorDataSeries SellIndicator { get; set; }

        [Output("SignalBarHigh", Color = Colors.Gold, Thickness = 1, PlotType = PlotType.Points)]
        public IndicatorDataSeries SignalBarHigh { get; set; }

        [Output("SignalBarLow", Color = Colors.Gold, Thickness = 1, PlotType = PlotType.Points)]
        public IndicatorDataSeries SignalBarLow { get; set; }

        enum Signals
        {
            None,
            Buy,
            Sell
        }

        private Colors signalBarColor;
        private Signals lastSignal;
        private DateTime lastTime;
        private AverageTrueRange ATR;

        protected override void Initialize()
        {
            if (!Enum.TryParse<Colors>(SignalBarColor, out signalBarColor))
                signalBarColor = Colors.Gold;

            lastSignal = Signals.None;
            lastTime = new DateTime();
            lastTime = MarketSeries.OpenTime[MarketSeries.Close.Count - 1];
        }

        public override void Calculate(int index)
        {
            if (!NewBar(index) || (index < 6))
                return;

            ATR = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);

            double bs = BuySignal(index);
            double ss = SellSignal(index);

            if (bs > 0)
            {
                BuyIndicator[index] = bs;
                SignalBarHigh[index - 3] = MarketSeries.High[index - 3];
                SignalBarLow[index - 3] = MarketSeries.Low[index - 3];
                ChartObjects.DrawLine("SignalBar" + (index - 3), index - 3, SignalBarHigh[index - 3], index - 3, SignalBarLow[index - 3], Colors.Gold, 3, LineStyle.Solid);
            }
            else if (ss > 0)
            {
                SellIndicator[index] = ss;
                SignalBarHigh[index - 3] = MarketSeries.High[index - 3];
                SignalBarLow[index - 3] = MarketSeries.Low[index - 3];
                ChartObjects.DrawLine("SignalBar" + (index - 3), index - 3, SignalBarHigh[index - 3], index - 3, SignalBarLow[index - 3], Colors.Gold, 3, LineStyle.Solid);

            }
        }

        private double SellSignal(int index)
        {
            bool ok = true;

            if (Sensitivity > 2)
                if (MarketSeries.High[index - 6] >= MarketSeries.High[index - 5])
                    ok = false;

            if (Sensitivity > 1)
                if (MarketSeries.High[index - 5] >= MarketSeries.High[index - 4])
                    ok = false;

            if (Sensitivity > 0)
                if (MarketSeries.High[index - 4] >= MarketSeries.High[index - 3])
                    ok = false;

            if (ok)
                if (MarketSeries.Close[index - 2] < MarketSeries.High[index - 3])
                    if (MarketSeries.Close[index - 1] < MarketSeries.Low[index - 3])
                    {
                        lastSignal = Signals.Sell;
                        return (MarketSeries.High[index] + ATR.Result[index]);
                    }

            return (double.NaN);
        }

        private double BuySignal(int index)
        {
            bool ok = true;

            if (Sensitivity > 2)
                if (MarketSeries.Low[index - 6] <= MarketSeries.Low[index - 5])
                    ok = false;

            if (Sensitivity > 1)
                if (MarketSeries.Low[index - 5] <= MarketSeries.Low[index - 4])
                    ok = false;

            if (Sensitivity > 0)
                if (MarketSeries.Low[index - 4] <= MarketSeries.Low[index - 3])
                    ok = false;

            if (ok)
                if (MarketSeries.Close[index - 2] > MarketSeries.Low[index - 3])
                    if (MarketSeries.Close[index - 1] > MarketSeries.High[index - 3])
                    {
                        lastSignal = Signals.Buy;
                        return (MarketSeries.Low[index] - ATR.Result[index]);
                    }

            return (double.NaN);
        }

        private bool NewBar(int index)
        {
            if (lastTime != MarketSeries.OpenTime[index])
            {
                lastTime = MarketSeries.OpenTime[index];
                return true;
            }

            return false;
        }
    }
}


AR
arturzas

Joined on 15.06.2016

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: ScalperSignal.algo
  • Rating: 5
  • Installs: 14403
Comments
Log in to add a comment.
jani's avatar
jani · 5 years ago

Thank you for sharing your code!

I'm looking for a brief and fool proof way to make my custom indicators more efficient.

I think very good way is to let indicator to make calculations only on a new bar, as you have done in your code.

 

I have used following code for that:

  int lastindex = 0;
    
            if (IsLastBar)
            {
                if (index != lastindex)
                    lastindex = index;
                else
                    return;
            }

Any opinion about this one?

TR
treeaman · 6 years ago

Your Scalper Signal

Seting

Error CS0414: The field 'cAlgo.ScalperSignal.lastSignal' is assigned but its value is never used