get last bar candle index

khoshroomahdi's avatar

khoshroomahdi since: 17 Jun 2021;

  23 Jul 2021, 07:14
get last bar candle index

i try to draw box from last candle .

i use chart.lastbarvisible and bars.count

but when i move the chart to past recatangle moved.

so i need to get last bar candle index.

            var rectangle = Chart.DrawRectangle("rectangle_sample", Bars.Count, Bars.ClosePrices.Minimum(Period), Chart.LastVisibleBarIndex - Period, Bars.ClosePrices.Maximum(Period), Color.FromArgb(100, Color.Red));
amusleh's avatar

amusleh since: 01 Mar 2021;

  23 Jul 2021, 08:08

Hi,

I'm not sure what you are trying to do, Bars.Count gives you the number of available bars on your chart, so if you pass it as a first bar index for rectangle, it will be drawn from the last bar on your chart.

Community Developer | Spotware | Telegram: @algodeveloper
khoshroomahdi's avatar

khoshroomahdi since: 17 Jun 2021;

  23 Jul 2021, 09:04
RE:

amusleh said:

Hi,

I'm not sure what you are trying to do, Bars.Count gives you the number of available bars on your chart, so if you pass it as a first bar index for rectangle, it will be drawn from the last bar on your chart.

I use that but when scrool to past it shows like below picture.

amusleh's avatar

amusleh since: 01 Mar 2021;

  23 Jul 2021, 09:27

Hi,

Please read the API references, check the examples, I see you don't understand how the DrawRectangle works, and it's not clear at all what you are trying to do.

I recommend you before you open a thread here, read the API references, play with code examples, then if something was not clear you can ask here.

Community Developer | Spotware | Telegram: @algodeveloper