Bollinger Bands Trading Strategy free

by 4xdev.team in category Other at 05/12/2021
Description

Hey-ho! 

Let us introduce the cBot with a built-in BB indicator. This cool trading tool will help you to monitor price volatility.

 

Features

The BB strategy can:

  • Check ready-formed bars and current price position. You can select the right time to open a trade. 
  • Work in 3 modes: Current price and BB line crossing (Current Breakout), Closing of the last bar above/below the line (Close Above/Below), Price and the last crossed bar crossing (Bar Cross).
  • Manage positions. 
  • Calculate all the risks for the entire position.
  • Remove the Stop Loss level on the opening price after overcoming a certain distance thanks to the BreakEven option. In this case, your trade won’t be a loss-making one.

Note! You can select the BB line (Top or Bottom) and crossing type for every trade type. 

 

Parameters

We have equipped our EA with more than 14 additional parameters. So, you can configure the cBot according to your needs!

Note! Try the Bollinger Bands strategy on your demo account first before going live.


 

Other Products

Ichimoku Cloud System: 

PSAR Strategy: 

ADR Custom Indicator: 

Daily H/L Custom Indicator: 

 

Contact Info

Contact us via support@4xdev.com.

Check out our cozy Telegram blog for traders:https://t.me/Forexdev.  

Visit our website to find more tools and programming services:https://bit.ly/3BtyUap

Take a look at our YouTube channel:https://www.youtube.com/channel/UChsDb4Q8X2Vl5DJ7H8PzlHQ.   


 

Feel the heavenly pleasure of trading  — with 4xDev.


 

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 cAlgo.API;
using cAlgo.API.Indicators;
using System;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BbTradeSystem : Robot
    {
        public enum ENUM_TP_TYPE
        {
            Fixed = 0,
            RiskRatio = 1
        }
        public enum ENUM_RISK_SOURCE
        {
            Equity = 0,
            Balance = 1
        }

        public enum ENUM_LOT_TYPE
        {
            Fixed_Lot = 0,
            Percent = 1
        }
        public enum ENUM_CROSS_TYPE
        {
            Current_Breakout = 0,
            //Current breakout
            Close_Above_Below = 1,
            //Close Above/Below
            Bar_Cross = 2
            //Bar Cross
        }
        public enum ENUM_CROSS_LINE
        {
            Top_Line = 0,
            // Top Line
            Bottom_Line = 1
            // Bottom Line
        }
        public enum ENUM_CROSS_DIRECTION
        {
            Above = 0,
            // Above
            Below = 1
            // Below
        }

        #region Input BB Parameters

        [Parameter("BB Source", Group = "BB Parameters")]
        public DataSeries BBSeries { get; set; }

        [Parameter("BB Period", Group = "BB Parameters", DefaultValue = 20)]
        public int BBPeriods { get; set; }

        [Parameter("Bands Deviation", Group = "BB Parameters", DefaultValue = 2)]
        public double deviation { get; set; }

        [Parameter("MA Type", Group = "BB Parameters")]
        public MovingAverageType maType { get; set; }
        #endregion


        #region Input Trade Parameters

        [Parameter("Label", Group = "Trade Parameters", DefaultValue = "BB Trade System")]
        public string Label { get; set; }

        [Parameter("Cross Type", Group = "Trade Parameters", DefaultValue = ENUM_CROSS_TYPE.Current_Breakout)]
        public ENUM_CROSS_TYPE crossType { get; set; }
        [Parameter("Buy Cross Line", Group = "Trade Parameters", DefaultValue = ENUM_CROSS_LINE.Bottom_Line)]
        public ENUM_CROSS_LINE crossLineBuy { get; set; }
        [Parameter("Buy Cross Direction", Group = "Trade Parameters", DefaultValue = ENUM_CROSS_DIRECTION.Below)]
        public ENUM_CROSS_DIRECTION crossDirectBuy { get; set; }
        [Parameter("Sell Cross Line", Group = "Trade Parameters", DefaultValue = ENUM_CROSS_LINE.Top_Line)]
        public ENUM_CROSS_LINE crossLineSell { get; set; }
        [Parameter("Sell Cross Direction", Group = "Trade Parameters", DefaultValue = ENUM_CROSS_DIRECTION.Above)]
        public ENUM_CROSS_DIRECTION crossDirectSell { get; set; }

        [Parameter("Take Profit type", Group = "Trade Parameters", DefaultValue = ENUM_TP_TYPE.Fixed)]
        public ENUM_TP_TYPE tpType { get; set; }

        [Parameter("Stop Loss in pips", Group = "Trade Parameters", DefaultValue = 0)]
        public double SL { get; set; }

        [Parameter("Take Profit value", Group = "Trade Parameters", DefaultValue = 0)]
        public double TP { get; set; }

        [Parameter("Close on the opposite signal", Group = "Trade Parameters", DefaultValue = true)]
        public bool oppositeClose { get; set; }

        [Parameter("Max Orders", Group = "Trade Parameters", DefaultValue = 1)]
        public int maxOrders { get; set; }

        [Parameter("Use Reverse Trade", Group = "Trade Parameters", DefaultValue = true)]
        public bool reverseTrade { get; set; }

        #endregion
        #region Input Lot Size Parameters
        [Parameter("Lot Type", Group = "Lot Size", DefaultValue = ENUM_LOT_TYPE.Fixed_Lot)]
        public ENUM_LOT_TYPE lotType { get; set; }

        [Parameter("Risk Source", Group = "Lot Size", DefaultValue = ENUM_RISK_SOURCE.Balance)]
        public ENUM_RISK_SOURCE riskSource { get; set; }

        [Parameter("Risk/Lot Value", Group = "Lot Size", DefaultValue = 0.1)]
        public double risk { get; set; }
        #endregion
        #region Input Break Even Parameters
        [Parameter("Use BreakEven", Group = "BreakEven", DefaultValue = false)]
        public bool UseBE { get; set; }
        [Parameter("BreakEven Start(pips)", Group = "BreakEven", DefaultValue = 10)]
        public double BEStart { get; set; }

        [Parameter("BreakEven Profit(pips)", Group = "BreakEven", DefaultValue = 0)]
        public double BEProfit { get; set; }
        #endregion

        private BollingerBands BB;

        protected override void OnStart()
        {
            BB = Indicators.BollingerBands(BBSeries, BBPeriods, deviation, maType);
            // Put your initialization logic here
        }

        double bbPrevTop;
        double bbPrevBott;
        double pricePrev;
        DateTime lastTrade;


        protected override void OnTick()
        {
            if (UseBE)
                BreakEven();

            if (lastTrade != Bars.OpenTimes.Last(0))
            {
                if (CheckCondition(TradeType.Buy) && CalculateOrders() < maxOrders)
                {
                    if (oppositeClose)
                        CloseOrders(TradeType.Sell);
                    lastTrade = Bars.OpenTimes.Last(0);
                    OpenOrder(TradeType.Buy);
                }
                if (CheckCondition(TradeType.Sell) && CalculateOrders() < maxOrders)
                {
                    if (oppositeClose)
                        CloseOrders(TradeType.Buy);
                    lastTrade = Bars.OpenTimes.Last(0);
                    OpenOrder(TradeType.Sell);
                }
            }
            bbPrevTop = BB.Top.Last(0);
            bbPrevBott = BB.Bottom.Last(0);
            pricePrev = Bars.ClosePrices.Last(0);

        }

        bool CheckOrder(TradeType type)
        {
            if (Positions.FindAll(Label, Symbol, type) != null)
                return false;
            return true;
        }

        int CalculateOrders()
        {
            return Positions.FindAll(Label, Symbol).Length;
        }

        void CloseOrders(TradeType type)
        {
            if (reverseTrade)
                type = type == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            foreach (var pos in Positions.FindAll(Label, Symbol, type))
            {
                ClosePosition(pos);
            }
        }

        void OpenOrder(TradeType type)
        {
            if (reverseTrade)
                type = type == TradeType.Buy ? TradeType.Sell : TradeType.Buy;

            double op;
            double tp = tpType == ENUM_TP_TYPE.Fixed ? TP : SL * TP;
            double sl;

            double source = riskSource == ENUM_RISK_SOURCE.Balance ? Account.Balance : Account.Equity;

            double volumeInUnits = 0;
            if (lotType == ENUM_LOT_TYPE.Fixed_Lot)
                volumeInUnits = Symbol.QuantityToVolumeInUnits(risk);
            else
                volumeInUnits = CalculateVolume(SL, risk, source);

            if (volumeInUnits == -1)
                return;
            ExecuteMarketOrder(type, SymbolName, volumeInUnits, Label, SL, TP);
        }


        private void BreakEven()
        {
            if (!UseBE)
                return;

            foreach (var pos in Positions.FindAll(Label, SymbolName))
            {
                if (pos.TradeType == TradeType.Buy)
                {
                    if (Symbol.Ask >= pos.EntryPrice + BEStart * Symbol.PipSize && (pos.StopLoss < pos.EntryPrice + BEProfit * Symbol.PipSize || pos.StopLoss == null))
                    {
                        ModifyPosition(pos, pos.EntryPrice + BEProfit * Symbol.PipSize, pos.TakeProfit);
                    }
                }
                if (pos.TradeType == TradeType.Sell)
                {
                    if (Symbol.Bid <= pos.EntryPrice - BEStart * Symbol.PipSize && (pos.StopLoss > pos.EntryPrice - BEProfit * Symbol.PipSize || pos.StopLoss == null))
                    {
                        ModifyPosition(pos, pos.EntryPrice + BEProfit * Symbol.PipSize, pos.TakeProfit);
                    }
                }
            }
        }

        bool CheckCondition(TradeType trade)
        {
            int shift = crossType == ENUM_CROSS_TYPE.Current_Breakout ? 0 : 1;

            double bb;
            double bbPrev;

            if (trade == TradeType.Buy)
            {
                if (crossLineBuy == ENUM_CROSS_LINE.Top_Line)
                    bb = BB.Top.Last(shift);
                else
                    bb = BB.Bottom.Last(shift);
                if (crossType == ENUM_CROSS_TYPE.Current_Breakout)
                {
                    if (crossLineBuy == ENUM_CROSS_LINE.Top_Line)
                        bbPrev = bbPrevTop;
                    else
                        bbPrev = bbPrevBott;
                    if (crossDirectBuy == ENUM_CROSS_DIRECTION.Above)
                    {
                        if (Bars.ClosePrices.Last(0) < bb && pricePrev > bbPrev)
                            return true;
                        else
                            return false;
                    }
                    if (crossDirectBuy == ENUM_CROSS_DIRECTION.Below)
                    {
                        if (Bars.ClosePrices.Last(0) > bb && pricePrev < bbPrev)
                            return true;
                        else
                            return false;
                    }
                }
                if (crossType == ENUM_CROSS_TYPE.Close_Above_Below)
                {
                    if (crossDirectBuy == ENUM_CROSS_DIRECTION.Above)
                    {
                        if (Bars.ClosePrices.Last(1) > bb)
                            return true;
                        else
                            return false;
                    }
                    if (crossDirectBuy == ENUM_CROSS_DIRECTION.Below)
                    {
                        if (Bars.ClosePrices.Last(1) < bb)
                            return true;
                        else
                            return false;
                    }
                }
                if (crossType == ENUM_CROSS_TYPE.Bar_Cross)
                {
                    if (Bars.LowPrices.Last(1) < bb && Bars.HighPrices.Last(1) > bb)
                        return true;
                    else
                        return false;
                }
            }


            if (trade == TradeType.Sell)
            {
                if (crossLineSell == ENUM_CROSS_LINE.Top_Line)
                    bb = BB.Top.Last(shift);
                else
                    bb = BB.Bottom.Last(shift);
                if (crossType == ENUM_CROSS_TYPE.Current_Breakout)
                {
                    if (crossLineSell == ENUM_CROSS_LINE.Top_Line)
                        bbPrev = bbPrevTop;
                    else
                        bbPrev = bbPrevBott;
                    if (crossDirectSell == ENUM_CROSS_DIRECTION.Above)
                    {
                        if (Bars.ClosePrices.Last(0) < bb && pricePrev > bbPrev)
                            return true;
                        else
                            return false;
                    }
                    if (crossDirectSell == ENUM_CROSS_DIRECTION.Below)
                    {
                        if (Bars.ClosePrices.Last(0) > bb && pricePrev < bbPrev)
                            return true;
                        else
                            return false;
                    }
                }
                if (crossType == ENUM_CROSS_TYPE.Close_Above_Below)
                {
                    if (crossDirectSell == ENUM_CROSS_DIRECTION.Above)
                    {
                        if (Bars.ClosePrices.Last(1) > bb)
                            return true;
                        else
                            return false;
                    }
                    if (crossDirectSell == ENUM_CROSS_DIRECTION.Below)
                    {
                        if (Bars.ClosePrices.Last(1) < bb)
                            return true;
                        else
                            return false;
                    }
                }
                if (crossType == ENUM_CROSS_TYPE.Bar_Cross)
                {
                    if (Bars.LowPrices.Last(1) < bb && Bars.HighPrices.Last(1) > bb)
                        return true;
                    else
                        return false;
                }
            }
            return false;
        }
        private double CalculateVolume(double stopLossPips, double riskSize, double source)
        {
            // source = Account.Balance or Account.Equity
            double riskPerTrade = source * riskSize / 100;
            double totalPips = stopLossPips;

            double _volume;
            double exactVolume = riskPerTrade / (Symbol.PipValue * totalPips);
            if (exactVolume >= Symbol.VolumeInUnitsMin)
            {
                _volume = Symbol.NormalizeVolumeInUnits(exactVolume);
            }
            else
            {
                _volume = -1;
                Print("Not enough Equity to place minimum trade, exactVolume " + exactVolume + " is not >= Symbol.VolumeInUnitsMin " + Symbol.VolumeInUnitsMin);
            }
            return _volume;
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}
Comments

diepiosm - December 08, 2021 @ 08:39

Hello! I would like to thank the author for this helpful web article, as I have really enjoyed it! And also I think that one more link will be really helpful to lthose who are interested in playing a variety of interesting games krunkerio
 

banasher336 - April 13, 2022 @ 21:24

The cheap writers also gave plagiarised or refreshed essays that don't work in universities. They might also fail to oxessays reviews or deliver late, which can determine the student's final grades. So even if a budget is a constraint, it is always wise to avoid investing money in cheap essay writing services

TheMC - June 01, 2022 @ 10:24

Hi,
congratulations for the excellent work.
However, it seems to me that the bot does not close positions at the opposite signal.

lvh16570 - July 06, 2022 @ 14:26

If you are intended to pass and become Nutanix NCA-5.15 Nutanix Certified Associate (NCA) 5.15 exam certified then enrolled in our preparation program today and avail the intelligently designed actual questions https://www.dumpsbuddy.com/nca-5-20-certification-exam.html in three easy and accessible formats, PDF file test. Dumpsbuddy.com is the best platform, which offers Braindumps for Nutanix Certified Associate NCA-5.15 Nutanix Certified Associate (NCA) 5.15 Certification exam duly prepared by experts. Our Nutanix Certified Associate (NCA) 5.15 exam material is excellent to NCA-5.15 pass exam in a week.

ciaraveum008 - August 25, 2022 @ 14:39

It is really fulfilling that some could see that the UW School of Drama values joined your advantage. Check this https://www.passivevoicefixer.com/facts-about-active-and-passive-voice-checker/ it will help you a ton. In a little while we would have the decision to see all the in a like manner shocking convincing craftsmanship.

nutriplan042016 - September 02, 2022 @ 11:08

A student should wearisome undertaking to assist with additional data and help from his enlightening plan. Visit https://www.checkmysentence.com/ for additional subtleties. Other than zeroing in on the assessments, they should other than being especially occupied with the extracurricular examinations.

nutriplan042016 - September 02, 2022 @ 11:12

Direct from the most strong early phase season of music-creation approaches for young people, the watchmen should give close thought. Click http://www.copyrightchecker.net/ to get bungle free work on time. Specifically, they should make control picking the best instructor.

ciaraveum008 - October 08, 2022 @ 15:22

It was genuinely perplexing and bantering with to look at in any way at all of the exercises of Qatar ExxonMobil. Try this www.paragraphchecker.com/check-my-paragraph-for-errors/ site for more ideas. Really take a gander at this to get colossal assistance with it. I especially visited Qatar to invite this festival.

ciaraveum008 - October 08, 2022 @ 15:29

Consider what things as shown by a general perspective draw in you and what you love to do ought to be as shown by an overall viewpoint attempted to go going before picking any straightforwardness program. Visit http://www.englishgrammarcheck.org/advantages-and-disadvantages-of-grammar-check-english-oriented-applications/ for additional bits of information concerning illustrating. consider what kind of calling course you expect later and what your full-scale work fights are.

dimaciaa - October 10, 2022 @ 14:21

Every day I play  to it, but I never get goosebumps. Officially a big fan of Drift Hunter .

0