In this part, we will continue discussing expressions. While we have covered function expressions and other types of expressions, some functions require further explanation. For instance, in Example 3, you see the functions MathEXP and MathABS. These functions are available for use in expressions and perform specific tasks. For example, if you want to calculate **e ^{0.1}**, the relevant function is MathEXP. If you want to obtain the absolute value of a number, use MathABS. All of these functions require a parameter. To use a function, you call it, open a square bracket, write its parameter, and then close the bracket.

**Candle Functions**

The first section of these functions deals with candles, allowing you to access candle properties. For example, you might use Open[1] to refer to the opening price of the previous candle. Similarly, you can use these functions for other candle values like close, low, high, and volume. For instance, to check if the body of the three previous candles is greater than 3 pips, you would write “BODY[3] > 3 pips”. You can access all properties of any candle using these functions. While you can define indicators for candle properties, it’s generally better to use these functions directly to save indicator fields for other uses. The most useful function in this area is CANDLENUMBER, which provides the number of a candle. For example, if INDICATOR1 finds the Highest High of a group of candles and returns a value like 1.12345, you can find the shift number of that candle using CandleNumber[1] in any expression.

**Mathematical Functions**

The next section covers mathematical functions. For example, MathABS calculates the absolute value of a number. MathCEIL rounds a number up to the nearest integer, and MathRAND generates a random number.

For instance, if you need to calculate the distance between MA1 and MA2, you can use MathABS[MA1 – MA2]. These functions may or may not require a parameter.

**Time Functions**

Time functions provide various time specifications. For example, Hour gives you 10 if the broker’s time is 10:30. To perform a task after 10 o’clock, you can write Hour > 10. To avoid taking positions in the 12^{th} month of the year, you can write Month < 12 and combine it with other conditions. The function Week provides the number of weeks that have passed since the beginning of the year, while DayOFWeek and DayOFYear provide information about the current day of the week and day of the year, respectively.

Time functions used in time indicators include those starting with “TM”. For example, MinuteSTART gives the starting time of the current minute, and HourSTART gives the starting time of the current hour.

To select a candle group from the beginning of the current week up to one hour ago, you would use “WeekSTART, HourSTART”. To find the lowest low from the start of the current week, use “WeekSTART, NOW” as parameters.

**Current Selected Order Functions** **(Only for use in close, break-even, and trailing-stop expressions)**

These functions work on orders. For example, to define a trailing condition or break-even, you might use Profit > 10 to break even any open position with profits greater than $10. Another example is OpenDURATION, which shows the time passed since an order was opened. IsBuy and IsSell indicate the type of position (Buy or Sell). To break even all orders with profits greater than 10 points, use ProfitPoints > 10. To start trailing on positions with a size greater than 0.3 lots, use Lots > 0.3.

**Signal Functions**

To get information about the latest signal, use LastSignalISBuy and LastSignalISSell. To find out how many seconds have passed since the last signal, use LastSignalSeconds. For example, to avoid entering a new position until 30 minutes (1800 seconds) after the last signal, add this to your entry expressions: <Entry Expression> AND LastSignalSeconds > 1800.

**Tick Functions**

Tick functions include Ask, Bid, and Spread. For example, to close all positions when the price exceeds 1.3452, write Ask > 1.3452. To enter a position only when the spread is less than 12, write Spread < 12, and combine it with other entry conditions. These functions allow access to tick values up to 100 ticks back. For instance, to get the value of the 45^{th} tick, write Ask[45].

**Open Order Functions (Usable in All Expressions)**

To access properties of all open orders, such as profit, TP, SL, and open duration, use functions with the prefix PrevOrder. The last order is number 0, the previous one is 1, and so on. For example, PrevOrderProfit[0] returns the profit of the last order.

**Group of Open Order Functions**

These functions allow you to access properties of a group of open orders, such as the number of open orders or the total profit of the current open orders.

**Closed Order Functions (ClosedOrder)**

These functions provide access to properties of a specific closed order.

**A Set of Closed Orders Functions (ClosedOrders)**

These functions return information about a set of closed orders.

**Account Functions**

Account functions provide information about account properties, such as AccountBalance or AccountNumber. For example, to avoid opening new orders when your overall loss from all open positions exceeds $100, use AccountEquity < AccountBalance – 100.

**Custom Functions**

Custom functions are used for martingale and grid strategies, such as MartingaleAttempt, which shows the number of attempts or grid profits. These functions are only usable in martingale and grid expressions.

**Cross Functions**

Cross functions include CROSSUP, CROSSDOWN, or CROSS, used to check if two indicators, such as moving averages, have crossed each other.

**Other Functions**

Additional logical syntaxes are supported, including mathematical operations, comparisons, and constants. These include VALUE, LASTVALUE, NOTHING, AND, OR, XOR, PLUS, MINUS, NOT, MOD, POW, and PI.

AND, OR, and XOR are common logical operators. PLUS and MINUS are used for addition and subtraction. NOT inverts the value of a logical statement. MOD provides the remainder of a division (e.g., 100 MOD 2 gives 0, and 40 MOD 6 gives 4).

POW calculates exponents (e.g., 3 POW 4 gives 3^{4} = 81). PI represents the mathematical constant π, approximately 3.14159.

**Function Examples**

**EX1**: ISBULL[2]

This means that if the second previous candle is a bullish one this expression gives you a true value otherwise it gives you a false value.

**EX2**: Close[2] > Open[2]

This exactly does the same thing as EX1 which was mentioned above.

**EX3**: IsDoji[4]

This means that the 4th previous candle is a DOJI one or not. If yes it gives you a true value and if not, it gives you a false value.

**EX4**: MathABS[MA1 – MA2]

This gives you the difference between MA1 and MA2.

**EX5**: Hour = 17 AND Minute = 30

This gives a true value when the time is 17:30 otherwise it’s false.

**EX6**: Lots > 0.1 AND OpenDuration > 60

This gives you a true value if the order size is greater than 0.1 lots and at least 60 seconds have passed from the opening of the order.

**EX7**: MA1 CROSSUP MA2

This gives you a true value when the first moving average crosses the second one upwards.

**EX8**: Ask > MA1 AND Spread < 10 points

This gives you a true value when the price is greater than the moving average and the spread is less than 10 points.

**EX9**: OpenProfit > 15 OR OpenOrder < 2

This gives you a true value when the profit of all open positions is greater than $15 or the total number of open positions is less than 2.

**EX10**: AccountEquity > AccountBalance

This gives you a true value when the sum of the profits of all open positions is positive.