Is it a bug? TickVolume's return value is not correct.
Is it a bug? TickVolume's return value is not correct.
26 Jul 2018, 05:45
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 TestTickVolume : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { // Put your initialization logic here } protected override void OnBar() { Print(MarketSeries.TickVolume[MarketSeries.TickVolume.Count - 1]); Print(MarketSeries.TickVolume.Last(1)); } protected override void OnStop() { // Put your deinitialization logic here } } }
When I run it on the chart, the log shows
-------------------
25/07/2018 22:38:04.649cBot "TestTickVolume" was stopped for EURUSD, m1.
25/07/2018 22:38:00.712 44
25/07/2018 22:38:00.712 1
25/07/2018 22:37:54.040cBot "TestTickVolume" was started successfully for EURUSD, m1.
-------------------
Basically,
MarketSeries.TickVolume.Last(1) returns the correct value (44)
But,
MarketSeries.TickVolume[MarketSeries.TickVolume.Count - 1] always returns incorrect value (1)
I think they should be the same result.
Is this a bug? Or my code is not correct?
Could you please give me some hints! I appreciate it.
Thank you in advance.
Replies
hideki
26 Jul 2018, 16:40
Hi Panagiotis,
Thank you for responding and providing the sample code!
It's interesting. Becuase I verified:
MarketSeries.Close[MarketSeries.Close.Count - 1] is equivalent to MarketSeries.Close.Last(1)
But as you mentioned here:
MarketSeries.TickVolume[MarketSeries.TickVolume.Count - 2] (the index is not "M.T.C-1" but "M.T.C-2") is equivalent to MarketSeries.TickVolume.Last(1)
May I ask why the "index" value should be different between in MarketSeries.Close and MarketSeries.TickVolume?
Thank you in advance.
@hideki
PanagiotisCharalampous
27 Jul 2018, 09:38
Hi hideki,
The same logic applies for MarketSeries.Close. Check it with the code below
Print(MarketSeries.TickVolume[MarketSeries.TickVolume.Count - 2]); Print(MarketSeries.TickVolume.Last(1)); Print(MarketSeries.Close[MarketSeries.TickVolume.Count - 2]); Print(MarketSeries.Close.Last(1));
Best Regards,
Panagiotis
@PanagiotisCharalampous
hideki
29 Jul 2018, 16:25
Hi Panagiotis,
Thank you! I really appreciate you providing the sample code.
I also verified by myself. Good learning for me.
It is very interesting. May I ask: what does "index" really mean?
MarketSeries.TickVolume.Count[index]
If index=[MarketSeries.TickVolume.Count-2], it means the TickVolume of last bar, but if index=[MarketSeries.TickVolume.Count-1] or index=[MarketSeries.TickVolume.Count], which bar's value will be outputed?
If you can provide more detail information, I would appreciate it!
Thank you in advance!
@hideki
PanagiotisCharalampous
30 Jul 2018, 09:57
Ηι hideki,
index=[MarketSeries.TickVolume.Count-1] is the value of the last bar which is equal to MarketSeries.TickVolume.Last(0). index=[MarketSeries.TickVolume.Count] does not exist since indexing in C# starts from 0.
Let me know if this makes things clearer for you.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
26 Jul 2018, 09:40
Hi hideki,
Thanks for posting in our forum. MarketSeries.TickVolume.Last(1) is equivalent to MarketSeries.TickVolume[MarketSeries.TickVolume.Count - 2]. See corrected code below.
Best Regards,
Panagiotis
@PanagiotisCharalampous