Saturday, September 04, 2010

Indicator Support / Resistance [ISR]

Descripton
Summary:
This heat study script generates values based on support and resistance levels of an indicator.

Returns:
Support: 1
Resistance: -1


Variables
TypeIdentifierDescription
IntegerArray_indicatorKeysUse for holding all of the indicator keys duplicated from the specified indicator key and indexed by symbol index.
IntegerArray_supportIndicatorKeysUse for holding all of the support indicator keys duplicated from the specified support indicator key and indexed by symbol index.
IntegerArray_resistanceIndicatorKeysUse for holding all of the resistance indicator keys duplicated from the specified resistance indicator key and indexed by symbol index.
Number_supportMarginUse for the percentage distance from the support level in which support starts.
Number_resistanceMarginUse for the percentage distance from the resistance level in which resistance starts.

OnInitialize
Function Parameters
TypeIdentifierDescription
IndicatorindicatorKeyUse for the indicator key.
IndicatorsupportIndicatorKeyUse for the support indicator key to duplicate for all of the account symbols and with which trading signals will be generated.
IndicatorresistanceIndicatorKeyUse for the resistance indicator key to duplicate for all of the account symbols and with which trading signals will be generated.
NumbersupportMarginUse for the percentage distance from the support level in which support starts. [Default 0.2]
NumberresistanceMarginUse for the percentage distance from the resistance level in which resistance starts. [Default 0.2]
Implementation
	 ' Assign the script parameters to script variables.
	_supportMargin = supportMargin
	_resistanceMargin = resistanceMargin
	
	 ' Use for holding indicator keys based on the specified indicator key, indexed by symbol index.
	Redefine _indicatorKeys(SymbolCount() - 1)
	 ' Use for holding indicator keys based on the specified support indicator key, indexed by symbol index.
	Redefine _supportIndicatorKeys(SymbolCount() - 1)
	 ' Use for holding indicator keys based on the specified resistance indicator key, indexed by symbol index.
	Redefine _resistanceIndicatorKeys(SymbolCount() - 1)
	 ' Iterate over all of the account symbols.
	For i As Integer = 0 To SymbolCount() - 1
		 ' Create an indicator for each account symbol, based on the specified indicator.
		_indicatorKeys(i) = IndicatorCopy(indicatorKey, i)

		 ' Create an indicator for each account symbol, based on the specified support indicator.
		_supportIndicatorKeys(i) = IndicatorCopy(supportIndicatorKey, i)

		 ' Create an indicator for each account symbol, based on the specified resistance indicator.
		_resistanceIndicatorKeys(i) = IndicatorCopy(resistanceIndicatorKey, i)
	Next

OnValue
Function Parameters
TypeIdentifierDescription
IntegersymbolIndex
Implementation
	 ' Get the indicator value, indexed by bar index.
	Define value As Number = IndicatorValue(_indicatorKeys(symbolIndex))
	 ' Get the support indicator value, indexed by bar index.
	Define supportValue As Number = IndicatorValue(_supportIndicatorKeys(symbolIndex))
	 ' Get the resistance indicator value, indexed by bar index.
	Define resistanceValue As Number = IndicatorValue(_resistanceIndicatorKeys(symbolIndex))
	
	 ' Support.
	If (supportValue <= value And value <= supportValue * (1 + _supportMargin)) Then
		Return 1
	 ' Resistance.
	ElseIf  (resistanceValue * (1 + _resistanceMargin) <= value And value <= resistanceValue) Then
		Return -1
	End If

Copyright © 2010 IQBroker, LLC. All rights reserved.