Tuesday, September 07, 2010

Bolton-Tremblay [BTI]

Descripton
Summary: 
This indicator script is an exchange breadth indicator, that is used to spot trend changes in the exchange and measure the general exchange strength and weakness. 

Calculation:
Complex, see script.

Interpretation: 
1. Positive Divergence:  When the underlying exchange is moving downwards, but the indicator script is moving upwards, the underlying exchange is likely to reverse direction and move upwards.
2. Negative Divergence:  When the underlying exchange is moving upwards, but the indicator script is moving downwards, the underlying exchange is likely to reverse direction and move downwards.
3. Upwards Trend: When the indicator script is moving upwards, the underlying exchange is in an upwards trend.
4. Downwards Trend: When the indicator script is moving downwards, the underlying exchange is in a downwards trend.


Variables
TypeIdentifierDescription
String_exchangeIDUse for the exchange ID of the symbols to include in the Bolton-Tremblay. (i.e. NYSE, LSE, NASDAQ)
Integer_symbolCountUse for the number of symbols in the symbol group.

OnInitialize
Function Parameters
TypeIdentifierDescription
StringexchangeIDUse for the exchange ID of the symbols to include in the Bolton-Tremblay. (i.e. NYSE, LSE, NASDAQ) [Default NYSE]
Implementation
	 ' Assign the parameter to a script variable and make sure it is in upper case.
	_exchangeID = StringToUpper(exchangeID)
	_symbolCount = SymbolCount()
	 ' Find a symbol index that matches the specified exchange ID.
	Define symbolIndex As Integer = -1
	For i As Integer = 0 To _symbolCount - 1
		If (SymbolExchangeID(i) = _exchangeID)
			symbolIndex = i
		End If
	Next
	 ' Initialize the indicator as an index.
	IndicatorIndex(symbolIndex)

OnValues
Function Parameters
TypeIdentifierDescription
IntegerbarIndex
Integerlength
Implementation
	 ' Use for the number of advancing symbols, indexed by bar index. 
	Define advancing(length - 1) As Number
	 ' Use for the number of declining symbols, indexed by bar index.
	Define declining(length - 1) As Number
	 ' Use for the number of unchanged symbols, indexed by bar index.
	Define unchanged(length - 1) As Number
	 ' Use for the calculated Bolton-Tremblay values, indexed by bar index.
	Define results(length - 1) As Number
	 ' Iterate over all of the symbols in the group.
	For symbolIndex As Integer = 0 To _symbolCount - 1
		 ' Only process symbols that belong to the specified exchange.
		If (SymbolExchangeID(symbolIndex) = _exchangeID) Then
			 ' Get the opening prices of the current symbol, indexed by bar index.  
			Define open() As Number = BarOpen(symbolIndex, barIndex, length)
			 ' Get the closing prices of the current symbol, indexed by bar index. 
			Define close() As Number = BarClose(symbolIndex, barIndex, length)
			 ' Iterate over all of the symbol bars while counting the advancing and declining bars.
			For i As Integer = length - 1 To 0 Step -1
				If (close(i) > open(i)) Then
					advancing(i) += 1
				Else If (close(i) < open(i)) Then
					declining(i) += 1
				Else
					unchanged(i) += 1
				End If
			Next
		End If
	Next

     ' Get the last indicator value.
	Define indexValue As Number = IndicatorIndexValue()
	Define R As Number
	 ' Calculate the Bolton-Tremblay values for the specified bar range.
	For i As Integer = length - 1 To 0 Step -1
		 ' Calculate the Bolton-Tremblay value for the current bar.
		R = (advancing(i) / unchanged(i)) - (declining(i) / unchanged(i)) 
		If (R > 0) Then
			indexValue += MathSqrt(MathAbs(R))
		Else
			indexValue -= MathSqrt(MathAbs(R))
		End If
		 ' Assign the Bolton-Tremblay value for the current bar.
		results(i) = indexValue
	Next
	Return results

Copyright © 2010 IQBroker, LLC. All rights reserved.