Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
i'll give anyone a dollar if they can explain why this isn't placing an order. set_max_position error

tells me i can't go long 1 share when my max_position is set to >30 - it makes no sense

def initialize(context):  
    set_max_position_size(sid(24), max_shares=30, max_notional=2000.0)  
    context.aapl = sid(24)

    #portfolio can only have 1 share of AAPL at a time  
def handle_data(context, data):  
    #the sume of the prior 11 minutes volume, excluding the most recent minute  
    hist = data.history(sid(24), 'volume', 10, '1m')  
    vol_10 = hist[0:10].sum()  
    #volume of the most recent minute  
    vol_1 =  hist[0]  
    #define current trading day low price  
    day_low = data.history(sid(24), 'low', 1, '1d')  
    #define current price  
    current_price = data.current(sid(24), 'price')  
    #define cost basis  
    cost_basis = context.portfolio.positions[context.aapl].cost_basis  
    #define current position  
    current_position = context.portfolio.positions[context.aapl].amount  
    #if most recent minute volume is > 25% of the prior 10 minutes total volume  
    #and the current price is within 5 minutes of the low price  
    #for the day, buy 1 share of AAPL  
    if vol_1 > vol_10 *.25:  
        order(context.aapl, 1)  
    #if position opened, simultaneously open stop loss order at .999% of cost basis  
    if current_position > 0:  
        order(context.aapl, -1, style=StopOrder(cost_basis *.99))  

error is: TradingControlViolation
There was a runtime error on line 26.
Order for 1 shares of Equity(24 [AAPL]) at 2017-01-05 14:40:00+00:00 violates trading constraint MaxPositionSize('max_notional': 2000.0, 'max_shares': 30, 'asset': Equity(24, symbol=u'AAPL', asset_name=u'APPLE INC', exchange=u'NASDAQ', start_date=Timestamp('2002-01-01 00:00:00+0000', tz='UTC'), end_date=Timestamp('2017-05-01 00:00:00+0000', tz='UTC'), first_traded=None, auto_close_date=Timestamp('2017-05-04 00:00:00+0000', tz='UTC'), exchange_full=u'NASDAQ GLOBAL SELECT MARKET')).Learn More

2 responses

this i figured it out. order error:

if vol_1 > vol_10 *.25:

had to take away *.25

Does that mean I won't get a dollar?