Pass a series of bars to a function
Pass a series of bars to a function
08 Jul 2022, 09:16
Hi
I'd like to pass a series of bars to to a function such as below:
public void drawSupport(Bars previousBars)
{
// Define Support zone as the being the candle with the lowest low with higher lows on either side for 2 candles
if (previousBars.Last(2).Low < previousBars.Last(3).Low && previousBars.Last(2).Low < previousBars.Last(1).Low)
{
if (previousBars.Last(1).Low < previousBars.Last(0).Low)
{
if (previousBars.Last(3).Low < previousBars.Last(4).Low)
{
}
}
}
}
I need to pass a Bars object to the function, but can only seem to pass a Bar (singular) object. What's the best way to pass the previous 5 bars? I come from a Python background and this kind of thing is extremely easy to do so I'm having a hard time adjusting to a non-Python way of thinking.
Replies
ctid3999979
09 Jul 2022, 08:48
( Updated at: 09 Jul 2022, 09:00 )
RE:
Thanks for the response. This seems to be what I'm looking for.
I've implemented the code below, but drawSupport doesn't appear the be getting called from in the OnBar function. I've setup a breakpoint and attached it to cTrader. It compiles fine and I can run it as a backtest, but nothing happens.
Sorry if it's really obvious, but again, it's the learning curve coming from Python.
protected override void OnBar()
{
drawSupport(srBars.Skip(Math.Max(0, Bars.Count() - 5)));
}
public void drawSupport(IEnumerable<Bar> previousBars)
{
// Define Support zone as the being the candle with the lowest low with higher lows on either side for 2 candles
if (previousBars.ElementAt(2).Low < previousBars.ElementAt(3).Low && previousBars.ElementAt(2).Low < previousBars.ElementAt(1).Low)
{
if (previousBars.ElementAt(1).Low < previousBars.ElementAt(0).Low)
{
if (previousBars.ElementAt(3).Low < previousBars.ElementAt(4).Low)
{
}
}
}
}
@ctid3999979
PanagiotisCharalampous
11 Jul 2022, 15:17
Hi there,
You can read how to debug cBots here.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous
PanagiotisCharalampous
08 Jul 2022, 12:01
Hi there,
Here you go
protected override void OnStart() { drawSupport(Bars.Skip(Math.Max(0, Bars.Count() - 5))); } public void drawSupport(IEnumerable<Bar> previousBars) { }
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous