Skip to content

Quick-tip 63 | Namespace explanation

What is a namespace?

Namespaces are a grouping of classes that relate to one another.  Examples of namespaces in the EasyLanguage class library include:

tsdata.marketdata

Contains classes that are used to access market data such as price quotes, market levels, and fundamental values.

elsystem.drawing

Contains classes that are used to describe the color and font characteristics of form controls and drawing objects.

elsystem.drawingobjects

Contains classes that are used to create and manipulate drawing tools (trendlines, text, rectangles, etc.) in a chart window.

elsystem.office.excel

Contains base classes that are used to access data from Excel spreadsheet files.

Why use namespaces?

Name spaces are included in a program with the using key word.

By including namespaces means that classes, methods, properties, and events can be referenced without including the namespace.name as a qualifier., e.g.

var: PriceSeriesProvider PSP( NULL );

rather than:

var: tsdata.marketdata.PriceSeriesProvider PSP( NULL );

For example, in the following simple program we are not using the ‘using namespace’ declaration.

var: tsdata.marketdata.PriceSeriesProvider PSP( NULL );

Once
Begin
PSP = new tsdata.marketdata.PriceSeriesProvider;

PSP.Symbol = Symbol;
PSP.Interval.ChartType = tsdata.marketdata.DataChartType.Bars;
PSP.Interval.IntervalType = tsdata.marketdata.DataIntervalType.Minutes;
PSP.Interval.IntervalSpan = 5;
PSP.Range.Type = tsdata.marketdata.DataRangeType.Bars;
PSP.Range.Bars = 100;
PSP.IncludeVolumeInfo = false;
PSP.IncludeTicksInfo = false;
PSP.UseNaturalHours = false;
PSP.Realtime = true;
PSP.TimeZone = tsdata.common.TimeZone.exchange;
PSP.Load = true;
PSP.Name = “PSP”;

Value99 = PSP.Count;

End;

Plot1( PSP.Close[0] );

Whereas, in an almost identical program we are including the using statement.

Using tsdata.marketdata;
Using tsdata.common;

var: PriceSeriesProvider PSP( NULL );

Once
Begin
PSP = new PriceSeriesProvider;

PSP.Symbol = Symbol;
PSP.Interval.ChartType = DataChartType.Bars;
PSP.Interval.IntervalType = DataIntervalType.Minutes;
PSP.Interval.IntervalSpan = 5;
PSP.Range.Type = DataRangeType.Bars;
PSP.Range.Bars = 100;
PSP.IncludeVolumeInfo = false;
PSP.IncludeTicksInfo = false;
PSP.UseNaturalHours = false;
PSP.Realtime = true;
PSP.TimeZone = TimeZone.exchange;
PSP.Load = true;
PSP.Name = “PSP”;

Value99 = PSP.Count;

End;

Plot1( PSP.Close[0] );

The second version is easier to read and understand, but works the same way.

 

The example indicator(s) applied to a chart
The example indicator(s) applied to a chart

Find the name of a namespace

If you know the name of a class, but don’t know which namespace it is in, you can go to the dictionary and search for the name of the class.

For example, say you were unsure of what namespace the vector object belongs to, you can go to the dictionary and do a search.

By looking through the list you will see that vector belongs to the elsystem.collections namespace.

 

Video example