Category Other  Published on 02/05/2014

Zephyn Scalper

Description

Uses simple moving average and stochastic oscillator to find a good trade opportunity

testet using GBPUSD symbol and 5m chart.

Use at own risk


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ZephynScalper : Robot
    {
        [Parameter("Periods SMA", DefaultValue = 35)]
        public int Periods_SMA { get; set; }

        [Parameter("Source SMA")]
        public DataSeries Source_SMA { get; set; }

        [Parameter("TakeProfit", DefaultValue = 30, MinValue = 1)]
        public int TakeProfit { get; set; }

        [Parameter("Stop Loss", DefaultValue = 50, MinValue = 1)]
        public int StopLoss { get; set; }

        [Parameter("Trail start", DefaultValue = 12, MinValue = 1)]
        public int Trail_start { get; set; }
        [Parameter("Trail", DefaultValue = 8, MinValue = 1)]
        public int Trail { get; set; }

        [Parameter("Volume", DefaultValue = 10000, MinValue = 10000)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        [Parameter("K Periods", DefaultValue = 5)]
        public int KPeriods { get; set; }

        [Parameter("D Periods", DefaultValue = 3)]
        public int DPeriods { get; set; }

        [Parameter("K Slowing", DefaultValue = 3)]
        public int K_Slowing { get; set; }

        private bool Sellingongoing = false;
        private bool Buyingongoing = false;
        private int OpenTrades = 0;
        double tradePrice;

        private SimpleMovingAverage _SMA;
        private StochasticOscillator _SOC;

        protected override void OnStart()
        {
            _SMA = Indicators.SimpleMovingAverage(Source_SMA, Periods_SMA);
            _SOC = Indicators.StochasticOscillator(KPeriods, K_Slowing, DPeriods, MaType);

            Positions.Closed += PositionsOnClosed;
        }


        protected override void OnTick()
        {
            //Print("Ask: " + Symbol.Ask);
            //købs pris

            //Print("Bid: " + Symbol.Bid);
            //salgs pris

            //Print(_SMA.Result.LastValue);
            //Print("D" + _SOC.PercentD.LastValue);
            //Print("K" + _SOC.PercentK.LastValue);


            foreach (var _p in Positions.FindAll("ZephynScalper", Symbol, TradeType.Buy))
            {
                if (_p.Pips > Trail_start)
                {
                    if (tradePrice < Symbol.Bid)
                    {
                        double NewStopLoss = Symbol.Ask - Trail * Symbol.PipSize;
                        ModifyPosition(_p, NewStopLoss, _p.TakeProfit.Value);
                        tradePrice = Symbol.Ask;

                        //Print("Stop loss: " + NewStopLoss);
                        //Print("Current price: " + Symbol.Ask);
                    }
                }
            }

            foreach (var _p2 in Positions.FindAll("ZephynScalper", Symbol, TradeType.Sell))
            {
                if (_p2.Pips > Trail_start)
                {
                    if (tradePrice > Symbol.Ask)
                    {
                        double NewStopLoss = Symbol.Bid + Trail * Symbol.PipSize;
                        ModifyPosition(_p2, NewStopLoss, _p2.TakeProfit.Value);
                        tradePrice = Symbol.Bid;
                    }
                }
            }

            if (_SMA.Result.LastValue < Symbol.Bid)
            {

                if (_SOC.PercentD.LastValue < 20)
                {
                    if (_SOC.PercentK.LastValue < 20)
                    {
                        if (_SOC.PercentK.LastValue > _SOC.PercentD.LastValue)
                        {
                            if (Buyingongoing == false)
                            {
                                Open(TradeType.Buy);
                                tradePrice = Symbol.Bid;
                                Buyingongoing = true;
                            }
                        }
                    }
                }

            }

            else if (_SMA.Result.LastValue > Symbol.Ask)
            {

                if (_SOC.PercentD.LastValue > 80)
                {
                    if (_SOC.PercentK.LastValue > 80)
                    {
                        if (_SOC.PercentK.LastValue < _SOC.PercentD.LastValue)
                        {
                            if (Sellingongoing == false)
                            {
                                Open(TradeType.Sell);
                                tradePrice = Symbol.Ask;
                                Sellingongoing = true;
                            }
                        }
                    }
                }



            }

        }

        private void Open(TradeType tradeType)
        {
            // var position = Positions.Find("ZephynScalper", Symbol, tradeType);

            // if (position == null)
            //     ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", StopLoss, TakeProfit);
            if (OpenTrades < 2)
            {
                ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", null, TakeProfit);
                OpenTrades++;
            }

        }

        private void PositionsOnClosed(PositionClosedEventArgs args)
        {
            var position = args.Position;
            //Print("Position closed with {0} profit", position.GrossProfit);
            if (position.Label.ToString() == "ZephynScalper")
            {
                OpenTrades--;
            }

            if (position.TradeType == TradeType.Sell)
            {
                Sellingongoing = false;
            }

            if (position.TradeType == TradeType.Buy)
            {
                Buyingongoing = false;
            }

            if (OpenTrades < 0)
                OpenTrades = 0;

        }


        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


ZE
Zephyn

Joined on 16.02.2014

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Zephyn Scalper.algo
  • Rating: 0
  • Installs: 5679
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
hennies's avatar
hennies · 3 years ago

Hi Mark,

I must congratulate you! Not many bots out there that functions as well as yours!. I notice ZSII has been removed as I am referring to your 2nd version.

Please drop me a line and we can share some notes and perhards help each other improve our bots.

Regards,

Hennie Smith

hennies1959@gmail.com

 

MA
manwasr · 8 years ago

The backtest result are scaring me(too good to be true).

+189%, something seems off.

Cheers though.

TY
tynamite · 10 years ago

Can anybody of the users say something about the results, please ?

Thanks !

AY
aysos75 · 10 years ago

Ne pas oublier aussi de modifier dans la fonction Open(TradeType tradeType)

ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", null, TakeProfit);

par

ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", StopLoss, TakeProfit);

AY
aysos75 · 10 years ago

Le code calculant le nouveau StopLoss est erroné :

à la place de 

foreach (var _p in Positions.FindAll("ZephynScalper", Symbol, TradeType.Buy))

            {

                if (_p.Pips > Trail_start)

                {

                    if (tradePrice < Symbol.Bid)

                    {

                        double NewStopLoss = Symbol.Ask - Trail * Symbol.PipSize;

                        ModifyPosition(_p, NewStopLoss, _p.TakeProfit.Value);

                        tradePrice = Symbol.Ask;

 

                        //Print("Stop loss: " + NewStopLoss);

                        //Print("Current price: " + Symbol.Ask);

                    }

                }

            }

 

            foreach (var _p2 in Positions.FindAll("ZephynScalper", Symbol, TradeType.Sell))

            {

                if (_p2.Pips > Trail_start)

                {

                    if (tradePrice > Symbol.Ask)

                    {

                        double NewStopLoss = Symbol.Bid + Trail * Symbol.PipSize;

                        ModifyPosition(_p2, NewStopLoss, _p2.TakeProfit.Value);

                        tradePrice = Symbol.Bid;

                    }

                }

            }

 

écrire :

foreach (var _p in Positions.FindAll("ZephynScalper", Symbol, TradeType.Buy))

            {

                if (_p.Pips > Trail_start)

                {

                    if (tradePrice < Symbol.Bid)

                    {

                        double NewStopLoss = _p.StopLoss.Value + Trail * Symbol.PipSize;

                        ModifyPosition(_p, NewStopLoss, _p.TakeProfit.Value);

                        tradePrice = Symbol.Ask;

 

                        //Print("Stop loss: " + NewStopLoss);

                        //Print("Current price: " + Symbol.Ask);

                    }

                }

            }

 

            foreach (var _p2 in Positions.FindAll("ZephynScalper", Symbol, TradeType.Sell))

            {

                if (_p2.Pips > Trail_start)

                {

                    if (tradePrice > Symbol.Ask)

                    {

                        double NewStopLoss = _p2.StoLoss.Value - Trail * Symbol.PipSize;

                        ModifyPosition(_p2, NewStopLoss, _p2.TakeProfit.Value);

                        tradePrice = Symbol.Bid;

                    }

                }

            }

 

AY
aysos75 · 10 years ago

robot Zephyn sclaper not closing the losers where this apparent performance positions. If we had a look at equity, we see that it is far from being efficient.

TR
tradermatrix · 10 years ago

ligne 158 

remplacer null  par StopLoss

 private void Open(TradeType tradeType)

        {

            // var position = Positions.Find("ZephynScalper", Symbol, tradeType);

 

            // if (position == null)

            //     ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", StopLoss, TakeProfit);

            if (OpenTrades < 2)

            {

                ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", null, TakeProfit);

  ExecuteMarketOrder(tradeType, Symbol, Volume, "ZephynScalper", StopLoss, TakeProfit);

                OpenTrades++;

 }

 

        }

////////////////////////////////////////////////

mais vous devrez regler  et changer certains  parametres du robot

bons trades

Marc

           

 

OD
oddieee · 10 years ago

hi, what parameters are you using on GBPUSD to be profitable?

Please email me, oddieeee@gmail.com.

Thanks!

IM
imWald · 10 years ago

Hi

missing the source code, I like to optimize the code by my self...

Robert