Gallery
Market Facilitation Index
<%@ 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"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Financial Market Indicators Sample</title>
<script runat="server">
void Page_Load(Object sender,EventArgs e)
{
// Demonstrates the use of the Market Facilitation Index indicator
// First we declare a chart of type FinancialChart
// The Financial Chart
FinancialChart.Title="Company X Stock Price";
FinancialChart.TempDirectory="temp";
FinancialChart.Debug=true;
FinancialChart.ShadingEffect = true;
FinancialChart.LegendBox.Template ="%icon %name";
FinancialChart.Size="800X500";
FinancialChart.TitleBox.Position = TitleBoxPosition.FullWithLegend;
FinancialChart.XAxis.Scale = Scale.Time;
FinancialChart.XAxis.FormatString = "MMM d";
FinancialChart.XAxis.TimeInterval = TimeInterval.Week;
// For financial indicators the time scale is inverted (i.e. the first element of the series is the newest)
FinancialChart.XAxis.InvertScale = true;
FinancialChart.YAxis.Label.Text = "Price (USD)";
FinancialChart.YAxis.FormatString = "currency";
FinancialChart.YAxis.ScaleRange.ValueLow = 15;
// 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,2,1);
priceDataEngine.EndDate = new DateTime (2021,5,29);
priceDataEngine.SqlStatement = @"SELECT TransDate, HighPrice, LowPrice, OpenPrice, ClosePrice,Volume FROM FinancialCompany WHERE TransDate >= #STARTDATE# AND TransDate <= #ENDDATE# ORDER BY TransDate DESC ";
priceDataEngine.DataFields = "xAxis=TransDate,High=HighPrice,Low=LowPrice,Open=OpenPrice,Close=ClosePrice,Volume=Volume";
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.CandleStick;
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);
// Create the second chart area
ChartArea volumeChartArea = new ChartArea();
volumeChartArea.Label.Text = "Stock Volume";
volumeChartArea.YAxis.Label.Text = "Volumes";
volumeChartArea.Series.Name="Stock Volume";
volumeChartArea.HeightPercentage = 17;
volumeChartArea.Series.DefaultElement.ToolTip="%YValue";
FinancialChart.ExtraChartAreas.Add(volumeChartArea);
Series volumes = new Series();
volumes.Trim (cp, ElementValue.XDateTime);
volumes.Name = "Volumes";
volumes.Type = SeriesType.Bar;
foreach(Element el in prices.Elements)
{
Element newEl = new Element();
newEl.YValue = el.Volume;
newEl.XDateTime = el.XDateTime;
if (el.Close < el.Open)
newEl.Color = Color.FromArgb(254, 76, 20);
else
newEl.Color = Color.FromArgb(66, 133, 244);
volumes.Elements.Add(newEl);
}
volumeChartArea.SeriesCollection.Add (volumes);
// Market Facilitation Index
FinancialChart.DefaultSeries.DefaultElement.Marker = new ElementMarker (ElementMarkerType.None);
FinancialChart.ChartAreaLayout.Mode = ChartAreaLayoutMode.Vertical;
FinancialChart.DefaultSeries.Type = SeriesType.Spline;
// Create a new char area for the indicator Market Facilitation Index
ChartArea mfiChartArea = new ChartArea();
mfiChartArea.Label.Text = "Market Facilitation Index";
mfiChartArea.YAxis = new Axis();
mfiChartArea.HeightPercentage = 20;
FinancialChart.ExtraChartAreas.Add(mfiChartArea);
// Market Facilitation Index
Series mfiSeries = FinancialEngine.MarketFacilitationIndex(prices);
mfiSeries.Type = SeriesType.Spline;
mfiSeries.DefaultElement.Color = Color.FromArgb(45,125,255);
mfiChartArea.SeriesCollection.Add(mfiSeries);
}
</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"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Financial Market Indicators Sample</title>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Demonstrates the use of the Market Facilitation Index indicator
' First we declare a chart of type FinancialChart
' The Financial Chart
FinancialChart.Title="Company X Stock Price"
FinancialChart.TempDirectory="temp"
FinancialChart.Debug=True
FinancialChart.ShadingEffect = True
FinancialChart.LegendBox.Template ="%icon %name"
FinancialChart.Size="800X500"
FinancialChart.TitleBox.Position = TitleBoxPosition.FullWithLegend
FinancialChart.XAxis.Scale = Scale.Time
FinancialChart.XAxis.FormatString = "MMM d"
FinancialChart.XAxis.TimeInterval = TimeInterval.Week
' For financial indicators the time scale is inverted (i.e. the first element of the series is the newest)
FinancialChart.XAxis.InvertScale = True
FinancialChart.YAxis.Label.Text = "Price (USD)"
FinancialChart.YAxis.FormatString = "currency"
FinancialChart.YAxis.ScaleRange.ValueLow = 15
' 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,2,1)
priceDataEngine.EndDate = New DateTime (2021,5,29)
priceDataEngine.SqlStatement = "SELECT TransDate, HighPrice, LowPrice, OpenPrice, ClosePrice,Volume FROM FinancialCompany WHERE TransDate >= #STARTDATE# AND TransDate <= #ENDDATE# ORDER BY TransDate DESC "
priceDataEngine.DataFields = "xAxis=TransDate,High=HighPrice,Low=LowPrice,Open=OpenPrice,Close=ClosePrice,Volume=Volume"
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.CandleStick
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)
' Create the second chart area
Dim volumeChartArea As ChartArea = New ChartArea()
volumeChartArea.Label.Text = "Stock Volume"
volumeChartArea.YAxis.Label.Text = "Volumes"
volumeChartArea.Series.Name="Stock Volume"
volumeChartArea.HeightPercentage = 17
volumeChartArea.Series.DefaultElement.ToolTip="%YValue"
FinancialChart.ExtraChartAreas.Add(volumeChartArea)
Dim volumes As Series = New Series()
volumes.Trim (cp, ElementValue.XDateTime)
volumes.Name = "Volumes"
volumes.Type = SeriesType.Bar
For Each el As Element In prices.Elements
Dim newEl As Element = New Element()
newEl.YValue = el.Volume
newEl.XDateTime = el.XDateTime
If el.Close < el.Open Then
newEl.Color = Color.FromArgb(254, 76, 20)
Else
newEl.Color = Color.FromArgb(66, 133, 244)
End If
volumes.Elements.Add(newEl)
Next el
volumeChartArea.SeriesCollection.Add (volumes)
' Market Facilitation Index
FinancialChart.DefaultSeries.DefaultElement.Marker = New ElementMarker (ElementMarkerType.None)
FinancialChart.ChartAreaLayout.Mode = ChartAreaLayoutMode.Vertical
FinancialChart.DefaultSeries.Type = SeriesType.Spline
' Create a new char area for the indicator Market Facilitation Index
Dim mfiChartArea As ChartArea = New ChartArea()
mfiChartArea.Label.Text = "Market Facilitation Index"
mfiChartArea.YAxis = New Axis()
mfiChartArea.HeightPercentage = 20
FinancialChart.ExtraChartAreas.Add(mfiChartArea)
' Market Facilitation Index
Dim mfiSeries As Series = FinancialEngine.MarketFacilitationIndex(prices)
mfiSeries.Type = SeriesType.Spline
mfiSeries.DefaultElement.Color = Color.FromArgb(45,125,255)
mfiChartArea.SeriesCollection.Add(mfiSeries)
End Sub
</script>
</head>
<body>
<div style="text-align:center">
<dotnet:Chart id="FinancialChart" runat="server"/>
</div>
</body>
</html>
- Sample FilenameMarketFacilitationIndex.aspx
- Version3.4
- Uses DatabaseYes