Category Trend  Published on 13/08/2020

Bollinger Bands Trend Free

Description

The Trading System uses Bollinger Bands. It will Buy Or Sell if the Bar close price upper or lower than Bollinger Bands.

PS: I changed source to use percent volume and use optimize, bellow is result

 

 

 

 


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 MyBollingerBands : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        [Parameter("BandPeriods", DefaultValue = 14)]
        public int BandPeriod { get; set; }
        [Parameter("Std", DefaultValue = 1.8)]
        public double std { get; set; }
        [Parameter("MAType")]
        public MovingAverageType MAType { get; set; }
        [Parameter("Initial Volume Percent", DefaultValue = 1, MinValue = 0)]
        public double InitialVolumePercent { get; set; }
        [Parameter("Stop Loss", DefaultValue = 100)]
        public int StopLoss { get; set; }
        [Parameter("Take Profit", DefaultValue = 100)]
        public int TakeProfit { get; set; }

        private BollingerBands boll;

        protected override void OnStart()
        {
            // Put your initialization logic here
            boll = Indicators.BollingerBands(Source, BandPeriod, std, MAType);
        }

        protected override void OnBar()
        {
            var volumne = Math.Floor(Account.Balance * 10 * InitialVolumePercent / 10000) * 10000;

            Print("Volume{0}", volumne);
            Print("Balance{0}", Account.Balance);
            Print("Equity{0}", Account.Equity);

            if (Bars.Last(2).Close > boll.Top.Last(2))
            {
                if (Bars.Last(1).Close > boll.Top.Last(1))
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumne, "ndnghiaBollinger", StopLoss, TakeProfit);
                }
                else
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volumne, "ndnghiaBollinger", StopLoss, TakeProfit);
                }
            }
            else if (Bars.Last(2).Close < boll.Bottom.Last(2))
            {
                if (Bars.Last(1).Close < boll.Bottom.Last(1))
                {

                    ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volumne, "ndnghiaBollinger", StopLoss, TakeProfit);
                }
                else
                {

                    ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumne, "ndnghiaBollinger", StopLoss, TakeProfit);
                }
            }


        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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


nghiand.amz's avatar
nghiand.amz

Joined on 06.07.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: MyBollingerBands.algo
  • Rating: 0
  • Installs: 2170
Comments
Log in to add a comment.
DA
davidmwabuka · 3 months ago

Congrat mate, its robust and it works very well. but i cant seem to undertsand the strategy it uses. 

nghiand.amz's avatar
nghiand.amz · 1 year ago

Why it doesn't work, does not  run or does the result is bad?

CL
claudio2002.cm · 2 years ago

Cool... The thing is, It doesn't work, could you update it?