Skip to content

Commit

Permalink
Improve some indicator stuff
Browse files Browse the repository at this point in the history
Make ROCP computation a little easier to follow
Return the raw type of 'second' in .Of extension
  • Loading branch information
mchandschuh committed Apr 27, 2015
1 parent d5731b5 commit c1b62d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Indicators/IndicatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public static void Update(this IndicatorBase<IndicatorDataPoint> indicator, Date
/// <param name="first">The indicator that sends data via DataConsolidated even to the second</param>
/// <param name="waitForFirstToReady">True to only send updates to the second if first.IsReady returns true, false to alway send updates to second</param>
/// <returns>The reference to the second indicator to allow for method chaining</returns>
public static IndicatorBase<IndicatorDataPoint> Of<T>(this IndicatorBase<IndicatorDataPoint> second, IndicatorBase<T> first, bool waitForFirstToReady = true)
public static TSecond Of<T, TSecond>(this TSecond second, IndicatorBase<T> first, bool waitForFirstToReady = true)
where T : BaseData
where TSecond : IndicatorBase<IndicatorDataPoint>
{
first.Updated += (sender, consolidated) =>
{
Expand Down
10 changes: 6 additions & 4 deletions Indicators/RateOfChangePercent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public RateOfChangePercent(string name, int period)
/// <returns>A new value for this indicator</returns>
protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input)
{
if (!window.IsReady)
// if we're not ready just grab the first input point in the window
decimal denominator = !window.IsReady ? window[window.Count - 1] : window.MostRecentlyRemoved;

if (denominator == 0)
{
// keep returning the delta from the first item put in there to init
return window[window.Count - 1] == 0 ? 0 : 100 * (input - window[window.Count - 1]) / window[window.Count - 1];
return 0;
}

return window.MostRecentlyRemoved == 0 ? 0 : 100 * (input - window.MostRecentlyRemoved) / window.MostRecentlyRemoved;
return 100*(input - denominator)/denominator;
}
}
}

0 comments on commit c1b62d8

Please sign in to comment.