my cBot stops on each bars

Created at 02 Mar 2018, 21:27
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!
itmfar's avatar

itmfar

Joined 08.11.2017

my cBot stops on each bars
02 Mar 2018, 21:27


I have problem with my code. it stops

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 ZiIchi : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }
        private IchimokuKinkoHyo ihk;

        [Output("TenkanSen", Color = Colors.Red)]
        public IndicatorDataSeries TenkanSen { get; set; }
        [Output("Kijunsen", Color = Colors.Blue)]
        public IndicatorDataSeries KijunSen { get; set; }
        [Output("SenkouSpanB", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanB { get; set; }
        [Output("SenkouSpanA", Color = Colors.Green, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries SenkouSpanA { get; set; }

        [Parameter("Volume", DefaultValue = 3, MinValue = 0)]
        public int Volume { get; set; }

        protected override void OnStart()
        {
            ihk = Indicators.IchimokuKinkoHyo(9, 26, 52);
        }

        protected override void OnTick()
        {

        }
        protected override void OnBar()
        {
            var index = Source.Count - 1;
            TenkanSen[index] = ihk.TenkanSen[index];
            KijunSen[index] = ihk.KijunSen[index];
            SenkouSpanB[index] = ihk.SenkouSpanB[index];
            SenkouSpanA[index] = ihk.SenkouSpanA[index];
            findCrossTJ(Source.Count - 1);
        }

        private void findCrossTJ(int index)
        {
            if (TenkanSen.HasCrossedAbove(KijunSen, 0))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "CrossTJA" + index);
            }
            if (TenkanSen.HasCrossedBelow(KijunSen, 0))
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "CrossTJB" + index);
            }
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
      
    }
}

 


@itmfar
Replies

PanagiotisCharalampous
05 Mar 2018, 10:32

Hi itmfar,

The reason your cBot stops is because it is crashing on OnBar(). Check your log. You need to initialize the IndicatorDataSeries. My question is why do you need to transfer the values to new data series and don't just use the ihk data series directly?

Best Regards,

Panagiotis


@PanagiotisCharalampous

ericjavier.santiago
31 Aug 2018, 20:24

Plot a series from a cBot

Hi Panagiotis,

I have a similar problem. I already initialized the series using ( CreateDataSeries();) but now I don't see any plot. Is it possible to plot a series from a cBot?

         

         [Output("bf", Color = Colors.Green, PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries bf { get; set; }

       

        protected override void Initialize()
        {
            bf = CreateDataSeries();
        }

Regrads,

Eric


@ericjavier.santiago

PanagiotisCharalampous
03 Sep 2018, 11:10

Hi Eric,

If you want to plot data series on the chart, you need to use a custom indicator and then add it on the chart.

Best Regards,

Panagiotis


@PanagiotisCharalampous

notexample
14 Nov 2018, 12:03

RE:

i use cbot on charts. Sometimes one of them stops. Cbot opens an order but does not close it due to stopping. How i solve the problem?

 


@notexample

PanagiotisCharalampous
14 Nov 2018, 12:09

Hi notexample,

Thank you for posting in our forum. I would suggest that you create a new thread with your problem and provide some more information so that we can reproduce it and advise what is going wrong. We will definitely need your cBot code.

Best Regards,

Panagiotis


@PanagiotisCharalampous