Tuesday, September 07, 2010

Indicator Downwards Momentum [IDM]

Descripton
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.


Variables
TypeIdentifierDescription
Integer_analyzedIndicatorKeyUse for the indicator key to analyze for downwards momentum.
Integer_periodsUse for the number of periods to check for a downwards momentum.
Number_minPercentDecreaseUse for the minimum percentage that the analyzed indicator must decrease from the oldest period to the latest one.
Integer_smaIndicatorKeyUse for the simple moving average indicator key of the analyzed indicator.

OnAnalysis
Function Parameters
TypeIdentifierDescription
IntegerbarIndex
Implementation
	 ' 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

OnInitialize
Function Parameters
TypeIdentifierDescription
IndicatoranalyzedIndicatorKeyUse for the indicator key to analyze for downwards momentum.
IntegerperiodsUse for the number of periods to check for a downwards momentum. [Default 20]
NumberminPercentDecreaseUse for the minimum percentage that the test indicator must decrease from the oldest period to the latest one. [Default 10]
Implementation
	 ' 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)

Copyright © 2010 IQBroker, LLC. All rights reserved.