cBot not producing trades

Created at 13 Oct 2014, 18:30
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
JA

jagtrading

Joined 01.10.2014

cBot not producing trades
13 Oct 2014, 18:30


Hi Guys,

 

I've been messing about briefly with cAlgo for the last 2 weeks and for some reason I can't get my program to trade. I only used it for 2-3 hours now but its not working for me. Could someone help?? The program won't produce any trades when I backtest or optimize.

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 stochasticbollinger : Robot
    {
        [Parameter("EMA_period", DefaultValue = 5)]
        public int EMA_Period { get; set; }

        [Parameter("BollingerPeriod", DefaultValue = 100)]
        public int Bol_Period { get; set; }

        [Parameter("BollingerDeviation", DefaultValue = 1)]
        public double Bol_Deviation { get; set; }

        [Parameter("StochasticPeriod", DefaultValue = 25)]
        public int Stoch_Period { get; set; }

        [Parameter("StochasticSlowing", DefaultValue = 50)]
        public int Stoch_Slowing { get; set; }

        [Parameter("BollingerStochDev", DefaultValue = 25)]
        public double BolStoch_Deviation { get; set; }

        [Parameter("BollingerStochPeriod", DefaultValue = 1)]
        public int BolStoch_Period { get; set; }

        [Parameter("ATRperiod", DefaultValue = 14)]
        public int ATR_PERIOD { get; set; }

        [Parameter("ATRmultiplestop", DefaultValue = 2)]
        public int ATR_STOPLOSS { get; set; }

        [Parameter("ATRmultipletakeprofit", DefaultValue = 2)]
        public int ATR_TAKEPROFIT { get; set; }

        [Parameter("Slippage", DefaultValue = 4)]
        public int Slippage { get; set; }

        [Parameter("Margin", DefaultValue = 1.0)]
        public int _Margin { get; set; }

        [Parameter("CandlePeriod", DefaultValue = 0.0)]
        public int CandlePeriod { get; set; }

        private int p_volume;
        private string BuyLabel = "Buy Position";
        private string SellLabel = "Sell Position";
        private BollingerBands Boll_Bands;
        private BollingerBands BollStoch_Bands;
        private StochasticOscillator Stoch_;
        private AverageTrueRange ATR_;
        private ExponentialMovingAverage MAone_;



        protected override void OnStart()
        {
            p_volume = _Margin * 10000;

            Boll_Bands = Indicators.BollingerBands(MarketSeries.Close, Bol_Period, Bol_Deviation, MovingAverageType.Simple);
            Stoch_ = Indicators.StochasticOscillator(Stoch_Period, Stoch_Slowing, 1, MovingAverageType.Simple);
            BollStoch_Bands = Indicators.BollingerBands(Stoch_.PercentK, BolStoch_Period, BolStoch_Deviation, MovingAverageType.Simple);
            ATR_ = Indicators.AverageTrueRange(ATR_PERIOD, MovingAverageType.Simple);
            MAone_ = Indicators.ExponentialMovingAverage(MarketSeries.Close, EMA_Period);
        }

        protected override void OnBar()
        {
            var SellPositions = Positions.Find(SellLabel, Symbol, TradeType.Sell);

            var BuyPositions = Positions.Find(BuyLabel, Symbol, TradeType.Buy);

            var ATRTP = ATR_TAKEPROFIT * ATR_.Result.LastValue * 10000;

            var ATRSL = ATR_STOPLOSS * ATR_.Result.LastValue * 10000;



            if ((Positions.Count == 0) && (MAone_.Result.HasCrossedAbove(Boll_Bands.Bottom.LastValue, CandlePeriod)) && (Stoch_.PercentK.LastValue > BollStoch_Bands.Bottom.LastValue))
            {
                ClosePosition(SellPositions);
                ExecuteMarketOrder(TradeType.Buy, Symbol, p_volume, BuyLabel, ATRSL, ATRTP, Slippage);
            }

            else if ((Positions.Count == 0) && (MAone_.Result.HasCrossedBelow(Boll_Bands.Top.LastValue, CandlePeriod)) && (Stoch_.PercentK.LastValue < BollStoch_Bands.Top.LastValue))
            {
                ClosePosition(BuyPositions);
                ExecuteMarketOrder(TradeType.Sell, Symbol, p_volume, SellLabel, ATRSL, ATRTP, Slippage);
            }


            else if (Positions.Count == 1)
            {
                if (Positions.Find(BuyLabel) != null)
                {
                    ModifyPosition(BuyPositions, ATRSL, ATRTP);
                }
                else if (Positions.Find(SellLabel) != null)
                {
                    ModifyPosition(SellPositions, ATRSL, ATRTP);
                }
            }



        }

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

 

 


@jagtrading
Replies

Spotware
14 Oct 2014, 10:08

We can recommend you to contact one of our Partners or post a job in Development Jobs section.


@Spotware