Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why doesnt this buy? two lines of code

if context.dal in data:
order(context.dal,100)

Thank you..!

# For this example, we're going to write a simple momentum script.  When the  
  # stock goes up quickly, we're going to buy; when it goes down quickly, we're  
  # going to sell.  Hopefully we'll ride the waves.

  # To run an algorithm in Quantopian, you need two functions: initialize and  
  # handle_data.

def initialize(context):  
  # This initialize function sets any data or variables that you'll use in  
  # your algorithm.  For instance, you'll want to define the security (or  
  # securities) you want to backtest.  You'll also want to define any  
  # parameters or values you're going to use.

  # In our example, we're looking at Apple.  If you re-type this line  
  # yourself, you'll see the auto-complete that is available for the  
  # security ID.  
  context.dal = sid(2079)  
  context.ual = sid(28051)  
  context.dal_invested = False  
  context.ual_invested = False  
  # In these two lines, we set the maximum and minimum we want our algorithm  
  # to go long or short our security.  You don't have to set limits like this  
  # when you write an algorithm, but it's good practice.  
  context.max_notional = 1000000.1  
  context.min_notional = -1000000.0

def handle_data(context, data):  
  # This handle_data function is where the real work is done.  Our data is  
  # minute-level tick data, and each minute is called a frame.  This function  
  # runs on each frame of the data.  
  #price = data[context.dal].price  
  if context.dal in data:  
    order(context.dal,100)  
4 responses

are you getting a runtime error or is the algo simply not buying?

Hi Josh,

Without the if condition i got runtime error notradedataavailable.

Once i added the if conditon, no runtimeerror but it would not buy. Thanks!

Hello,

I think the issue is the dates that DAL traded i.e. 2002-01-02 to 2005-10-12. Outside of this period you will get the results you are seeing.

P.

Thanks a lot Peter!! This will get me started :)