Gold Scalper free

by vmalan95 in category Trend at 06/10/2021
Description

hi

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
´╗┐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;
        }
    }
}
Comments
0