| Overall Statistics |
|
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
namespace QuantConnect
{
class SimpleExample : QCAlgorithm
{
Symbol _symbol;
AverageDirectionalIndex _adx;
RollingWindow<IndicatorDataPoint[]> _window;
public override void Initialize()
{
SetStartDate(2015, 11, 01);
SetEndDate(2015, 11, 2);
SetCash(10000);
_symbol = AddForex("EURUSD").Symbol;
_adx = new AverageDirectionalIndex("ADX_14_5", 14);
_window = new RollingWindow<IndicatorDataPoint[]>(2);
// Here is where the RollingWindow is updated with the latest SMA observation.
_adx.Updated += (object sender, IndicatorDataPoint updated) =>
{
_window.Add(new IndicatorDataPoint[]
{
_adx.PositiveDirectionalIndex.Current,
_adx.NegativeDirectionalIndex.Current
});
};
var fiveMinuteConsolidator = new QuoteBarConsolidator(TimeSpan.FromMinutes(5));
SubscriptionManager.AddConsolidator(_symbol, fiveMinuteConsolidator);
RegisterIndicator(_symbol, _adx, fiveMinuteConsolidator);
}
public override void OnData(Slice slice)
{
if (!_window.IsReady) return;
Log("Actual PositiveDirectionalIndex value :" + _adx.PositiveDirectionalIndex);
Log("Actual NegativeDirectionalIndex value :" + _adx.NegativeDirectionalIndex);
Log("Previous PositiveDirectionalIndex: " + _window[1][1]);
Log("Previous NegativeDirectionalIndex: " + _window[1][0]);
// Here you can implement your logic.
if (_window[1][0] > _window[0][1])
{
//Do stuff
}
}
}
}