Help to define what is wrong with my BarOpened EventArgs method.

Created at 11 Sep 2020, 15:06
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!
AN

anton.kovalchuk

Joined 01.03.2016

Help to define what is wrong with my BarOpened EventArgs method.
11 Sep 2020, 15:06


 Hi all,

If I understand correctly the method public void NewBarOpened(BarOpenedEventArgs br) should be executed once for each new bar on a chart.

I'm receiving   Print("Event"); with each tick when my pattern is true. What is wrong in my code?

 

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.FullAccess)]
    public class InsideBarTracking : Robot
    {
        [Parameter("Positon Value", Group = "Position Settings", DefaultValue = 5000)]
        public double PositionValue { get; set; }

        [Parameter("Take Profit", Group = "Position Settings", DefaultValue = 6)]
        public int FixedProfit { get; set; }

        [Parameter("Fixed Stop Lost", Group = "Position Settings", DefaultValue = 18)]
        public int FixedStopLost { get; set; }


        protected override void OnStart()
        {
            Bars.BarOpened += NewBarOpened;
        }

        public void NewBarOpened(BarOpenedEventArgs br)
        {

            if (GetPattern().Item1 == true)
            {
               Print("Event");
            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            //TelegramNotifications("Inside Bar Tracking was Stopped");
        }

public Tuple<bool, TradeType> GetPattern()
{
   ...
   return true
}


}

 


@anton.kovalchuk
Replies

PanagiotisCharalampous
11 Sep 2020, 15:15

Hi Anton,

Is this the complete cBot code you are using? Because I cannot reproduce such a behavior

Seems to work fine for me

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

anton.kovalchuk
11 Sep 2020, 15:33

RE:

Panagiotis Charalampous Thank you for quick response 

It was not all code

but this small code does not work too

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 InsideBar : Robot
    {
        [Parameter("Positon Value", Group = "Position Settings", DefaultValue = 5000)]
        public double PositionValue { get; set; }


        protected override void OnStart()
        {

            Bars.BarOpened += NewBarOpened;

        }

        public void NewBarOpened(BarOpenedEventArgs br)
        {
            Print("New Bar");
        }


        protected override void OnTick()
        {
            // Put your core logic here
        }

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

Video: https://gofile.io/d/ik0m49


@anton.kovalchuk

mauriziolobello
25 Feb 2021, 18:51 ( Updated at: 21 Dec 2023, 09:22 )

RE: BarOpened

PanagiotisCharalampous said:

Hi Anton,

Is this the complete cBot code you are using? Because I cannot reproduce such a behavior

Seems to work fine for me

Best Regards,

Panagiotis 

Join us on Telegram

 

I've got this same behavior (multiple events when should happen once for each period) with actual version 3.8, TF is H1.


@mauriziolobello

PanagiotisCharalampous
26 Feb 2021, 08:03

Hi Anton,

It is a known bug and we will fix it.

Best Regards,

Panagiotis 

Join us on Telegram 

 


@PanagiotisCharalampous