Get Events for all the Symbols in a Bot
Created at 13 Dec 2021, 17:19
Get Events for all the Symbols in a Bot
13 Dec 2021, 17:19
I have:
[Parameter(DefaultValue = "AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY")]
public string InstrumentList { get; set; }
protected override void OnStart() {
string[] symbols = InstrumentList.Split(',');
Print("Symbols to get: {0}", InstrumentList);
Symbol[] SelectedSymbols = Symbols.GetSymbols(symbols);
Print("Selected symbols: {0}", string.Join(", ", SelectedSymbols as object[]));
foreach (Symbol symbol in SelectedSymbols) {
if (symbol == null) {
Print("Null symbol");
continue;
}
Bars bars = MarketData.GetBars(TimeFrame.Minute, symbol.Name);
if (bars == null) {
Print("Null bar for symbol {0}", symbol);
continue;
}
}
Bars.BarOpened += BarOpened;
PendingOrders.Filled += PendingOrderFilled;
Positions.Opened += PositionOpened;
Positions.Closed += PositionClosed;
Print("Started");
}
This is attached to a EURUSD also.
I am only receiving events for the symbol EURUSD. I want to have the events fire for all the symbols. How do I do that?
amusleh
14 Dec 2021, 10:21
Hi,
You have to subscribe to all symbol Bars BarOpened event, not just the current symbol Bars:
@amusleh