Hi, Is there a way where i can code up a strategy based “touch detection”.
For example, the indicator automatically identify strong support and resistance levels that the price has touched multiple times. It has to touch a minimum of 2 times, before a limit order will be submitted.
I see alot of indicators, but i just want a simple support and resistance level; and how do i store it to see if the price will touch it again?
Thanks!
Mia Alissi
QuantConnect provides a wide range of indicators, but it doesn't have a built-in method for identifying support and resistance levels. However, you can implement this yourself by analyzing price data.
To identify support and resistance levels, you could track the highs and lows of the price over a certain period and store these values. If the price touches these levels again, it could be considered a touch of the support or resistance level.
Here's a simple example of how you might implement this in Python:
In this example, we're using the MAX and MIN indicators to track the highest and lowest prices over the last 14 days. When the current price touches these levels, we log a message and you can add your limit order logic there.
Remember, this is a very basic example and real-world market conditions can be much more complex. You might want to consider factors like volume, volatility, and the overall trend when identifying support and resistance levels.
For more information on how to use indicators and handle data in QuantConnect, you can refer to the documentation and example algorithms provided in the extracts.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Muhammad Yusuf Bin Salleh
Thanks Mia, but i would like the price to touch these levels at least twice before adding a limit order logic. How do i go about doing that?
Mia Alissi
To implement a strategy that requires the price to touch the support or resistance levels at least twice before placing a limit order, you can keep track of the number of touches for each level.
Here's a simple way to do this in Python:
In this example, we're incrementing
self.resistance_touches
andself.support_touches
each time the price touches the resistance or support level, respectively. When the count reaches 2, you can add your limit order logic.Remember to reset these counters when your conditions are met, or they will continue to increment each time the price touches these levels.
This is a simple example and may not cover all scenarios. You might want to add more conditions to better define what constitutes a "touch" of a level, or to handle cases where the price breaks through a level rather than bouncing off it.
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Muhammad Yusuf Bin Salleh
Thanks! How do i reset it then :)
Mia Alissi
You can reset the counters by simply setting them back to zero when your conditions are met. For example, if you place a limit order when the price touches a level twice, you can reset the counter at that point. Here's how you might do it:
In this example,
self.resistance_touches = 0
andself.support_touches = 0
are used to reset the counters after a limit order is placed.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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Muhammad Yusuf Bin Salleh
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!