Back

Need some help with the Delay() indicator please

Hi, I'm really strugling understanding how to use the Delay() indicator. It is a usual case to want to look at the value of an indicator X bars ago. This is my usual algorithm template. Running the sample below throws the following error pointing at the RegisterIndicator() line. Thanks for any comments/recommendations/criticisms:

 

20171119 23:49:30.893 ERROR:: ConsoleSetupHandler.Setup(): System.ArgumentException: Type mismatch found between consolidator and indicator for symbol: BTCUSD.Consolidator outputs type TradeBar but indicator expects input type IndicatorDataPointusing System;
using System.Collections.Generic;
using System.Linq;
using QuantConnect.Brokerages;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;

namespace QuantConnect.Algorithm.CSharp
{
public class TestMACD: QCAlgorithm
{
protected Symbol btcusd = QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX);
private MovingAverageConvergenceDivergence MacD;
private List<MovingAverageConvergenceDivergence> MacDs;

private Delay delay;
private Delay delayedMacD;

private void ConsolidatedBarHandler(object sender, TradeBar data)
{
if (!MacD.IsReady) return;
Debug(String.Format("{0} -> {1}",data.Time.ToString(), data.EndTime.ToString()));
}

public override void Initialize()
{
// set up our analysis span
SetStartDate(2014, 1, 1);
SetEndDate(2015, 1, 1);
SetCash(1e6);
SetBenchmark(btcusd);
// SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
SetWarmUp(TimeSpan.FromMinutes(60));

AddCrypto(btcusd, Resolution.Minute);


var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(60));
consolidator.DataConsolidated += ConsolidatedBarHandler;
SubscriptionManager.AddConsolidator(btcusd, consolidator);

MacD = MACD(btcusd, 26, 12, 9, MovingAverageType.Exponential, Resolution.Hour, Field.Close);

var MacD2 = new MovingAverageConvergenceDivergence(btcusd, 26, 12, 9, MovingAverageType.Exponential);
delay = new Delay(2);
delayedMacD = delay.Of(MacD2);
RegisterIndicator("BTCUSD", delayedMacD, Resolution.Minute);

}

public void OnData(TradeBars data)
{

}
}
}

Update Backtest








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