ZigZagBot free

by kkostaki in category Trend at 29/08/2012
Description

Strategy using ZigZag Indicator. 

The zigzag is an Indicator that is usually used as a filter of small price momements.

/algos/indicators/show/157

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
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: cAlgo
//#reference: ..\Indicators\ZigZag.algo

using cAlgo.API;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class ZigZagCycleBot : Robot
    {
        private Position _position;
        private ZigZag _zigZag;
        private double _prevValue;


        [Parameter(DefaultValue = 12)]
        public int ZzDepth { get; set; }

        [Parameter(DefaultValue = 550)]
        public int StopLoss { get; set; }

        [Parameter(DefaultValue = 5)]
        public int ZzDeviation { get; set; }

        [Parameter(DefaultValue = 3)]
        public int ZzBackStep { get; set; }

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


        protected override void OnStart()
        {
            _zigZag = Indicators.GetIndicator<ZigZag>(ZzDepth, ZzDeviation, ZzBackStep);
        }

        protected override void OnBar()
        {
            if (Trade.IsExecuting)
                return;

            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;


            double lastValue = _zigZag.Result.LastValue;

            if (!double.IsNaN(lastValue))
            {

                // Buy                
                if (lastValue < _prevValue && !isLongPositionOpen)
                {
                    ClosePosition();
                    Buy();
                }
                // Sell
                else if (lastValue > _prevValue && _prevValue > 0.0 && !isShortPositionOpen)
                {
                    ClosePosition();
                    Sell();
                }

                _prevValue = lastValue;
            }
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            _position = openedPosition;
            Trade.ModifyPosition(openedPosition, GetAbsoluteStopLoss(openedPosition, StopLoss), null);
        }

        private void ClosePosition()
        {
            if (_position == null)
                return;
            Trade.Close(_position);
            _position = null;
        }

        private void Buy()
        {
            Trade.CreateBuyMarketOrder(Symbol, Volume);
        }

        private void Sell()
        {
            Trade.CreateSellMarketOrder(Symbol, Volume);
        }

        private double? GetAbsoluteStopLoss(Position position, int stopLoss)
        {
            return position.TradeType == TradeType.Buy ? position.EntryPrice - Symbol.PipSize * stopLoss : position.EntryPrice + Symbol.PipSize * stopLoss;
        }

    }
}
Comments

tradermatrix - August 30, 2012 @ 10:13

bonjour apres plusieurs essais d enregistrement par coller copier ou downloab le resultat est :"creation échouée" error : the type or namespace name'zigzag could not be found (are you missing a using directive or an assembly reference?) l erreur est ici private ZigZag_zigzag; merci de votre comprehension cordialement TRADERMATRIX

tomolo - March 05, 2013 @ 19:36

I'm having the same problem, it might help if you post in English. Do you have a solution now? I cant get any of the indicators i build to work with the robots because of this name not found issue

kkostaki - March 06, 2013 @ 10:36

Please download again. I added the zigzag.cs indicator, so you need to build that first and it should work.

Alex5566 - March 25, 2013 @ 18:55

im new to algo, after download zigzag robot, where should i put it to ?

cAlgo_Fanatic - March 26, 2013 @ 13:00

Please click on the link "How to Install" in the Robots section: /algos/robots for information.

traderfx - April 30, 2013 @ 17:54

Bot doesn't work. Build Failed: The type or namespace 'ZigZag' could not be found (are you missing a using directive or an assembly reference?) Line 12: private ZigZag _zigZag; I have the ZigZag indicator that you mentioned is required. P.S: Don't the bots that are uploaded here go through a basic check to see if they atleast work before uploading them?

cAlgo_Fanatic - May 07, 2013 @ 14:49

Please remove the first line: //#reference: ..\Indicators\ZigZag.algo and add the reference by clicking on the button Add Reference next to build.

scalpit - May 24, 2013 @ 17:08

Hi. I've built the ZigZag indicator and the ZigZag bot. Also removed the first reference line and added the right reference. However when I run the bot on a chart (or backtesting), I get the following error: "Crashed in OnStart with ArgumentException; Incorrect parameters count. Parameter name:parameterValues" Any idea what is going wrong please? Great indicator BTW!

adaled - May 24, 2013 @ 17:26

Hi, I think you need to download it again. It works fine for me.

scalpit - May 25, 2013 @ 09:34

Thanks, it is working now... Although not profitable in back testing. Perhaps it needs some additional filters like only trade at certain times of the day, add a trailing stop etc...

aysos75 - June 29, 2014 @ 13:58

ZigzagCycleBot gives good results: 

EURUSD, H1, 01/01/2014 to 29/06/2014, zzDepth = 12 StopLoss = 550 ZzDeviation = 5, ZzBackStep = 3, Volume = 100000

matfx - June 30, 2014 @ 06:25

Thanks Abdallah will try your setting.

matfx - June 30, 2014 @ 06:58

I try backtesting it on eurusd and eurcad H1 chart give good result.

boyrayza - August 08, 2018 @ 10:15

HI. So Who Have a new Full Version for this EA?

Please sent  It works Source Code for me. 

Thank you all ^0^

2.5