Advanced - All Available Functions, Flags and Values

Here are all the different functions, flags and values that are available for Advanced paintbars and scans.

 

 

Including External Code

#include

This allows you to include code from an external file (specified following the #include).
 
Example:   #include c:\temp\mylibrary.code

Data Management

SetDaysNeeded(int NumDays)

This is important for scans, not paintbars. Scans usually determine how much data they have to load to perform the scan based on the indicators used. Sometimes that is insufficient. For example, you may want to have EMA as accurate as possible, and EMAs, due to their nature, require much more data than their period to be accurate.
 
This function will set the number of days of data that the scan will load in order to run.

Candle and Color/Shape Values

CandleSizeInSec - int
 
Open, High, Low, Close, BarVolume - Double

 

 

 

Timestamp - DateTime

 

 

CurrentCandle - struct

 

CandleNumber - int

 

 

 

IsLastCandle - Boolean

CandleSizeInSec - is only valid for Intraday time-based calculations. Returns the candle size for the current calculation

 

The values for the candle for which the calculation is performed. These can be indexed, so Close[1] means the close value of the previous candle, and Open[3] means the open value of 3 candles back.

 

The Timestamp (and all other DateTime values in paintbar calculations) is always UTC. Can also be indexed like Open, High Low etc.

 

CurrentCandle also contains all the information about the current candle (but cannot be indexed).
 

CandleNumber is the sequential number of the current candle. Is useful if you want to check if the candle being 

worked on has changed or to use as the X coordinate in the SetLine function

 
IsLastCandle is true if the candle being processed is the last candle. For example, you may use IsLastCandle to process some functionality on on the last candle.
 

PBarColor - Color

 

PBarShape - PBShape

 

PBarValue - double

Each candle, if one of the Color/Shape functions is called on it, is assigned a color and shape for the paintbar. The PBarColor and PBarShape values refer to those. They are also indexed, like the Candle Values, so PBarShape[2] would refer to the paintbar shape 2 candles ago.

 

So you can do something like this:
 
   if (PBarShape[2] == PBShape.Star)

     ....

 

PBarValue is the value that was previously set by SetYValue.

Plotting the Paintbar Result

SetYValue(double YValue)

 

SetYValue(double YValue1, double YValue2)

 

 

See Line- and Cloud- Paintbar

Sometimes you want to plot the paintbar as a curve/line instead of just shapes. This function allows you to do it. The YValue is the position of the shape on the chart, and it will plot lines between adjacent shapes. Color still needs to be set for the lines.

 

NOTE: this function HAS to be called after SetColor or SetColorAndShape. It cannot be called by itself without calling one of those functions first!

 

NOTE: if you set the value in this function to YSkipValue then the drawing of the line/curve will stop at that point and only resume when another SetYValue is called with a value that is not YSkipValue.

Trading Account Information

Trading_AccountValue

Trading_Cash

Trading_DayTradeBP

Trading_OvernightBP

Trading_Pos

Trading_PosPaid

Trading_LastFillQty

Trading_LastFillPrice

The total account value

Cash available in the account

Daytrading buying power in the account

Overnight buying power in the account

Currently held position (quantity) in the account

Average paid for the currently held position

Quantity for the last fill

Price for the last fill

Trade Bead Values from Chart

TradeBead(int BeadNumber)

The trade bead value from the chart (can only be used in Paintbars)

Parameter Functions

 

See Custom Parameters

DefinePaintbarParameter(String ParameterID, string ParameterDescription = null, Boolean IsInteger = false, Double Minimum = 0, Double Maximum = 100, Double Increment = 1, Double Default = 1)

Defines a paintbar parameter that a user can set. This value can be retrieved with a GetPaintbarParameter function.

 

ParameterID   - string identifying the parameter (to be used to retrieve it)

ParameterDescription - description of the parameter (for example, "Period")

IsInteger - true/false

Minimum - minimum possible value for the parameter

Maximum - maximum possible value foe the parameter

Increment - for the up/down arrows in the parameter editor field

Default - the parameter's default value

Double GetPaintbarParameter(String ParameterID)

ParameterID   - string identifying the parameter (see DefinePaintbarParemeter above)
Returns the value of the parameter that is set by the user of the paintbar

Inter-Paintbar Communication

void SetInterVar(string name, double value, Boolean Global = false)
 
void SetInterVar(string name, String value, Boolean Global = false)

Set a an inter-paintbar variable name to value. Can be retrieved in a different paintbar or scan by using the GetInterVar function.
 
NOTE: the inter-paintbar variables are per symbol. That is, if you set the variable on a paintbar that is running on MSFT you cannot read it on a paintbar that is running on INTC. If you want the variable to be symbol-independent, set the Global in the function call to true.
 
NOTE: this var, once set, can be used in Hotkeys using the intervar() function.

double GetInterVar(string name, Boolean Global = false)
 
string GetInterVarString(string name,  Boolean Global = false)
 

Get a previously set inter-paintbar variable name. If the value has not been set yet, will return Double.MinValue or "" for a string.

void SetChartVar(string name, double value)
 

Like the SetInterVar but this var would be local to the current Chart (and only Chart) that the paintbar is being run on.

 

NOTE: this var, once set, can be used in Hotkeys using the chartvar() function.

double GetChartVar(string name)

The Get for the SetInterVar

Color/Shape Functions

See Setting Colors and Shapes

 

NOTE: all the SetColor functions may have an optional first int resultnum parameter. This parameter is used for:
 
1. Scans - when specifying multiple scan result columns, you can specify multiple scan result colors.

2. Cloud paintbar - specifying the colors of the lines and fill of the cloud.

SetColor(Color color)

 

SetColor(SysColor syscolor)

 

SetColor(int intcolorRGB)

Sets the output color to this absolute color. Does not allow the user of the paintbar to change the color in the paintbar instance parameters.

 

The SysColor refers to the MT's chart color scheme colors. intcolorRGB is the standard RGB representation of colors. For example, Color.Red is same as 0xFF0000.

SetColor(String NamedColor, SysColor DefaultColor = SysColor.None)

 

SetColor(String NamedColor, Color DefaultColor = default(Color))

 

SetColor(String NamedColor, uint DefaultColorRGB = 0)

Sets the output color to a "named color".  The name of the color will appear in the paintbar's instance parameters and user of the paintbar will be able to set it.

 

NOTE: The NamedColor has to be a literal string (not a variable) at least once in the code of the paintbar in order to appear in the paintbar's instance parameters.

 

SetShape(PBShape Shape)

Simply - set the shape. Set it to PBShape.Default to allow the user of the paintbar to set the desired shape in the paintbar's instance parameters.

SetColorAndShape...

Like SetColor, but also sets the shape.

GetNamedColor(String NamedColor)

Returns the color assigned to a "named color".

Line-drawing Functions

 

See Straight Lines and Text in Paintbars

SetLine(double ID,

Color color,

double x1, double y1,

double x2, double y2,

int width = 1,

string text = null,

LineTextPosition textposition = LineTextPosition.RightAbove,

double fontMult = 1)
 
 
SetLine(double ID,

Color color,

DateTime T1, double y1,

DateTime T2, double y2,

int width = 1,

string text = null,

LineTextPosition textposition = LineTextPosition.RightAbove,

double fontMult = 1)

Parameters
 
ID - each line has a unique numeric ID so that later iterations of the paintbar can reset the old line's value if they need to do that or delete it.
 
Color - this is the line's color

 

x1, x2 - these are the X coordinates of the line's 2 anchors points. The units for these are Candle Numbers. Usually the paintbar would use the CandleNumber of the current candle to set these. These don't have to be integers - you can do CandleNumber - 2.5 to place the anchor 2.5 candles before the current one, for example. Use some high number - like 100000 - to place an anchor all the way on the right of the chart.
 
T1, T2 - instead of CandleNumbers, you can use the timestamps to anchor the line
 

y1, y2 - these are the Y (price) coordinates of the line's 2 anchor points
 
width - the width, in pixels, of the line drawn

 

text - an optional text to be shown on the line

 

textposition - where on the line the text needs to be shown

 

fontmult - the size multiplier for the text, compared to regular chart fonts that are used for things like axis ticks.

 

 

NOTE: you can use the SetLine function to just place text on the chart - to do that, just place a line of 0 width (set both x1 and x2 to the same value) with Text on the chart

RemoveLine(double ID)

Removes the line if it was previously set with SetLine

RemoveAllLines()


Alert Functions

 

See Paintbar Alerts

TriggerAlert()

Triggers the alert. Since no name is specified, this will show up in the Paintbar Parameters Editor as "Alert".

TriggerAlert(String AlertName)

Triggers the alert. Specifies the name of the alert.

TriggerAlert(String AlertName,

String Message)

Triggers the alert, specifies alert's name, passes a message to the alert that may be displayed in the alert notification.

Scan Result Functions

 

See Scanning

ClearScanResult()

clears the scan result if it was set

IsScan

true if the code is running as part of a scan, false if is running as a paintbar

Double ScanResult
 
String ScanResultStr

allows you to access the previously set ScanResult - both the numeric and string - for the current run of the scan

SetScanResult(Boolean value = true)
 
SetScanResult(Double value)
 
SetScanResult(String value)
 
SetScanResult(Double numValue, String strValue)

Sets the scan result for the current iteration of the scan. Can set it to Boolean, Double or String value

 

NOTE: you may have several results from one scan (they will show in separate columns). To do that, you specify the column number (0-based) as the first parameter in the SetScanResult. For example:   SetScanResult(2, true);

 

NOTE: when you specify multiple scan results, the column number HAS to be a literal number. It cannot be a variable.

SetScanResultColumnName(String sName)

 

SetScanResultColumnName(int colnum, String sName)

Sets the caption for the scan result column in the portfolio.
 
NOTE: you may have several results from one scan (they will show in separate columns). To set captions for more columns than one, specify the column number (0-based) as the first parameter in the SetScanResultColumnName. For example:   SetScanResultColumnName(2, "MyScan");
 
NOTE: when you specify the column number, it HAS to be a literal number. It cannot be a variable.

Flags

 

IsLastCandle

true if current candle is the last one on the chart. For example, since scans are only meaningful for the last candle in the current data set for the symbol, sometimes it is useful to check the IsLastCandle and not do any calculations if it is false, to speed up the scan initialization.

IsNewCandle

true if current candle is a new one - that is, the current tick is the first tick in the candle.

IsNewDay

true if new trading day (compare this to IsNewSession) - that is, the current tick is the first tick in the new trading day (that includes premarket if it is shown on the chart)

IsNewSession

true if new trading session (compare this to IsNewDay) - that is, the current tick is the first tick in the new trading session (that does not include premarket)

IsColorSetForCandle

true if paintbar color is set already for the current candle.

IsHidden

true if the paintbar is hidden on the chart. Also is set to true If this is a scan, not a paintbar.

IsOnHistoricalChart

true if current scan/paintbar is running on a historical chart

IsOnIntradayChart

true if current scan/paintbar is running on an intraday chart

IsScan

true if the code is running as part of a scan, false if is running as a paintbar

IsScanTriggered

true if the there is a scan triggered on the current candle

Candle Patterns

CandlePattern

This object provides functions to detect Candle Patterns. See Candle Patterns in Advanced Paintbars for more information.

Timestamps and Session Information

 

See Timestamp and Trading Session

Timestamp

The Date/Time of the current candle's timestamp

 

TradingSessionInfo GetTradingSessionInfo(DateTime timestamp)

Gets the struct that holds the information about the trading session that includes the timestamp. Usually is called with the candle's Timestamp.

 

See Timestamp and Trading Session for more information.

TradingDay
 
NowTradingDay

The info about the current candle's trading day - session start/end, day start/end etc.

 

The info about the current trading day - that is, the trading day based on your computer's current time.

 

CurrentDailyHigh
CurrentDailyLow

CurrentPrevClose

The values for the daily high and low and previous day's close for the session that is current for the current candle. Note that the session's high and low is updated for subsequent candles as the paintbar progresses. The CurrentDailyHigh and CurrentDailyHigh are correct at the Timestamp of the candle.
 
NOTE: just like Close, Open etc., these values can be indexed. So CurrentDailyHigh[1] would be the daily high for the day before the current candle's session.
 
NOTE: the CurrentPrevClose does not include aftermarket values

Looping Functions

 

See Looping Functions

All(Candle Range, Boolean Expression)

Any(Candle Range, Boolean Expression)

Count(Candle Range, Boolean Expression)

Min(Candle Range, Numeric Expression)

Max(Candle Range, Numeric Expression)

Sum(Candle Range, Numeric Expression)

Average(Candle Range, Numeric Expression)

Slope(Candle Range, Numeric Expression)

These functions allow you to do some candle-range calculations or conditionals without having to write loops.

 

See Advanced - Looping Functions for more information.

Debugging

LogString(String)

 

Will write out a string to a general log file. You can monitor the log file using Microsoft's DebugView utility - see https://docs.microsoft.com/en-us/sysinternals/downloads/debugview