this a once a day balancing of my current positions, for some reason it won't go live but it is still backtest it
this a once a day balancing of my current positions, for some reason it won't go live but it is still backtest it
Try removing the spaces between data[stoc] and .mavg's. Like this:
MA1 = data[stock].mavg(50)
MA2 = data[stock].mavg(200)
Where you have:
A1 = data[stock] .mavg(50)
MA2 = data[stock] .mavg(200)
Then test live testing it.
After a full backtest that is. And you would have to make sure you have your brokerage account connected to your profile before you can live trade it as well
After a full backtest that is. And you would have to make sure you have your brokerage account connected to your profile before you can live trade it as well
William Gallosa,
Try this may be it will help you.
def initialize(context):
schedule_function(trade,date_rules.every_day(),time_rules.market_open(minutes=65))
def trade(context, data):
#-----------------------------------------------------------------------------------
stocks = symbols('AMZN', 'FB', 'BABA', 'AAPL', 'NKE', 'TLT', 'TSLA', 'UA', 'SBUX', )
ma_f, ma_s = 50, 200
#-----------------------------------------------------------------------------------
ma_fast = data.history(stocks, 'price', ma_f, '1d').mean()
ma_slow = data.history(stocks, 'price', ma_s, '1d').mean()
ratio = ma_fast / ma_slow
pos_trend = ratio[ratio >= 1.0]
wt_stk = 1.0 / len(stocks)
if get_open_orders(): return
for stock in stocks:
if data.can_trade(stock):
if stock in pos_trend.index:
order_target_percent(stock, wt_stk)
else:
order_target_percent(stock, 0)
record(Leverage = context.account.leverage)
William,
Vladimir's solution is a good one. The reason your original version is not able to trade live is because it's using an old version of the API that is deprecated. The best way to learn the current API is to go through the Getting Started Tutorial.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.