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

Get Highest and Lowest value of first 15 Minutes data



  • I have 1 minute CSV data. I want to get the highest and lowest value of the first 15 minutes data on a daily basis to calculate other things.



  • You can create a highest and lowest variable that reset every day, In the first 15 minutes, compare the highest to the current high and keep the highest, and opposite for low. The code could look like this:

    def __init__(self):
        self.highest = 0
        self.lowest = 0
    
    
    def next(self):
        if self.data.datetime.time() < datetime.time(9, 45, 0):
            if self.data.datetime.date() != self.data.datetime.date(-1):
                print("\n")
                self.highest = self.datas[0].high[0]
                self.lowest = self.datas[0].low[0]
    
    
            self.highest = max(self.datas[0].high[0], self.highest)
            self.lowest = min(self.datas[0].low[0], self.lowest)
    
                self.log(f"highest (high) {self.highest:7.2f} ({self.datas[0].high[0]:7.2f}), "
                                 f"lowest (low) {self.lowest:7.2f} ({self.datas[0].low[0]:7.2f})")
            
    

    Output

    2020-04-22 09:31:00, highest (high) 2778.25 (2778.25), lowest (low) 2780.75 (2780.75)
    2020-04-22 09:32:00, highest (high) 2778.75 (2778.75), lowest (low) 2780.75 (2781.50)
    2020-04-22 09:33:00, highest (high) 2778.75 (2772.25), lowest (low) 2779.25 (2779.25)
    2020-04-22 09:34:00, highest (high) 2778.75 (2773.50), lowest (low) 2773.50 (2773.50)
    2020-04-22 09:35:00, highest (high) 2778.75 (2774.75), lowest (low) 2773.50 (2776.75)
    2020-04-22 09:36:00, highest (high) 2778.75 (2776.50), lowest (low) 2773.50 (2777.25)
    2020-04-22 09:37:00, highest (high) 2778.75 (2775.50), lowest (low) 2773.50 (2780.25)
    2020-04-22 09:38:00, highest (high) 2778.75 (2774.50), lowest (low) 2773.50 (2776.25)
    2020-04-22 09:39:00, highest (high) 2778.75 (2775.75), lowest (low) 2773.50 (2775.75)
    2020-04-22 09:40:00, highest (high) 2778.75 (2776.75), lowest (low) 2773.50 (2777.75)
    2020-04-22 09:41:00, highest (high) 2780.00 (2780.00), lowest (low) 2773.50 (2781.00)
    2020-04-22 09:42:00, highest (high) 2780.00 (2777.75), lowest (low) 2773.50 (2782.25)
    2020-04-22 09:43:00, highest (high) 2780.00 (2777.50), lowest (low) 2773.50 (2779.25)
    2020-04-22 09:44:00, highest (high) 2780.00 (2777.50), lowest (low) 2773.50 (2778.75)
    


  • @run-out said in Get Highest and Lowest value of first 15 Minutes data:

    if self.data.datetime.date() != self.data.datetime.date(-1):

    Can you explain that line of code? When would they not be different?Thanks!



  • @avinash After thinking about it for a while I realized it was because you are using minute data so you want that to update only when the date changed. Please correct me if I'm wrong. Thanks!



  • @Eduardo-De-La-Garza said in Get Highest and Lowest value of first 15 Minutes data:

    Can you explain that line of code? When would they not be different?Thanks!

    One minute date, checking for new date at the beginning of the day. :)


Log in to reply
 

});