Indicators API functions

From NakedMarkets
Jump to navigation Jump to search

Summary

This page contains all the functions and constants available to develop a custom indicator through the Naked-Markets API.
The source code of existing indicators is public on our Github to help seeing how the API can be used.

The main indicator functions

Function name Description Mandatory/Optional
OnInit() Defines the code which will be executed when the indicator is initialized during Naked Markets startup Mandatory
OnCalculate() Defines the code which will be executed each time a new bar will be printed on the chart Mandatory
OnTimer() Not yet implemented Optional
OnChartEvent() Not yet implemented Optional
OnAttach() Defines the code which will be executed when the indicator will be attached to the chart Optional


Input parameters

The input parameters have be defined within the OnInit() function.
The value of these parameters can be modified by the users when they attach the indicator to a chart. They can represent the Period parameter or the settings of the indicator.
These parameters are included through the concept of C# custom attributes.
For example, in the Donchian Channel indicator, there are 2 different parameters, the period and the visibility of the middle line, defined as follows :

       [Input(Name = "Period")]
       public int period = 21;
       [Input(Name = "Show Mid Level")]
       public bool ShowMidLevel = true;

In order to set an external input parameter, you have to use a public variable with the attribute [Input] above.
This attribute can have a name, which is the label displayed in the NakedMarkets interface : [Input(Name = "User Parameter")].
The type of the parameter variable can be a :

  • int (integer)
  • double (floating number)
  • bool (boolean value, true or false)
  • string
  • Enum (list of values)


If you need to use a list with an enum type and change the labels to be more user-friendly, it can be done with the custom attribute "Description".
This use-case can be seen in the Sessions indicator, where a custom Enum type is defined with different labels related to the hours.
Then, the enum type is bound to the input parameter via its type.

Indicator Buffers

The data indicator buffers are crucial for your custom indicator because it stores the indicator values.
Since the Naked-Markets indicator API wants to be close to the MQL4 language, the indicator buffers are similar to the Metatrader ones.
These are defined by setting a public variable of type IndicatorBuffer in the current class. Here is an example of the RSI indicator :

       public IndicatorBuffer RSI = new IndicatorBuffer();
       public IndicatorBuffer AvGain = new IndicatorBuffer();
       public IndicatorBuffer AvLoss = new IndicatorBuffer();


Then, these values can be retrieved or modified by accessing it as an array, ie : AvGain[index].

Constant parameters

Timeframes constants are used to set the values of timeframes
Series constants are used in function to set the mode of data access (open, low, close, high, volume or time)
Drawing styles constants are used in chart drawing functions to set the graph type (line, histogram, candles, ...)
Line styles constants are used in graphical objects functions to set the style of the line
Objects type constants are used in graphical objects functions to set the type of the object (rectangle, ellipse, horizontal line, ...)
Objects properties constants are used in graphical objects functions to set the property of the object (date value, price value, color, ...)
Applied Prices constants are mainly used in Moving Average functions to set the type of the Moving Average Price (Close, Median, Typical, Weighted, ...)
MA Method constants are mainly used in Moving Average functions to set the type of the Moving Average (SMA, EMA, SMMA or LWMA)

Data access functions

Here are the meta-data functions :

Function name Description Returned value
Symbol() Get the current Symbol of the attached chart string
Period() Get the current Timeframe of the attached chart int
Ask() Get the current Ask value double
Bid() Get the current Bid value double
Spread() Get the current Spread value double
Digits() Get the number of digits after the comma double
Point() Get the minimum value of the Symbol double
Bars() Get the number of bars on the attached chart int


Here are the data access functions related to the index :

Function name Description Parameter Returned value
Open(int index) Get the Open value of the bar index of the bar double
High(int index) Get the High value of the bar index of the bar double
Low(int index) Get the Low value of the bar index of the bar double
Close(int index) Get the Close value of the bar index of the bar double
Time(int index) Get the Time (Date) value of the bar index of the bar DateTime
Volume(int index) Get the Volume value of the bar index of the bar int


These functions are used to have the value of a specific bar related to its index.
When the index is 0, this is the last bar.
When the index is 1, this is the previous last bar.
When the index is 2, this is the previous previous last bar. And so on.

The Symbol and the Timeframe are the ones related to the attached chart.
Here are the generic data access functions, specifying the Symbol or Timeframe :

