Back

Programmatic trendlines

Is there anything built into QuantConnect (Like an indicator or something) where you could create a trendline based off two or more points and be able to see when it has been crossed by incoming data?

I am looking for something that I can use on daily charts to look for patterns like double tops, double bottoms, Three Rising Valleys, etc and be able to trigger an insight when the pattern confirms.

I am familiar with the standard oscillators I see on the indicator documentation page, but I haven't found anything where I can do programmatic trendlines, it seems like something that would be here.

Any pointers would be appreciated! 

Update Backtest







0

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.


Hi Marcus,

You can find suitable indicators built in QuantConnect and then plot them for finding patterns on daily charts. As for incoming data, if you claim a specific symbol, then the indicator based on it will be automatically updated. If not, we suggest you register the indicator for automatic updates with the RegisterIndicator() method, so that you will get the trend of indicators when new data is included.

Also, if you want to design your own indicators to find valuable patterns (double tops, double bottoms, Three Rising Valleys, etc), you can create custom indicators as stated in here.

For further information, you might find Indicators and Charting references be very helpful.

Here is an example of creating custom indicators using C#. Hope it helps!

namespace QuantConnect.Algorithm.CSharp
{
public class CustomIndicatorAlgorithm : QCAlgorithm
{
CustomSimpleMovingAverage Custom;
SimpleMovingAverage SMA;

public override void Initialize()
{
SetStartDate(2013,10,7);
SetEndDate(2013,10,11);
AddEquity("SPY", Resolution.Second);
SetCash(100000);

SMA = SMA("SPY", 60, Resolution.Minute);
Custom = new CustomSimpleMovingAverage("custom", 60);
RegisterIndicator("SPY", Custom, Resolution.Minute);
}

/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// Slice object keyed by symbol containing the stock data
public override void OnData(Slice data)
{
if (Portfolio.Invested){
SetHoldings("SPY", 1);
}

if (Time.Second == 0){
Log(string.Format(" sma -> IsReady: {0}. Time: {1}. Value: {2}", SMA.IsReady, SMA.Current.Time, SMA.Current.Value));
Log(Custom.Value);
}
// Regression test: test fails with an early quit
var diff = Math.Abs(Custom.Value - SMA.Current.Value);
if (diff > 1e-25m){
Quit(string.Format("Quit: indicators difference is {0}", diff));
}
}

}

public class CustomSimpleMovingAverage : WindowIndicator<IndicatorDataPoint>
{
DateTime Time;
public decimal Value;
public bool IsReady;
public RollingWindow<decimal> RW;
public string Name;


public CustomSimpleMovingAverage(string name, int period): base(name, period){
Name = name;
Time = DateTime.MinValue;
Value = 0;
IsReady = false;
RW = new RollingWindow<decimal>(period);
}

public void Update(TradeBar input){
RW.Add(input.Close);
var count = RW.Count;
Time = input.EndTime;
Value = RW.Sum() / count;
IsReady = (count == RW.Size);
}

protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input)
{
return Value;
}
}
}

 

0

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.


Trendlines seem like something generic and useful enough to warrant inclusion in the standard library of indicators, I would imagine. Can be a nice base to build other chart patterns off.

0

Thanks for the answers so far, I think what I am hearing is that there isn't something currently in the framework that will do a trendline, I was thinking about building an indicator to do it, but I wanted to make sure I wasn't just duplicating something that was already built into the framework.

0

Update Backtest





0

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.


Loading...

This discussion is closed