Bollinger Bands Trend Free 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

 

 

 

 

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.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
        }
    }
}
Comments
0