Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to build an intraday strategy?

Hello all, I am new to quantopian, I want to build an intraday strategy where I would need previous day OHLC prices.
Can someone please give me a basic template for this. Once I have completed my strategy I will be more then happy to share it.

6 responses

Hi harsh, you can use the history function to get a trailing window of data.

For example,

# OPEN PRICE: this will return yesterday's open and today's open price of the last minute bar  
opens = history(2, '1d', 'open_price')  
# take yesterday's open price value  
yest_open = opens[-2]


# HIGH PRICE: this will return yesterday's high and today's current high price  
highs = history(2, '1d', 'high')  
# take yesterday's high  
yest_high = highs[-2]


# LOW PRICE: this will return yesterday's low and today's current low price  
lows = history(2, '1d', 'low')  
# take yesterday's low  
yest_low = lows[-2]


# CLOSE PRICE: this will return yesterday's close and today's current close_price of the last minute bar  
closes = history(2, '1d', 'close_price')  
# take yesterday's close price value  
yest_close = closes[-2]  

Looking forward to seeing your strategy!

Disclaimer

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.

Thank you Alisa :)
How do I make it completely intraday ?
Like I want to entry any trade after 10am and exit all the open trades if any at 3:30pm ?

You can use code logic to set requirements for actions at specific times. The code will check the time in the algorithm and execute according to your trading statements.

I'd caution against using a hard coded time, such as "if its exactly 10AM do this". This coding style is brittle and isn't robust if things happen unplanned. For example, if your live algorithm isn't logged in, IB's servers undergo maintenance, our data feed has an outage, etc. If the hard-coded time is missed, that statement won't get evaluated.

Instead, you can use logic to only enter the code statement once, within a time window. Here is a rebalancing strategy as an example: https://www.quantopian.com/posts/rebalance-algo-9-sector-etfs

And here's another thread that closes at the end of the day, but it uses the brittle, hard-coded time: https://www.quantopian.com/posts/problem-with-eod-closing-runtime-error

Okay so I was going through the api docs and found out that we can place target orders and stoploss orders. I have a confusion in that:
So suppose we placed both orders for a AAPL, now if my target is achieved will my stoploss order automatically get cancelled? Or vice-versa like if we hit the stoploss first will the target order get cancelled ?

I saw that Dan answered your question (https://www.quantopian.com/posts/get-open-orders-not-working-as-expected). It's great to see you exploring and let me know if I can answer other questions along the way!

Yeah :)
Thank you Alisa, will surely ask.