forked from QuantConnect/Lean
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWarmupAlgorithm.cs
More file actions
50 lines (46 loc) · 1.59 KB
/
WarmupAlgorithm.cs
File metadata and controls
50 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using QuantConnect.Data;
using QuantConnect.Indicators;
namespace QuantConnect.Algorithm.CSharp
{
public class WarmupAlgorithm : QCAlgorithm
{
private bool first = true;
private const string symbol = "SPY";
private const int FastPeriod = 60;
private const int SlowPeriod = 3600;
private ExponentialMovingAverage fast, slow;
public override void Initialize()
{
SetStartDate(2013, 10, 08); //Set Start Date
SetEndDate(2013, 10, 11); //Set End Date
SetCash(100000); //Set Strategy Cash
// Find more symbols here: http://quantconnect.com/data
AddSecurity(SecurityType.Equity, symbol, Resolution.Second);
fast = EMA(symbol, FastPeriod);
slow = EMA(symbol, SlowPeriod);
SetWarmup(SlowPeriod);
}
/// <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 (first && !IsWarmingUp)
{
first = false;
Console.WriteLine("Fast: " + fast.Samples);
Console.WriteLine("Slow: " + slow.Samples);
}
if (fast > slow)
{
SetHoldings(symbol, 1);
}
else
{
SetHoldings(symbol, -1);
}
}
}
}