namespace QuantConnect
{
/// <summary>
/// Shows how to use the Minus and Of extension methods to define a MACD on the
/// difference in closing price between two securities
/// </summary>
public class MacdOnDifferenceAlgorithm : QCAlgorithm
{
/// <summary>
/// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
/// </summary>
public override void Initialize()
{
SetStartDate(2011, 01, 01); //Set Start Date
SetEndDate(2015, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
// Find more symbols here: http://quantconnect.com/data
AddSecurity(SecurityType.Forex, "USDCAD", Resolution.Daily);
//AddSecurity(SecurityType.Equity, "MSFT", Resolution.Daily);
AddData<QuandlFuture>("SCF/CME_CL1_ON", Resolution.Daily);
// Identity will get updated on each data point before OnData gets called
var msft = Identity("SCF/CME_CL1_ON");
var aapl = Identity("USDCAD");
// Minus will get free updates from it's components pieces (msft, aapl)
var diff = msft.Minus(aapl);
// Of will get free updates from it's parent indicator (diff)
var macdDiff = new MovingAverageConvergenceDivergence("CL1_CAD_MACD", 12, 26, 9).Of(diff);
// Plot macdDiff on each new update
PlotIndicator("CL1_CAD_MACD", macdDiff);
}
/// <summary>
/// OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
/// </summary>
/// <param name="data">Slice object keyed by symbol containing the stock data</param>
public override void OnData(Slice data)
{
if (!Portfolio.Invested)
{
SetHoldings("SCF/CME_CL1_ON", .5);
SetHoldings("USDCAD", .5);
}
}
}
public class QuandlFuture : Quandl
{
public QuandlFuture()
: base(valueColumnName: "Settle")
{
}
}
}