Multi Symbol OnBarOpened event

Created at 29 Oct 2023, 08:04
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!
YS

ys2310

Joined 03.12.2021

Multi Symbol OnBarOpened event
29 Oct 2023, 08:04


Hi,

I'm trying to code a custom OnBarsBarOpened() event for multi symbol bactesting as below.

encountered a "cannot implicitly convert type void to System.Action BarOpenedEventArgs" error at line bars.BarOpened += OnBarsBarOpened();

How can I fix this error and code this corectly?

		protected override void OnStart()
        {
            // To learn more about cTrader Automate visit our Help Center:
            // https://help.ctrader.com/ctrader-automate
            //System.Diagnostics.Debugger.Launch();

            foreach (Watchlist w in Watchlists)
                if (w.Name == "Popular Markets")
                    TradeList = Symbols.GetSymbols(w.SymbolNames.ToArray());

            foreach (Symbol s in TradeList)
            {

                var bars = MarketData.GetBars(TimeFrame, s.Name);
                bars.BarOpened += OnBarsBarOpened();
            }
        }

        void OnBarsBarOpened(BarOpenedEventArgs obj)
        {

        }

@ys2310
Replies

PanagiotisChar
30 Oct 2023, 06:47

Hi there,

Try changing 

bars.BarOpened += OnBarsBarOpened();

to

bars.BarOpened += OnBarsBarOpened;


@PanagiotisChar