For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

What is the most efficient way to detect one day is passed



  • Say I am calculating "volume-weighted-average-price". My input is 5min data. And I want to sum up to daily price. May I know what is the most efficient way to detect that "one day is passed" in my indicator?



  • You can resample your 5 min data to daily bars and then develop an indicator based on the daily bars. More information can be found here -
    Docs - Data resampling



  • Actually I have daily data, but to be more accurate, I would like to use 5 min data to compute weighted-average for each 5-min, because volumes are not evenly distributed in daily high-low.

    resample, if I understand correctly, just takes peak value...



  • another case could be Accumulation Distribution Line, compute buy/sell force in each 5-min could be more accurate than just use daily based data.



  • I didn't get what do you want, sorry. It is possible to go from 5 min data to daily bars with resample or replay, but you can't get back from daily to 5 min.

    If you have 5 min data, then use it for indicators and trade on daily bars.



  • @hobart-liu said in What is the most efficient way to detect one day is passed:

    resample, if I understand correctly, just takes peak value...

    You understand it wrongly. Resampling accumulates the volume.

    @hobart-liu said in What is the most efficient way to detect one day is passed:

    Say I am calculating "volume-weighted-average-price". My input is 5min data. And I want to sum up to daily price. May I know what is the most efficient way to detect that "one day is passed" in my indicator?

    I don't think that "volume-weighted-average-price fits the indicator pattern. A better, imho, options would be to extend the data feed with an extra line: vwap and insert a filter which calculates the value.

    Detecting that a new day is in place can be used with the standard data.datetime.date() method (where the 1st time refers to the line name ... it has confused me too several times)

    If you want to do the same in an indicator, you need to make sure that the incoming data has a datetime capable line, which is not guaranteed, because indicators are meant to accept anything.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.