Why always shows the open price???

Created at 27 Jul 2020, 10:25
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!
PA

pankuolung0804

Joined 27.07.2020

Why always shows the open price???
27 Jul 2020, 10:25


Hi there,

 

I'm trying to write a program to trade my DAX30.4H

Here is the problem.

I want to print out the last bar "close price" but it always shows the "open price".

there is the code.

 

Print("closeprice: " + Bars.ClosePrices);

 

Please advice, thank you!

 

Mason

 


@pankuolung0804
Replies

PanagiotisCharalampous
27 Jul 2020, 10:32

Hi pankuolung0804,

Try the below

Print("closeprice: " + Bars.ClosePrices.Last(1));

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

pankuolung0804
27 Jul 2020, 11:13

RE:

PanagiotisCharalampous said:

Hi pankuolung0804,

Try the below

Print("closeprice: " + Bars.ClosePrices.Last(1));

Best Regards,

Panagiotis 

Join us on Telegram

 

Thanks your info.

It looks work, does the cTrader can't handle the last bar close? it can handle the previous bar close?

Thank you!


@pankuolung0804

PanagiotisCharalampous
27 Jul 2020, 11:14

Hi pankuolung0804,

If you mean the current bar then use Last(0).

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

pankuolung0804
27 Jul 2020, 11:29 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi pankuolung0804,

If you mean the current bar then use Last(0).

Best Regards,

Panagiotis 

Join us on Telegram

Please see the image. if I use the last(0), it always shows the open price? is the backtest setting problem(open price data)?

 


@pankuolung0804

PanagiotisCharalampous
27 Jul 2020, 11:41

Hi pankuolung0804,

If you use the code in OnBar then this is what you should expect. When the bar opens then the close price is the same with the open price.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous