Discrepancy in data gathered

Created at 23 Aug 2022, 12:58
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!
NO

noolohp

Joined 11.03.2022

Discrepancy in data gathered
23 Aug 2022, 12:58


Hi, 

I am coordinating Bars.ClosePrices/OpenPrices/etc.[i] and Bars.Last(1).Close/Open/Etc. where the Bars.ClosePrices/OpenPrices/etc.[i] is being used in the Onbar() and Bars.Last(1).Close/Open/Etc. is being used as methods. However, there is discrepancy in data gathered for each bar as seen in the attached picture. To clarify, it demonstrates loop starts -> Bars.OpenTimes[i] (loop open time) -> Bars.Last(1).OpenTime (method open time) -> method activites (represented with number) -> loop activities (represented with letters) -> loop ends. As you can see that the loop open time and method open time are sometime not coordinated. Please give me some guidance on this occurrence. Here are the code I am using:

 

Thank you!


@noolohp
Replies

PanagiotisCharalampous
23 Aug 2022, 14:20

Hi noolohp,

I am not sure why you expect the two values to match. Here you always pring the last value

  Print("method " + Bars.Last(1).OpenTime);

and here you print a value based on the i counter

    Print(curreBarOpenTime);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

noolohp
23 Aug 2022, 18:09

RE:

PanagiotisCharalampous said:

Hi noolohp,

I am not sure why you expect the two values to match. Here you always pring the last value

  Print("method " + Bars.Last(1).OpenTime);

and here you print a value based on the i counter

    Print(curreBarOpenTime);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi PanagiotisCharalampous,

the curreBarOpenTime represents Bars.OpenTimes[i] in the while loop in OnBar() which I am trying to gather data based on the logic within the loop from the first data provided to the last data, thus, the Bars.OpenTimes[i] will always represent the last value of the graph (the same as Bars.Last(1).OpenTime) as per my understanding Bars.OpenTime[] starts from [0] and surplus each time new bar is opened so with i++ the value of Bars.OpenTimes[i] should be the same as Bars.Last(1).OpenTime. Moreover, the majority of the results show that the data gathered are from the same date and time but there are a few of them which show disprecancy in data gathered. For instance from the attachment, 19/07/2565 2:03:00 (Bars.OpenTimes[i]) and method 19/07/2565 2:03:00 (Bars.Last(1).OpenTime) are the same as well as 19/07/2565 2:05:00 (Bars.OpenTimes[i]) and method 19/07/2565 2:05:00 (Bars.Last(1).OpenTime)

Best Regards,

NL


@noolohp

PanagiotisCharalampous
24 Aug 2022, 08:34

Hi noolohp,

as per my understanding Bars.OpenTime[] starts from [0] and surplus each time new bar is opened so with i++ the value of Bars.OpenTimes[i] should be the same as Bars.Last(1).OpenTime

But you run the loop from the beginning for each bar, therefore the condition (see below) that prints the curreBarOpenTime might become true before the last bar is reached.

    if (isCurrentBarRed && isPreviousBarRed && !isRedDriven)

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

noolohp
24 Aug 2022, 17:18 ( Updated at: 24 Aug 2022, 17:19 )

RE:

PanagiotisCharalampous said:

Hi noolohp,

as per my understanding Bars.OpenTime[] starts from [0] and surplus each time new bar is opened so with i++ the value of Bars.OpenTimes[i] should be the same as Bars.Last(1).OpenTime

But you run the loop from the beginning for each bar, therefore the condition (see below) that prints the curreBarOpenTime might become true before the last bar is reached.

    if (isCurrentBarRed && isPreviousBarRed && !isRedDriven)

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi PanagiotisCharalampous,

Can you please amplify the above statement ? I apologize but I am abit confused as the results always show that Bars.Last(1).OpenTime is 1 bar ahead of Bars.OpenTime[i], thus, if the above statement is true, shouldn't the result be the otherway around ? Moreover, with regards to the mentioned code is there any possible alteration, in your opinion, to align the two value ?

Best regards,
NL


@noolohp

PanagiotisCharalampous
25 Aug 2022, 08:51

Hi noolohp,

he results always show that Bars.Last(1).OpenTime is 1 bar ahead of Bars.OpenTime[i]

Correct. The proble here is that sometimes is > 1, therefore it points to an older date. There is clearly a logical error in your code. You need to debug it and understand what is wrong.

 Moreover, with regards to the mentioned code is there any possible alteration, in your opinion, to align the two value ?

No, because I have no idea what you are trying to do. I can only explain what you are doing which is probably not aligned with your intentions.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

noolohp
25 Aug 2022, 09:43

RE:

PanagiotisCharalampous said:

Hi noolohp,

he results always show that Bars.Last(1).OpenTime is 1 bar ahead of Bars.OpenTime[i]

Correct. The proble here is that sometimes is > 1, therefore it points to an older date. There is clearly a logical error in your code. You need to debug it and understand what is wrong.

 Moreover, with regards to the mentioned code is there any possible alteration, in your opinion, to align the two value ?

No, because I have no idea what you are trying to do. I can only explain what you are doing which is probably not aligned with your intentions.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi PanagiotisCharalampous,

However, I am still confused as if is sometimes more than 1 it will then direct that Bars.Opentime[i] must be 1 bar ahead of Bars.Last(1).OpenTime and not as the result shows. For instance, a backtesting process with a total of 100 bars, Bars.OpenTime[i] would start with Bars.OpenTime[1] and then surplus each time to Bars.OpenTime[100]. Therefore, if i > 1 , wouldn't it a newer date instead of older date ?

Best regards,

NL


@noolohp

PanagiotisCharalampous
25 Aug 2022, 09:55

Hi noolohp,

it will then direct that Bars.Opentime[i] must be 1 bar ahead of Bars.Last(1).OpenTime and not as the result shows.

No that is not how it works. Bars.Last(1).OpenTime is not equal to Bars.OpenTime[i]. Last() methods counts backwards therefore  Bars.Last(1).OpenTime = Bars.OpenTime[Bars.Count - 2] 

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

noolohp
26 Aug 2022, 11:57

RE:

PanagiotisCharalampous said:

Hi noolohp,

it will then direct that Bars.Opentime[i] must be 1 bar ahead of Bars.Last(1).OpenTime and not as the result shows.

No that is not how it works. Bars.Last(1).OpenTime is not equal to Bars.OpenTime[i]. Last() methods counts backwards therefore  Bars.Last(1).OpenTime = Bars.OpenTime[Bars.Count - 2] 

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hi PanagiotisCharalampous,

Thank you for the information.I will work on it.

Best regards,

NL


@noolohp