Replies

kojomidoji
27 Dec 2021, 16:00

RE:

kojomidoji said:

Hello may i have someone getting me codes for price  crossovers.  1. Where the price crosses the upper Bollinger band from below 2. Where the price  crosses the same upper Bollinger band from above. 

The codes i have gotten from the forum so far only deal generally  with the price just closing greater than the bands.

Hello amusleh,

So many for the reply and the codes. .

I have added the codes accordingly but unfortunately the cbot could not detect many of the signals that meet the conditions and the rules set in the strategy as shown below 

1. Buy conditions:  Bollinger bands Bulge + Bollinger bottom band crossover from below + RSI less or equal to 30%

2. Sell conditions:  Bollinger bands Bulge + Bollinger top band crossover from above + RSI greater or equal to 70%

 

During 01/07/2021 to 6/12/2021 backtesting periods the following have been observed?

 

1. many potential signals (Buy and Sell) were not detected by the cbot  as shown in the attached screenshots signals 1 to 6.

2. also attached are some of the the few signals  detected and captured by the cbot

So i will be most grateful if you will be able to explain why the cbot could not capture majority of the potential signals based on the strategy rules as shown .

Also find below the sections of the Buy and sell codes:

"// Function to find the buy signals

        private bool BuyEntry(int index)
        {

            // We use this variable to return in the function
            bool result = false;

            // We check if we have a Squeeze / Bulge setup and enter it in these parameters
            bool squeeze = bbsqueeze.Bandwidth.Last(index) - bbsqueeze.Low.Last(index) <= 0 ? true : false;

            bool bulge = bbsqueeze.High.Last(index) - bbsqueeze.Bandwidth.Last(index) <= 0 ? true : false;

            bool rsiminL = _rsi.Result.LastValue <= 30 ? true : false;

            // If we have a Bulge

             if (bulge)

          if ((Bars.Last(2).High < boll.Bottom.Last(2) && Bars.Last(1).High > boll.Bottom.Last(1)) && _rsi.Result.Last(index) <= 30)
            {
                //Print("Blue Line touched or is over the Green Line, bulge condition met | BB% = {0} | Buy condition met.", bbpercent.Result.Last(index));
                Print("Bollinger bottom band crossover from below, and RSI below or equals 30% | RSI = {0} | Buy condition met.", _rsi.Result.Last(index));

                result = true;
            }

            // We return the result
            return result;
        }"

   "// Function to find the sell signals

        private bool SellEntry(int index)
        {

            // We use this variable to return in the function
            bool result = false;

            // We check if we have a Bulge setup and enter it in these parameters
            bool bulge = bbsqueeze.High.Last(index) - bbsqueeze.Bandwidth.Last(index) <= 0 ? true : false;

          if (bulge)
           if ((Bars.Last(2).High < boll.Top.Last(2) && Bars.Last(1).High > boll.Top.Last(1)) && _rsi.Result.Last(index) >= 70)
            {
                // Print("Blue Line touched or is over the Green Line, bulge condition met | BB% = {0} | Sell condition met.", bbpercent.Result.Last(index));
                Print("Bollinger top band crossover from above, and RSI above  or equals 70% | RSI  = {0} | Sell condition met.", _rsi.Result.Last(index) >= 70);
                result = true;
            }

            // We return the result
            return result;
        }"

 


@kojomidoji

kojomidoji
15 Nov 2021, 05:00

RE:

PanagiotisCharalampous said:

Hi kojomidoji,

You did not reply to my question. Can you reply please?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hello Panagiostis,

Please see below my codes which is essentially pseudo codes please help me with the correct codes , meanwhile i have also attached or added the indicator for the %b :

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 BollingerBandsSqueeze_Breakout : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private BollingerBandsSqueezeAndBreakout bbsb;
        private BollingerBandsPercentB bbpb



        protected override void OnStart()
        {
            // Put your initialization logic here
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(10, 2, MovingAverageType.Simple, 20);
            
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(HighLowPeriod)
            
            bbpb = Indicators.GetIndicator<BollingerBandsPercentB>(perid, k, MaType);
            
            //no values returns when the indicator variables are typed followed by a dot as shown in below:
            bbsb.
            bbpb.

            
        }
        public override void Calculate(int index) 
        {
        highLow[index] = 
        
        }

        protected override void OnTick()
        {
            // Put your core logic here
            bandwidthblue= bbsb.bandwith.lastvalue();
            lowred= bbsb.low.lastvalue(); //squeeze
            highgreen= bbsb.high.lastvalue(); //Bulge
            
            resultB = bbpb.result.lastvalue(); //Outbreak direction
            
            //Signal generation
            if bandwidthblue touch lowred Then Buy
            
            if bandwidthblue touch highgreen And
              If resultB equals or greater than 1 Sell 
              Else 
              If resultB equals or less than 0  then Reverse trade //take oppsite trade
              
          
            
        
            
        }

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


@kojomidoji

kojomidoji
13 Nov 2021, 10:24

RE: %b indicator

kojomidoji said:

 

using System;

using cAlgo.API;

using cAlgo.API.Internals;

using cAlgo.API.Indicators;

 

namespace cAlgo.Indicators

{

