You should probably organize your layout w/ something along these lines:
# choose the top two percentile of DollarValue rankings
# construct a new batch transform, tuck it into the context
# call the function my_transform every two days, keeping 7 days of history in the data panel
context.a_batch_transform = BatchTransform(func=my_transform, refresh_period=2, delta=timedelta(days=7))
def handle_data(data, context):
# update the transform with the current data events
transform_results = context.a_batch_transform.handle_data(data)
# place orders, rebalance portfolio, etc.
prices_dataframe = data_panel['price']
# do work on prices...
# return the data your algorithm will need to make buy/sell choices
Obviously this won't run any result, but I hope it generalizes some "flow of concept" :P