Hi, I'm not sure how to do this using an indicator. I've tried the following which doesn't work on multiple levels. I couldn't find a simple example where an algo gets the High of a couple of bars ago.
var spy_ind = Identity(spy, Resolution.Hour);
high_2 = new Delay(2).Of(Identity(spy));
RegisterIndicator(spy, high_2, Resolution.Hour);
Dan Whitnable
Alpha, are you looking for a C# or Python solution? Simple in Python using the 'History' method.
Alpha
Hi Dan, C# please. While on that topic, how would you force an SMA indicator to run on the High prices? I believe below runs on .Value which defaults to Close.
ema_fast = EMA(spy, 30, Resolution.Hour);
I was looking at the DisplacedMovingAverageRibbon.cs example for this.
The longer answer is that I'm a python quant but the following has made me switch to C#. If you know solutions to this, I'm back to python!
1. Desktop IDE Doesn't offer code analysis for python
2. environment "backtesting-desktop" doesn't seem to be doing the graphical plot.
Thanks!
Jared Broad
@Alpha - Field.High
- Desktop IDE code analysis is driven by your IDE, but people have been able to debug python algorithms in Visual Studio.
- Correct I think the desktop charting isn't great for custom plots but its open source so you can write your own ;)
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.
Alpha
Thanks Jared Broad
Alpha
Jared Broad I am having trouble getting the last 2 bars of data. I have minute data and I've consolidated it to 60 minute bars. In my 60 minute bar handler I do:
var bar = History<TradeBar>(btcusd, 2);
The full example is:
using System;
using System.Collections.Generic;
using System.Linq;
using Accord.Statistics.Links;
using QuantConnect.Brokerages;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Indicators;
using QuantConnect.Indicators.CandlestickPatterns;
namespace QuantConnect.Algorithm.CSharp
{
public class Test: QCAlgorithm
{
protected Symbol btcusd = QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX);
protected decimal signal(TradeBar data)
{
var bar = History<TradeBar>(btcusd, 2);
if (!(bar.Count() > 0)) { return 0.0m; }
return 0.0m;
}
private void ConsolidatedBarHandler(object sender, TradeBar data)
{
Order(btcusd, signal(data);
}
public override void Initialize()
{
// set up our analysis span
SetStartDate(2014, 1, 1);
SetEndDate(2015, 5, 30);
AddCrypto(btcusd, Resolution.Minute);
var consolidator = new TradeBarConsolidator(TimeSpan.FromMinutes(60));
consolidator.DataConsolidated += ConsolidatedBarHandler;
SubscriptionManager.AddConsolidator(btcusd, consolidator);
}
public void OnData(TradeBars data)
{
}
}
}
Alpha
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!