<pss_extension name="Price Relative Indicator" version="1.0.0">Price relative technical indicator
<author email="support@personalstockstreamer.com" name="DTLink Software" url="http://www.personalstockstreamer.com" />
<script language="VBScript">
<![CDATA[
' Price Relative indicator for Personal Stock Streamer
' Copyright © 2004-2005 by DTLink Software, All rights reserved.
' http://www.personalstockstreamer.com
' written by Anatoly Ivasyuk
' ================================================
' define the Price Relative indicator class
class PriceRelativeIndicator
' create the chart
public Function Create ( ChartObject )
Set ChartManager = Application.GetObject("ChartManager")
' create the dataset
Set MyDataSet = ChartObject.CreateObject("DataSet")
MyDataSet.ID = "Price Relative"
MyDataSet.Color = "Black"
MyDataSet.PenWidth = 2
ChartObject.AddObject(MyDataSet)
' create a separate canvas, the background rectangle for the chart
Set Canvas = ChartObject.CreateObject("Canvas")
Canvas.ID = "Price Relative"
ChartObject.AddObject(Canvas)
' create a legend for this chart
Set Legend = ChartObject.CreateObject("Legend")
Canvas.AddObject(Legend)
Legend.AddDataSet(MyDataSet)
' create the actual chart object, in this case a line chart
Set LineChart = ChartObject.CreateObject("LineChart")
Canvas.AddObject(LineChart)
LineChart.ID = "Price Relative"
LineChart.AddDataSet(MyDataSet)
' create and add the chart frame
Set Frame = ChartObject.CreateObject("Frame")
Frame.SetRelativeObject(LineChart)
Canvas.AddObject(Frame)
' create and add the axis
Set YAxis = ChartObject.CreateObject("Axis")
YAxis.TranslateReverse = true
YAxis.LabelFormat = "%0.4lf"
LineChart.SetAxis YAxis, "Right", false
LineChart.AddObject(YAxis)
Set XAxis = ChartObject.CreateObject("Axis")
XAxis.TickSize = 0
XAxis.MinorTickSize = 0
XAxis.FontSize = 0
LineChart.SetAxis XAxis, "Bottom", false
LineChart.AddObject(XAxis)
' the Create function needs to return a reference to the chart object
Set Create = LineChart
end Function
' recalculate the indicator based on current settings
public Function Recalc ( ChartObject )
Set ChartManager = Application.GetObject("ChartManager")
' get the data sets to work with
Set MyDataSet = ChartObject.GetDataSet("Price Relative")
Set CloseDataSet = ChartObject.GetDataSet("Close")
Set DateDataSet = ChartObject.GetDataSet("Date")
' find the relative ticker requested by user
Set Doc = Application.ActiveDocument
Set AltTicker = Doc.FindTicker(Nothing, ChartObject.GetParam(0), 0)
' check if the ticker exists in the document
If AltTicker Is Nothing Then
' if ticker was not found, create temporary ticker
Set AltTicker = Doc.CreateTicker
Set Portfolio = Doc.CurrentPortfolio
If Not AltTicker Is Nothing Then
AltTicker.SetProperty "Symbol", ChartObject.GetParam(0)
AltTicker.SetProperty "Visible", "0"
Portfolio.Insert -1, AltTicker
' set the label on this chart
MyDataSet.Label = MyDataSet.ID + " (" + ChartObject.GetParam(0) + ") "
' make sure this ticker gets deleted when the chart is closed
ChartObject.DeferDeleteTicker(AltTicker)
End If
End If
' now that we have a ticker, process the historical data
If Not AltTicker Is Nothing Then
Set AltCloseDataSet = ChartObject.GetDataSetFromTicker(AltTicker, "Close")
LastValidAltCloseData = -1
LastValidCloseData = -1
' make sure we generate the exact same amount of data as in the original data set
MyDataSet.Size = CloseDataSet.Size
' check for a valid data set
If AltCloseDataSet Is Nothing Then
' if there was no data set, set a dummy value so it will at least display the chart
MyDataSet.Data(MyDataSet.Size - 1) = 0
MyDataSet.Label = MyDataSet.ID + " (" + ChartObject.GetParam(0) + ") "
' request historical data from the application
ChartObject.RequestHistoricalDataForTicker(AltTicker)
Else
' loop through all of the data and calculate the Price Relative indicator
For x = 0 To CloseDataSet.Size - 1
If (CloseDataSet.IsValidData(x) And CloseDataSet.Data(x) > 0) Then
LastValidCloseData = x
If (AltCloseDataSet.IsValidData(x) And AltCloseDataSet.Data(x) > 0) Then
LastValidAltCloseData = x
MyDataSet.Data(x) = CloseDataSet.Data(x) / AltCloseDataSet.Data(x)
End If
End If
Next
' set the label on this chart
If (LastValidAltCloseData >= 0) Then
MyDataSet.Label = MyDataSet.ID + " (" + ChartObject.GetParam(0) + ") " + FormatNumber(MyDataSet.Data(LastValidAltCloseData), 4)
Else
MyDataSet.Label = MyDataSet.ID + " (" + ChartObject.GetParam(0) + ") "
End If
' check data at the end of the range
If LastValidAltCloseData < LastValidCloseData - 2 Then
ChartObject.RequestHistoricalDataForTicker(AltTicker)
End If
End If
End If
end Function
end Class
' ================================================
' register the Price Relative indicator with the application
Set ChartManager = Application.GetObject("ChartManager")
If Not ChartManager Is Nothing Then
Set MyIndicator = ChartManager.RegisterIndicator("Price Relative")
If IsObject(MyIndicator) And Not MyIndicator Is Nothing Then
MyIndicator.ID = "Price Relative"
MyIndicator.Description = "Price Relative"
MyIndicator.HandlerObject = new PriceRelativeIndicator
MyIndicator.NumParameters = 1
MyIndicator.DefaultParameters = "^SPX"
MyIndicator.OverlaysAllowed = "SMA,EMA,T3,TEMA,DEMA,TRIMA,WMA"
MyIndicator.AllowOnIntradayChart = False
End If
End If
]]>
</script>
</pss_extension>