Function name Description Parameters Returned value
iOpen(string Symbol, int Timeframe, int Index) Get the Open value of the bar The Symbol, the Timeframe, the Index double
iHigh(string Symbol, int Timeframe, int Index) Get the High value of the bar The Symbol, the Timeframe, the Index double
iLow(string Symbol, int Timeframe, int Index) Get the Low value of the bar The Symbol, the Timeframe, the Index double
iClose(string Symbol, int Timeframe, int Index) Get the Close value of the bar The Symbol, the Timeframe, the Index double
iTime(string Symbol, int Timeframe, int Index) Get the Time (Date) value of the bar The Symbol, the Timeframe, the Index DateTime
iVolume(string Symbol, int Timeframe, int Index) Get the Volume value of the bar The Symbol, the Timeframe, the Index int
iHighest(string Symbol, int Timeframe, Series SeriesType, int Count, int Start) Get the highest value of Series from the start within the Count previous bars The Symbol, the Timeframe, the type of series (HIGH, LOW, CLOSE, ...), the count, the starting point double
iLowest(string Symbol, int Timeframe, Series SeriesType, int Count, int Start) Get the lowest value of Series from the start within the Count previous bars The Symbol, the Timeframe, the type of series (HIGH, LOW, CLOSE, ...), the count, the starting point double
iBars(string Symbol, int Timeframe) Get the number of bars The Symbol, the Timeframe int
iBarShift(string Symbol, int Timeframe, DateTime Date, bool Exact) Get the index of the bar related to the given date The Symbol, the Timeframe, the Date, the precision of the date int


Indicator configuration functions

Here are the functions, dedicated to configure the indicator settings and the data buffers :

Function name Description Parameters Returned value
SetIndicatorShortName(string IndicatorName) Set the name of the indicator (used in the NakedMarkets interface) The Indicator name void
SetIndexBuffer(int BufferIndex, IndicatorBuffer Buffer) Set the index to the Indicator Buffer The index, the Indicator Buffer bool
SetIndexStyle(int BufferIndex, DrawingStyle DrawingStyle, Color ColorStyle, LineStyle LineStyle = LineStyle.STYLE_SOLID, int Width = 1) Set the style of the Indicator Buffer (line, histogram, color, style, ...) The index of the Indicator Buffer, the Drawing Style, the Color, the Line Style, the width void
SetIndexLabel(int BufferIndex, string Label) Set the label of the Indicator Buffer. This label appears in the indicator parameters The index of the Indicator Buffer, the label void
SetIndexShift(int BufferIndex, int Shift) Shift horizontally the Indicator Buffer data The index of the Indicator Buffer, the shift count void
SetIndicatorDigits(int Digits) Set the number of digits for the indicator The number of digits void
SetLevel(double Value, Color ColorStyle = null, LineStyle LineStyle = LineStyle.STYLE_SOLID, int Width = 1) Add a level to the indicator The value of the level, the color, line style, the width void
SetIndexArrow(int BufferIndex, int symbol, int xoffs = 0, int yoffs = 0) Set the symbol to the Indicator Buffer (prints symbols instead of data) The index of the Indicator Buffer, the Windings symbol character number, X offset, the Y offset void


Graphical objects functions

Here are the functions to create, modify and delete graphical objects on the chart :

Function name Description Parameters Returned value
ObjectCreate(string ObjectName, ObjectType ObjectType, DateTime Time1, double Price1, DateTime Time2 = null, double Price2 = 0, DateTime Time3 = null, double Price3 = 0) Creates a graphical objects with the related properties The object name and its properties bool
ObjectName(int ObjectIndex) Get the name of the object related to its index The object index string
ObjectDelete(string ObjectName) Delete the object related to its name The object name bool
ObjectDeleteAll(ObjectType = null) Delete the objects of related object Type The related object Type. If no parameters are used, delete every objects int
ObjectFind(string ObjectName) Get the index of the object, related to its name The object name int
ObjectSet(string ObjectName, ObjectProperty ObjectProperty, Object Value) Set the object property value The name of the object, the object property to set, the new value bool
ObjectGet(string ObjectName, ObjectProperty ObjectProperty) Get the object property value The name of the object, the object property to retrieve Object
ObjectTotal(ObjectType = null) Get the number of corresponding objects The related object Type. If no parameters are used, it's applied to every object types int


Misc. functions

Here are the misc. functions, which can be used to retrieve specific price values or common indicators values :

Function name Description Parameters Returned value
GetAppliedPrice(string Symbol, int Timeframe, int Index, Applied_Price Price) Get the price from the applied price constant The symbol, the timeframe, the index, the applied price method double
iMA(string Symbol, int Timeframe, int Period, int MAShift, MA_Method MAMethod, Applied_Price AppliedPrice, int Index) Get the Moving Average value from specified parameters The symbol, the timeframe, the MA period, the MA shift, the MA method, the applied price method, the index double
iATR(string Symbol, int Timeframe, int Period, int Index) Get the ATR value from the specified parameters The symbol, the timeframe, the period, the index double