@@ -14,8 +14,8 @@ namespace QuantConnect.Algorithm.CSharp
14
14
public class DailyResolutionVsTimeSpanRegressionAlgorithm : QCAlgorithm , IRegressionAlgorithmDefinition
15
15
{
16
16
private Symbol _spy ;
17
- private RelativeStrengthIndex _relativeStrengthIndex1 ;
18
- private RelativeStrengthIndex _relativeStrengthIndex2 ;
17
+ protected RelativeStrengthIndex RelativeStrengthIndex1 ;
18
+ protected RelativeStrengthIndex RelativeStrengthIndex2 ;
19
19
private bool _dataPointsReceived ;
20
20
21
21
public override void Initialize ( )
@@ -25,22 +25,24 @@ public override void Initialize()
25
25
26
26
_spy = AddEquity ( "SPY" , Resolution . Hour ) . Symbol ;
27
27
28
+ SetDailyPreciseEndTime ( ) ;
29
+
28
30
// First RSI: Updates at market close (4 PM) using daily resolution (9:30 AM to 4 PM)
29
- _relativeStrengthIndex1 = new RelativeStrengthIndex ( 14 , MovingAverageType . Wilders ) ;
30
- RegisterIndicator ( _spy , _relativeStrengthIndex1 , Resolution . Daily ) ;
31
+ RelativeStrengthIndex1 = new RelativeStrengthIndex ( 14 , MovingAverageType . Wilders ) ;
32
+ RegisterIndicator ( _spy , RelativeStrengthIndex1 , Resolution . Daily ) ;
31
33
32
34
// Second RSI: Updates every 24 hours (from 12:00 AM to 12:00 AM) using a time span
33
- _relativeStrengthIndex2 = new RelativeStrengthIndex ( 14 , MovingAverageType . Wilders ) ;
34
- RegisterIndicator ( _spy , _relativeStrengthIndex2 , TimeSpan . FromDays ( 1 ) ) ;
35
+ RelativeStrengthIndex2 = new RelativeStrengthIndex ( 14 , MovingAverageType . Wilders ) ;
36
+ RegisterIndicator ( _spy , RelativeStrengthIndex2 , TimeSpan . FromDays ( 1 ) ) ;
35
37
36
38
// Warm up indicators with historical data
37
39
var history = History < TradeBar > ( _spy , 20 , Resolution . Daily ) . ToList ( ) ;
38
40
foreach ( var bar in history )
39
41
{
40
- _relativeStrengthIndex1 . Update ( bar . EndTime , bar . Close ) ;
41
- _relativeStrengthIndex2 . Update ( bar . EndTime , bar . Close ) ;
42
+ RelativeStrengthIndex1 . Update ( bar . EndTime , bar . Close ) ;
43
+ RelativeStrengthIndex2 . Update ( bar . EndTime , bar . Close ) ;
42
44
}
43
- if ( ! _relativeStrengthIndex1 . IsReady || ! _relativeStrengthIndex2 . IsReady )
45
+ if ( ! RelativeStrengthIndex1 . IsReady || ! RelativeStrengthIndex2 . IsReady )
44
46
{
45
47
throw new RegressionTestException ( "Indicators not ready." ) ;
46
48
}
@@ -51,20 +53,25 @@ public override void Initialize()
51
53
Schedule . On ( DateRules . EveryDay ( ) , TimeRules . At ( 17 , 0 , 0 ) , CompareValuesAfterMarketHours ) ;
52
54
}
53
55
54
- private void CompareValuesDuringMarketHours ( )
56
+ protected virtual void SetDailyPreciseEndTime ( )
57
+ {
58
+ Settings . DailyPreciseEndTime = true ;
59
+ }
60
+
61
+ protected virtual void CompareValuesDuringMarketHours ( )
55
62
{
56
- var value1 = _relativeStrengthIndex1 . Current . Value ;
57
- var value2 = _relativeStrengthIndex2 . Current . Value ;
63
+ var value1 = RelativeStrengthIndex1 . Current . Value ;
64
+ var value2 = RelativeStrengthIndex2 . Current . Value ;
58
65
if ( value1 != value2 )
59
66
{
60
67
throw new RegressionTestException ( "The values must be equal during market hours" ) ;
61
68
}
62
69
}
63
70
64
- private void CompareValuesAfterMarketHours ( )
71
+ protected virtual void CompareValuesAfterMarketHours ( )
65
72
{
66
- var value1 = _relativeStrengthIndex1 . Current . Value ;
67
- var value2 = _relativeStrengthIndex2 . Current . Value ;
73
+ var value1 = RelativeStrengthIndex1 . Current . Value ;
74
+ var value2 = RelativeStrengthIndex2 . Current . Value ;
68
75
69
76
if ( value1 == value2 && _dataPointsReceived == true )
70
77
{
0 commit comments