How block stoping cbot after Exception in OnStart

Created at 24 Oct 2015, 18:34
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!
breakermind's avatar

breakermind

Joined 17.07.2013

How block stoping cbot after Exception in OnStart
24 Oct 2015, 18:34


H

Error log:

22/10/2015 15:31:18.580 | Crashed in OnStart with MySqlException: Duplicate entry '1444597200' for key 'time'

How prevent stop cbot after exception ?

try
            {
                connection.Open();
            } catch (Exception e)
            {
                Print(e);
             }

Thanks


@breakermind
Replies

breakermind
24 Oct 2015, 18:39

RE:

OK works.


@breakermind

breakermind
25 Oct 2015, 17:32

RE: RE:

Why I cant add cbot?

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 AccessDenied6 : Robot
    {
       // test on 1000000 USD

        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", DefaultValue = 50)]
        public int SlowPeriods { get; set; }

        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }
        [Parameter("Stop Loss", DefaultValue = 100)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 300)]
        public int TakeProfit { get; set; }

        private MovingAverage slowMa;
        private const string label = "Sample Trend cBot";
        int nextopen = 0;

        protected override void OnStart()
        {
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {
            MarketSeries data = MarketData.GetSeries(Symbol, TimeFrame.Hour);
            DataSeries series = data.Close;
            int index = series.Count - 1;

            double close = data.Close[index];
            double high = data.High[index];
            double low = data.Low[index];
            double open = data.Open[index];
            Int32 opentime = (Int32)(data.OpenTime[index].Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);

            var previousSlowMa = slowMa.Result.Last(1);

            if (nextopen != opentime)
            {
                if (previousSlowMa < open)
                    longPosition = null;
                if (previousSlowMa > open)
                    shortPosition = null;
            }


            if (previousSlowMa < open && longPosition == null)
            {
                if (shortPosition != null)
                    ClosePosition(shortPosition);
                ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, label, StopLoss, TakeProfit);
            }
            else if (previousSlowMa > open && shortPosition == null)
            {
                if (longPosition != null)
                    ClosePosition(longPosition);
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, StopLoss, TakeProfit);
            }
        }

        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }
    }
}

 


@breakermind

Spotware
26 Oct 2015, 13:35

Dear Trader,

We would like to inform you that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware