Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Noob question.... "def before_trading_start(context, data):"

Hi all, sorry for the very basic question but hopefully it only requires a simple answer.

I am trying to code up a strategy as follows...

Before the days trading starts (US Equities) calculate key entry points based on historical data from the last 3 days
Once these entry points have been calculated execute two limit orders based on the calculated key entry points.
Both of these steps need to occur before the trading session begins.

My question is: Should these steps be handled in the "def before_trading_start(context, data):" as this appears to be executed each morning before the session starts?

Regards
Richard

2 responses

You can't send an order from before_trading_start. So:

  1. In before_trading_start, calculate the parameters of your orders and put them in a list named eg. context.new_orders.
  2. In handle_data, for each element of context.new_orders, send an order based on it. Set context.new_orders to an empty list at the end, to avoid resending the same orders every minute.

Excellent, got it - thanks André