    [Levels(0, 0.5, 1)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class BollingerBandsPercentB : Indicator

    {

        [Parameter()]

        public DataSeries Price { get; set; }

 

        [Parameter("Period", DefaultValue = 20)]

        public int Period { get; set; }

 

        [Parameter("Std Dev", DefaultValue = 2)]

        public double K { get; set; }

 

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]

        public MovingAverageType MaType { get; set; }

 

        [Output("Main", Color = Colors.Red)]

        public IndicatorDataSeries Result { get; set; }

 

 

        private MovingAverage _movingAverage;

        private StandardDeviation _standardDeviation;

 

        private IndicatorDataSeries middleBB;

        private IndicatorDataSeries volatility;

        private IndicatorDataSeries upperBB;

        private IndicatorDataSeries lowerBB;

 

 

        protected override void Initialize()

        {

            _movingAverage = Indicators.MovingAverage(Price, Period, MaType);

            _standardDeviation = Indicators.StandardDeviation(Price, Period, MaType);

 

            middleBB = CreateDataSeries();

            volatility = CreateDataSeries();

            upperBB = CreateDataSeries();

            lowerBB = CreateDataSeries();

        }

 

        public override void Calculate(int index)

        {

            middleBB[index] = _movingAverage.Result[index];

            volatility[index] = _standardDeviation.Result[index];

            upperBB[index] = middleBB[index] + K * volatility[index];

            lowerBB[index] = middleBB[index] - K * volatility[index];

 

            Result[index] = (MarketSeries.Close[index] - lowerBB[index]) / (upperBB[index] - lowerBB[index]);

        }

 

    }

}

Comments

 

Hello any feedback on this issues please 


@kojomidoji

kojomidoji
12 Nov 2021, 09:04

%b indicator

 

using System;

using cAlgo.API;

using cAlgo.API.Internals;

using cAlgo.API.Indicators;

 

namespace cAlgo.Indicators

{

    [Levels(0, 0.5, 1)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class BollingerBandsPercentB : Indicator

    {

        [Parameter()]

        public DataSeries Price { get; set; }

 

        [Parameter("Period", DefaultValue = 20)]

        public int Period { get; set; }

 

        [Parameter("Std Dev", DefaultValue = 2)]

        public double K { get; set; }

 

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]

        public MovingAverageType MaType { get; set; }

 

        [Output("Main", Color = Colors.Red)]

        public IndicatorDataSeries Result { get; set; }

 

 

        private MovingAverage _movingAverage;

        private StandardDeviation _standardDeviation;

 

        private IndicatorDataSeries middleBB;

        private IndicatorDataSeries volatility;

        private IndicatorDataSeries upperBB;

        private IndicatorDataSeries lowerBB;

 

 

        protected override void Initialize()

        {

            _movingAverage = Indicators.MovingAverage(Price, Period, MaType);

            _standardDeviation = Indicators.StandardDeviation(Price, Period, MaType);

 

            middleBB = CreateDataSeries();

            volatility = CreateDataSeries();

            upperBB = CreateDataSeries();

            lowerBB = CreateDataSeries();

        }

 

        public override void Calculate(int index)

        {

            middleBB[index] = _movingAverage.Result[index];

            volatility[index] = _standardDeviation.Result[index];

            upperBB[index] = middleBB[index] + K * volatility[index];

            lowerBB[index] = middleBB[index] - K * volatility[index];

 

            Result[index] = (MarketSeries.Close[index] - lowerBB[index]) / (upperBB[index] - lowerBB[index]);

        }

 

    }

}

Comments


@kojomidoji

kojomidoji
12 Nov 2021, 08:58

RE:

PanagiotisCharalampous said:

Hi kojomidoji,

The links provide the code for the indicator. We need your cBot's code as well.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

Hello Panagiostis,

Please see below my codes which is essentially pseudo codes please help me with the correct codes , meanwhile i have also attached or added the indicator for the %b :

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 BollingerBandsSqueeze_Breakout : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private BollingerBandsSqueezeAndBreakout bbsb;
        private BollingerBandsPercentB bbpb



        protected override void OnStart()
        {
            // Put your initialization logic here
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(10, 2, MovingAverageType.Simple, 20);
            
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(HighLowPeriod)
            
            bbpb = Indicators.GetIndicator<BollingerBandsPercentB>(perid, k, MaType);
            
            //no values returns when the indicator variables are typed followed by a dot as shown in below:
            bbsb.
            bbpb.

            
        }
        public override void Calculate(int index) 
        {
        highLow[index] = 
        
        }

        protected override void OnTick()
        {
            // Put your core logic here
            bandwidthblue= bbsb.bandwith.lastvalue();
            lowred= bbsb.low.lastvalue(); //squeeze
            highgreen= bbsb.high.lastvalue(); //Bulge
            
            resultB = bbpb.result.lastvalue(); //Outbreak direction
            
            //Signal generation
            if bandwidthblue touch lowred Then Buy
            
            if bandwidthblue touch highgreen And
              If resultB equals or greater than 1 Sell 
              Else 
              If resultB equals or less than 0  then Reverse trade //take oppsite trade
              
             
            
            
            
            
            
        }

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


@kojomidoji

kojomidoji
10 Nov 2021, 16:38

RE:

Hello Panagiotis,

I have already added links to the codes in my previous message. The complete codes are in there

 

 

PanagiotisCharalampous said:

Hi kojomidoji,

Please share your cBot's code so that we can have a look. 

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@kojomidoji