Starting charts from 0 every morning?

If I want a instrument to start from 0 from the start of the day, please provide me AFL for this?
so for example if an instrument opens at 235, i want it to open from 0 and then if it goes to 240, on my chart it shows me that it has moved +4 and similarly if it has fallen from the open price.

OpenTime = 93000; // 9:30:00

BasePrice = ValueWhen( TimeNum() == OpenTime, Open );

OZ = Open - BasePrice ;
CZ = Close - BasePrice ;
LZ = Low - BasePrice ;
HZ = High - BasePrice ;

PlotOHLC( OZ, HZ, LZ, CZ, "Chart That starts from zero every day", colorDefault, styleCandle );

Alternatively you can use

NewDay = DateNum() != Ref( DateNum(), -1 );

BasePrice = ValueWhen( NewDay, Open );

// ... the rest is the same

Thank you so much Tomasz .

Just one doubt that you have only changed the opening candle open to 0 and also made changes close, high and low. However why the second candle and other candles after it, have followed the trend of the first candle (starting from zero). Why there is no requirement of making any changes from the second candle onwards?

AFL is based on array/vector processing.
You can read more here

Those variables like Open, High etc are arrays, not scalar vars.

1 Like

You wanted to start chart everyday from 0 based on open price. So the code just subtracts current day open from OHLC prices. This way price movement remains but just starts from 0.