Advanced Hedging and Scalping cBot free

by skoutz.rothchild in category Range at 23/01/2018
Description

An advanced version of the Hedging and Scalping cBot. It implements an automatic position scaling out logic and has good returns on many timeframes and time periods.  See below backtesting results on minute timeframe over a two years period.

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
´╗┐using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AdvancedHedgingandScalpingcBot : Robot
    {

        [Parameter("Volume", DefaultValue = 1000, MinValue = 1, Step = 1)]
        public int Volume { get; set; }
        private double _equity;
        private int noOfPositions = 4;
        private int pips = 2;
        protected override void OnStart()
        {
            _equity = Account.Balance;
            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BUY");
            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "SELL");
        }
        protected override void OnBar()
        {
            foreach (var position in Positions)
            {
                if (position.Pips > pips)
                {
                    ClosePosition(position);
                }
            }
            if (Positions.Count < noOfPositions)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BUY");
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "SELL");
            }


            int buyCount = 0;
            int sellCount = 0;
            foreach (var position in Positions)
            {
                if (position.TradeType == TradeType.Buy)
                    buyCount++;
                if (position.TradeType == TradeType.Sell)
                    sellCount++;
            }

            if (buyCount == 0 || sellCount == 0)
            {
                Volume += 1000;
                noOfPositions += 2;
                pips++;
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BUY");
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "SELL");
            }

            if (Account.Equity > _equity + Account.Equity / 100)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
                _equity = Account.Equity;
                Volume = 1000;
                noOfPositions = 4;
                pips = 2;
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "BUY");
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "SELL");
            }

        }

    }


}
Comments

naviallicer@gmail.com - January 24, 2018 @ 13:51

can you make  just a hedging bot like ea recovery zone

 

naviallicer@gmail.com - January 24, 2018 @ 13:57

can you write a code like this one?

 

thaiemoney - February 06, 2018 @ 12:34

Power Full Backtest

Thank you 

IandelMar - July 17, 2018 @ 01:41

Thanks a lot, im doing backtesting and sometimes really good, but i have time which my Account gettin zero. Can you please add Stopp Loss? What Pait do you use with timeframe? Thanks Ian

Sergii Bokancha - September 12, 2018 @ 06:33

Greeting to you skoutz.rothchild! I appreciate the work you sharing with others.

Can you please describe the exact logic of this code and how differently it performs compared to your first H&S cBot?

Thank you

ricky.global9 - December 25, 2018 @ 15:30

Good to Play With, not for real trade...

tyovev118 - March 31, 2020 @ 23:05

How do I stop the robot from opening more trades once the ones that are open get closed?

rickbeeke84 - July 16, 2021 @ 09:52

hello    how can i add a stoploss in this bot.   i like the bot  but i miss a stoploss to avoid blowing my account   

0