pandas-ta: How to use or implement Opening Range Breakout Strategy with EMA in real market
Which version are you running? The lastest version is on Github. Pip is for major releases.
import pandas_ta as ta
print(ta.version)
0.1.97b
Upgrade.
$ pip install -U git+https://github.com/twopirllc/pandas-ta
Is your feature request related to a problem? Please describe. Not exactly. I want to understand how to use pandas_ta for opening range or time range breakout strategies in real market. Is it only for technical analysis or can be used in real market.
Describe the solution you’d like Some example in real market suppose I want to use it for Indian broker like Zerodha/AliceBlue/Samco who provide API and tick data. I want to create a simple opening range breakout strategy for first 15min or 30min or 1hr time. But at the same time want to check whether LTP is above EMA 21, how can I do it using pandas_ta? How to create this custom strategy and where I should use the broker API when I get a signal. I saw the jupyter notebooks there is too much information and it confuses me a lot. Simple examples can be helpful.
Thanks for using Pandas TA!
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 24 (10 by maintainers)
So finally I started working on this long pending stuff. Here is my code
Hello @rahulmr,
Upgrade
You have not upgraded. Here is how to upgrade:
Questions
Pandas TA is used to calculate indicators and can be used in a real market. Pandas TA is one component of an Algo Trading system. It is up to the user to implement their Algo Trading components: Broker, Order Execution, TA, Backtesting/Forward Testing, et al or modify an existing Algo System to fit your needs.
I’m sorry to hear that it is confusing for you. Would you like to submit a simpler example Notebook that would be helpful for you and other users that may also find them confusing? If so, that would be greatly appreciated.
ORBx Pseudo Algo
I recommend reading How to utilize this Framework for live ticks Issue #87. Note: It doesn’t matter that it mentions ticks, it can be applied to minutes or 5 minutes et al. Much of the logic is already written in that post however you will not need to use the
ta.strategy()method since your only TA is anema. If you are using more thanema, then I recommend usingta.strategy()as it is designed to handle bulk indicator processing by utilizing mulitprocessing.Also please take some time and review some of the other repositories that you have forked regarding Breakout Strategies. There may be some good info to include as well.
You should be testing on a Paper Trading Account like your Broker or simulate it yourself.
Here is some pseudocode for ORBx, where x is the number of minutes:
NaNdfdf.ta.ema(length=21, append=True)df.ta.ema(length=21, append=True)pass. Otherwise, update ORBx_high and ORBx_low.dfIf you would like for me to do it, then we can discuss it offline. However if you would like some assistance with this, then you will have to do the coding above and share it here so I can help. Or you can create a Jupyter Notebook and make a Pull Request and we can do it together that way and help everyone using the library.
Hope this helps!
Thanks, KJ
Hello @rahulmr,
Just came across hackingthemarkets: Fullstack Trading App repo. It contains an ORB Strategy (backtest.py) but using Alpaca API (
import alpaca_trade_api) for trade execution. It may be a good starting point to decompose and replace Alpaca with your broker. Of course you will need to forward test on a paper/demo account and adjust it for live execution.Kind Regards, KJ
Hello @rahulmr,
Just came across a MT5 Algo Trading System. It covers the basics pretty well with additional functionality. It may address some of your questions.
KJ
@rahulmr
Thanks for the screenshots. Just letting you know I haven’t forgotten and not ignoring the issue. I have some personal stuff to take care of and can hopefully get back to helping you soon.
Thanks KJ
Hello @rahulmr,
Let’s handle this as a separate Issue #176.
Thanks, KJ
Don’t worry about the access token so much. It will expire someday. And it is only for streaming data and not for order placement.
I also got a way to get streaming data from TV - check it here with crypto example and valid for some NSE stocks as well.
@rahulmr,
Cool. I will check it out as soon as I can.
One thing I noticed is that you shared your
access_token. I would fix it ASAP by installing python-dotenv to use a.envfile to load youraccess_tokenso others do not have access to it.KJ
Hello @rahulmr,
Great!
Also, I recently came across this blog post. The Traders Guide to Mythological Constructs - Paracurve. A lot of good stuff to digest when you have some time.
Regards, KJ
@twopirllc Thanks I am loving the discussion. I will work on the points you have suggested.
Hello @rahulmr,
Yes, this is one of the primary reasons why I made Pandas TA. In some cases TA Lib is hard to install and it’s unfortunately development stalled.
Ok. Seems reasonable.
If we are considering Intraday, then maybe Price Action yields more money. Are these Day Trading Videos? Have any links? Are they using any indicators? I am curious how they understand what indicators are and what they are promoting. Do they have proof and Third Party audited results?
If we are considering Swing and Positional Trading, I highly doubt Price Action yields more money is always true. For daily, weekly or monthly time frames, everyone is using them in some capacity even if it just one additional non-constant feature calculated from the initial data set. Often quoted in American Financial Media are the following indicators, SMA10, SMA20, SMA50, SMA200, and Vol SMA20 and act as a “baseline”.
In the case of the Inside Bar Strategy, the general code is similar to the AI Example Notebook. However we will need to change the
longvariable to it’s Inside Bar Long Logic prior to generating the trend, it’s trend return and trading signals as the rest of the Notebook shows.Furthermore, in my opinion, there is some false narratives out there regarding indicators. But that’s a different discussion altogether.
I have converted several popular indicators from TradingView already, including a few of my own. For instance Lazybear’s Squeeze (one of the most popular TV indicators) is in the Example Notebook. You likely will not find these indicators anywhere else for the time being in Python Open Source Libraries.
Awesome! Can you get some of it built? Even if it’s only acquiring data and getting a live stream running, that is ok. Create it in the
examplesdirectory. Submit a Pull Request and I’ll merge it into thedevelopmentbranch and we can go from there.How come? Some come submit PRs and usually I add more indicators from multiple sources. Plus I have other features that I am trying to add to Pandas TA like stochastic generators, backtesting and risk analysis to start. Plenty to do with my limited free time.
You are right, there is no need to always use a Jupyter Notebook. However in many cases, visualization of the indicators carry more weight. Once someone is comfortable with the indicator visualization, it is easy to later include it in it’s own module.
In fact I have already done so in the Examples directory with the watchlist module. The watchlist module’s use is shown in both PandasTA Strategy Examples and AIExample. Users are welcome to copy and modify the watchlist module to be modified to include your own datasource/broker to download the data and generate indicator results with a Pandas Strategy. Contributions are welcome to the watchlist module and potentially grow into it’s own Open Source package.
Regards, KJ
@twopirllc Hey sorry was busy with some office work. Thanks for the detailed explanation. I will try it out. Sometimes too much is also confusing so asked for helped. Once I am done with the code I will get back to you. Thanks for creating a good module. The TA-Lib installation itself was too hectic.