exiting 3 days after entry

I am still very much learning but could anyone share thoughts on how to construct an exit for the end of general trading hours (4pm ) 3 days after entry?
Not worried about the specifics of exiting at 4PM more curious how to code the 3 days in the future.

Comments

  • ptunneyptunney Posts: 246

    Trevor Trinkino : You can setup a class dictionary that saves the value for the number of days since you entered the position, then you can update it each day and reference the dictionary at the end of each day to exit. Also need to run the backtest as a single multiday job

    David Bradley : you can use the order_id returned by algo_buy / algo_sell as keys in the dictionary, make sure to put it in on_save / on_restore

    Steven Chai : one cheap way to do this....

    entry_time = account[self.symbol].position.inventory[0].execution.time
    entry_time_day = service.time_to_string(entry_time,"%Y-%m-%d")
    print  self.symbol,"entry_time_day: ", entry_time_day             
    self.pbar = md.bar.daily(start= -3)         # request previous daily bar 
    pdays = [ service.time_to_string(x,"%Y-%m-%d") for x in self.pbar.timestamp]
    print entry_time_day,  pdays
    if entry_time_day <= pdays[0]:
        print 'exit', self.symbol
Sign In or Register to comment.