Gallery
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="dotnetCHARTING"%>
<%@ Import Namespace="dotnetCHARTING"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Financial DM Sample</title>
<script runat="server">
void Page_Load(Object sender,EventArgs e)
{
// Demonstrates the use of the DM+ and DM- indicators.
// First we declare a chart of type FinancialChart
// The Financial Chart
FinancialChart.Title="Directional Movement Chart";
FinancialChart.TempDirectory="temp";
FinancialChart.Debug=true;
FinancialChart.ShadingEffect = true;
FinancialChart.LegendBox.Template ="%icon %name";
FinancialChart.Size="800X400";
FinancialChart.XAxis.Scale = Scale.Time;
// For financial indicators the time scale is inverted (i.e. the first element of the series is the newest)
FinancialChart.XAxis.InvertScale = true;
FinancialChart.XAxis.FormatString = "MMM d";
FinancialChart.XAxis.TimeInterval = TimeInterval.Week;
FinancialChart.YAxis.Label.Text = "Price (USD)";
FinancialChart.YAxis.FormatString = "currency";
FinancialChart.YAxis.ScaleRange.ValueLow = 16.00;
FinancialChart.YAxis.ScaleRange.ValueHigh = 32.00;
FinancialChart.YAxis.Scale = Scale.Range;
// Here we load data samples from the FinancialCompany table from within chartsample.mdb
DataEngine priceDataEngine = new DataEngine ();
priceDataEngine.ChartType = ChartType.Financial;
priceDataEngine.ConnectionString = ConfigurationManager.AppSettings["DNCConnectionString"];
priceDataEngine.DateGrouping = TimeInterval.Day;
priceDataEngine.StartDate = new DateTime (2021,10,1);
priceDataEngine.EndDate = new DateTime (2021,12,31);
priceDataEngine.SqlStatement = @"SELECT TransDate, HighPrice, LowPrice, OpenPrice, ClosePrice FROM FinancialCompany WHERE TransDate >= #STARTDATE# AND TransDate <= #ENDDATE# ORDER BY TransDate ";
priceDataEngine.DataFields = "xAxis=TransDate,High=HighPrice,Low=LowPrice,Open=OpenPrice,Close=ClosePrice";
SeriesCollection sc = priceDataEngine.GetSeries();
Series prices = null;
if(sc.Count>0)
prices = sc[0];
else
return;
prices.DefaultElement.ToolTip="L:%Low-H:%High";
prices.DefaultElement.SmartLabel.Font = new Font("Arial", 6);
prices.DefaultElement.SmartLabel.Text="O:%Open-C:%Close";
prices.Type = SeriesTypeFinancial.Bar;
CalendarPattern cp = new CalendarPattern (TimeInterval.Day, TimeInterval.Week, "0000001");
cp.AdjustmentUnit = TimeInterval.Day;
prices.Trim (cp, ElementValue.XDateTime);
prices.Name = "Prices";
FinancialChart.SeriesCollection.Add (prices);
// Financial Series DMI Signal
FinancialChart.DefaultSeries.DefaultElement.Marker = new ElementMarker (ElementMarkerType.None);
//FinancialChart.ChartAreaLayout.Mode = ChartAreaLayoutMode.Vertical;
FinancialChart.DefaultSeries.Type = SeriesType.Line;
// Here we display the financial simple moving average for the prices series over five days
Series movingAverage = FinancialEngine.SimpleMovingAverage (prices, ElementValue.High, 10);
FinancialChart.SeriesCollection.Add (movingAverage);
// Create a new chart area for DM+ and DM-.
ChartArea dmChartArea = new ChartArea ("Directional Movement");
dmChartArea.HeightPercentage = 20;
dmChartArea.YAxis = new Axis();
dmChartArea.YAxis.ScaleRange.ValueLow = 0;
dmChartArea.YAxis.ScaleRange.ValueHigh = 0.8;
FinancialChart.ExtraChartAreas.Add (dmChartArea);
// Here we display the DM+
Series plusDM = FinancialEngine.PlusDirectionalMovement (prices);
plusDM.Type = SeriesType.Spline;
plusDM.DefaultElement.Color = Color.FromArgb(0, 255, 0);
if (plusDM.Elements.Count > 0)
dmChartArea.SeriesCollection.Add (plusDM);
else Console.WriteLine ("The series plusDM is empty");
// Here we display the DM-
Series minusDM = FinancialEngine.MinusDirectionalMovement (prices);
minusDM.Type = SeriesType.Spline;
minusDM.DefaultElement.Color = Color.FromArgb(0, 0, 255);
if (minusDM.Elements.Count > 0)
dmChartArea.SeriesCollection.Add (minusDM);
else Console.WriteLine ("The series minusDM is empty");
// Here we display the DMI Signal. For calcualating the DMI Signal we are using the
// Simple Moving Average method(method =1) over a period of 10 days.
Series dmiSignal = FinancialEngine.DMISignal (prices, 1, 10);
dmiSignal.Type = SeriesType.Marker;
dmiSignal.LegendEntry.Visible = false;
if (dmiSignal.Elements.Count > 0)
// We add the movingAverage series to dmiSignal in order to represents
// dmiSignal on to the FinancialChart. We did this because the YValues of the
// dmiSignal take the values of: 1, 0, or -1 representing a buy, no action or sell
// signal.
FinancialChart.SeriesCollection.Add (dmiSignal+movingAverage);
else Console.WriteLine ("The series dmiSignal is empty");
}
</script>
</head>
<body>
<div style="text-align:center">
<dotnet:Chart id="FinancialChart" runat="server"/>
</div>
</body>
</html>
<%@ Page Language="vb" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="dotnetCHARTING"%>
<%@ Import Namespace="dotnetCHARTING"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Financial DM Sample</title>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Demonstrates the use of the DM+ and DM- indicators.
' First we declare a chart of type FinancialChart
' The Financial Chart
FinancialChart.Title="Directional Movement Chart"
FinancialChart.TempDirectory="temp"
FinancialChart.Debug=True
FinancialChart.ShadingEffect = True
FinancialChart.LegendBox.Template ="%icon %name"
FinancialChart.Size="800X400"
FinancialChart.XAxis.Scale = Scale.Time
' For financial indicators the time scale is inverted (i.e. the first element of the series is the newest)
FinancialChart.XAxis.InvertScale = True
FinancialChart.XAxis.FormatString = "MMM d"
FinancialChart.XAxis.TimeInterval = TimeInterval.Week
FinancialChart.YAxis.Label.Text = "Price (USD)"
FinancialChart.YAxis.FormatString = "currency"
FinancialChart.YAxis.ScaleRange.ValueLow = 16.00
FinancialChart.YAxis.ScaleRange.ValueHigh = 32.00
FinancialChart.YAxis.Scale = Scale.Range
' Here we load data samples from the FinancialCompany table from within chartsample.mdb
Dim priceDataEngine As DataEngine = New DataEngine ()
priceDataEngine.ChartType = ChartType.Financial
priceDataEngine.ConnectionString = ConfigurationManager.AppSettings("DNCConnectionString")
priceDataEngine.DateGrouping = TimeInterval.Day
priceDataEngine.StartDate = New DateTime (2021,10,1)
priceDataEngine.EndDate = New DateTime (2021,12,31)
priceDataEngine.SqlStatement = "SELECT TransDate, HighPrice, LowPrice, OpenPrice, ClosePrice FROM FinancialCompany WHERE TransDate >= #STARTDATE# AND TransDate <= #ENDDATE# ORDER BY TransDate "
priceDataEngine.DataFields = "xAxis=TransDate,High=HighPrice,Low=LowPrice,Open=OpenPrice,Close=ClosePrice"
Dim sc As SeriesCollection = priceDataEngine.GetSeries()
Dim prices As Series = Nothing
If sc.Count>0 Then
prices = sc(0)
Else
Return
End If
prices.DefaultElement.ToolTip="L:%Low-H:%High"
prices.DefaultElement.SmartLabel.Font = New Font("Arial", 6)
prices.DefaultElement.SmartLabel.Text="O:%Open-C:%Close"
prices.Type = SeriesTypeFinancial.Bar
Dim cp As CalendarPattern = New CalendarPattern (TimeInterval.Day, TimeInterval.Week, "0000001")
cp.AdjustmentUnit = TimeInterval.Day
prices.Trim (cp, ElementValue.XDateTime)
prices.Name = "Prices"
FinancialChart.SeriesCollection.Add (prices)
' Financial Series DMI Signal
FinancialChart.DefaultSeries.DefaultElement.Marker = New ElementMarker (ElementMarkerType.None)
'FinancialChart.ChartAreaLayout.Mode = ChartAreaLayoutMode.Vertical;
FinancialChart.DefaultSeries.Type = SeriesType.Line
' Here we display the financial simple moving average for the prices series over five days
Dim movingAverage As Series = FinancialEngine.SimpleMovingAverage (prices, ElementValue.High, 10)
FinancialChart.SeriesCollection.Add (movingAverage)
' Create a new chart area for DM+ and DM-.
Dim dmChartArea As ChartArea = New ChartArea ("Directional Movement")
dmChartArea.HeightPercentage = 20
dmChartArea.YAxis = New Axis()
dmChartArea.YAxis.ScaleRange.ValueLow = 0
dmChartArea.YAxis.ScaleRange.ValueHigh = 0.8
FinancialChart.ExtraChartAreas.Add (dmChartArea)
' Here we display the DM+
Dim plusDM As Series = FinancialEngine.PlusDirectionalMovement (prices)
plusDM.Type = SeriesType.Spline
plusDM.DefaultElement.Color = Color.FromArgb(0, 255, 0)
If plusDM.Elements.Count > 0 Then
dmChartArea.SeriesCollection.Add (plusDM)
Else
Console.WriteLine ("The series plusDM is empty")
End If
' Here we display the DM-
Dim minusDM As Series = FinancialEngine.MinusDirectionalMovement (prices)
minusDM.Type = SeriesType.Spline
minusDM.DefaultElement.Color = Color.FromArgb(0, 0, 255)
If minusDM.Elements.Count > 0 Then
dmChartArea.SeriesCollection.Add (minusDM)
Else
Console.WriteLine ("The series minusDM is empty")
End If
' Here we display the DMI Signal. For calcualating the DMI Signal we are using the
' Simple Moving Average method(method =1) over a period of 10 days.
Dim dmiSignal As Series = FinancialEngine.DMISignal (prices, 1, 10)
dmiSignal.Type = SeriesType.Marker
dmiSignal.LegendEntry.Visible = False
If dmiSignal.Elements.Count > 0 Then
' We add the movingAverage series to dmiSignal in order to represents
' dmiSignal on to the FinancialChart. We did this because the YValues of the
' dmiSignal take the values of: 1, 0, or -1 representing a buy, no action or sell
' signal.
FinancialChart.SeriesCollection.Add (dmiSignal+movingAverage)
Else
Console.WriteLine ("The series dmiSignal is empty")
End If
End Sub
</script>
</head>
<body>
<div style="text-align:center">
<dotnet:Chart id="FinancialChart" runat="server"/>
</div>
</body>
</html>
- Sample FilenameDirectionalMovement.aspx
- Version4.0
- Uses DatabaseYes