Summary: This analyst script is used to determine whether an underlying indicator is in a downwards momentum. A downwards momentum exists when the underlying indicator is negative, trending down and reaching a minimum specified percentage decrease. Values: 1. 0 - No downwards momentum detected. 2. -100 - Downwards momentum detected.
' Get the analyzed indicator values, indexed by bar index. Define values() As Number = IndicatorValues(_analyzedIndicatorKey, barIndex, _periods) ' Get the SMA indicator values, indexed by bar index. Define SMAValues() As Number = IndicatorValues(_smaIndicatorKey, barIndex, _periods) ' If the latest analyzed indicator value decreased at least the specified minimum amount. If (values(0) < values(_periods - 1) * (1 - _minPercentDecrease / 100)) Then ' Iterate over the analyzed indicator values making sure that none crossed the simple moving average. ' and that none crossed the zero line. For i As Integer = _periods - 1 To 0 Step -1 If (values(i) > SMAValues(i) Or values(i) > 0) Then Return 0 End If Next ' If the analyzed indicator is negative, decreased enough and never crossed its simple moving average ' then it is in a downwards momentum. Return -100 End If Return 0
' Assign the script parameters to script variables. _analyzedIndicatorKey = analyzedIndicatorKey _periods = periods _minPercentDecrease = minPercentDecrease ' Initialize a simple moving average over the analyzed indicator. _smaIndicatorKey = IndicatorSMA(_analyzedIndicatorKey, _periods)