More Details by Examples

In this part, we are going to continue the discussion of expressions. When we explained function expressions and other expressions in the expression section, some functions need more explanations. For instance, in Example3, you see a function called MathEXP and a function called MathABS. These functions are the kind you are allowed to use in expressions and they will perform a specific task. For example, if you want to calculate e0.1, its relating function is MathEXP. Or if you want to obtain the absolute value of a number, the related function is MathABS. all of these functions contain a parameter. It means that whenever you want to use that function, you call that function and open a square bracket and write its parameter and then close the square brackets.

Candle Functions

The first section of these functions is the ones that work on candles, meaning you can use them if there is a need for a property of a candle. For instance, you may write Open[1]. with the same system, you can do the same for other candle values like close, low, high and volumes. For example, if you want to write the body of three previous candles is greater than 3 pips, it should be written as “BODY[3] > 3 pips”. So you will be able to access all the properties of any candle using these functions. You can also define an indicator to specify the properties of a candle. But it’s better to use relating functions instead because you can use the indicator fields for more indicators to be set. The most useful function in this area is CANDLENUMBER that gives you the number of the candle. For example, we define INDICATOR1 for finding Highest High of a group of candles that returns HH like 1.12345. Now, if we are looking for the shift number of that candle, we can do that just using CandleNumber[1] in any expressions.

Mathematical Functions

The next section is the mathematical functions. For instance, MathABS which calculates the absolute value of a number. Another example is MathCEIL, this function is for rounding a number. Or the function MathRAND which can be used for generating a random number.

For example, if you need to know the distance between MA1 and MA2, you can write MathABS[MA1 – MA2]. All these functions used in this section may or may not have a parameter.

Time Functions

These functions can give you any time specification you’ll need. For example, Hour, which gives you 10 if the broker’s time is 10:30. For instance, if you want to do a task when the time is after 10 you can write Hour>10 or you don’t want to take any position in the 12th month of the year, you can write Month<12 and “and” it with entrance conditions.  The word Week gives you the number of weeks that have passed from the beginning of the year, and you can also guess by yourself the meaning of DayOFWeek and DayOFYear.

The next part is the kind of time functions that are used in time indicators. There are some indicators in the indicator list which start with “TM”. for example, you can locate a candle group, a timely point of view and in their parameters you can use these kinds of syntaxes. For instance, it gives you the amount of current time, MinuteSTART, gives you the starting time of the current minute, HourSTART gives you the starting of the current hour, and so on.

Imagine that you want to separate a candle group from the beginning of the current week up to one hour ago, then you’ll have to go to the group candle parameter and write: “WeekSTART, HourSTART” or if you want to find the lower low from the beginning of the current week, you can select Lowest Low from time indicators and write “WeekSTART, NOW” as its parameters.

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

These functions work on orders. for example, when you want to define an expression for trailing condition or break even.  imagine that you want to breakeven any open position whose profits are greater than 10$. All you need to do is write Profit>10. another example is OpenDURATION which shows the time passed from the opening of an order. IsBuy and IsSell show you the type of position which could be Buy or Sell. Imagine that you’d want to break even all the orders whose profits are greater than 10 points then you should write: ProfitPoints>10. Or imagine that you want to start trailing on positions whose position size is greater than 0.3 lots, you may use the expression Lots>0.3.

Signal Functions

For getting information about the type of latest signal we can use LastSignalISBuy and  LastSignalISSell. If you need to find how many seconds is it past, LastSignalSeconds is used. Suppose you need to don’t enter new position until 30 minutes (1800 secs) after the last signal, just add this in entry expressions: <Entry Expression> AND LastSignalSeconds>1800

Tick Functions

There are functions for working on ticks like Ask, Bid, Spread. For example, if you’d want to close all the positions when the price passes 1.3452, you’ll have to write Ask>1.3452 or when you want to enter a position only when the spread is less than 12, you’ll write Spread<12, then “and” it with other entrance conditions. In these three functions (Ask, Bid, Spread) you can access the tick value up to 100 previous ticks. For example, if you want to have the value of the last 45th tick, you can write Ask[45].

Open Order Functions (usable in all expressions)

For all open orders, you can access any property of the orders like profit, TP, SL, open duration, and …by using functions with the prefix PrevOrder. The last order is number 0 and the previous one is 1 and so on. For example, PrevOrderProfit[0] returns the profit of the last order.

Group of Open Order Functions

For open orders, you can access any property of the group of them, for example, if you want to know the number of open orders or profit of a set of the current open orders.

Closed Order (ClosedOrder)

These functions help to get access to any property of a specific closed order.

A set of the Closed Orders (ClosedOrders)

These functions return any information about a set of closed orders

Account Functions

These kinds of expressions are about account properties e.g. AccountBalance or AccountNumber and …. For example, if you want not to open any order when your overall loss of all open positions is more than 100$, you’ll need to write AccountEquity<AccountBalance-100.

Custom Functions

For martingale and grid plans, we can use these kinds of functions like MartingaleAttempt which shows the number of attempts or grid profits. You can use them only in martingale and grid expression, nowhere else.

Cross Functions

you can use CROSSUP, CROSSDOWN or CROSS when you want to check the cross of two indicators like moving averages.

Other Functions

A series of logical syntaxes are supported here. Some of them are related to math calculations, some of them are for comparison, and some constant values plus these three syntaxes.                                                             VALUE, LASTVALUE, NOTHING.

AND, OR and XOR are famous logical expressions. PLUS and MINUS are for adding and subtracting. NOT is used for inverting the value of a logical statement. MOD, gives you the remainder of a division e.g. 100 MOD 2 gives you 0 or 40 MOD 6 gives you 4.

POW is exponent e.g. 3 POW 4 gives you 34 = 81.

PI is the pie number, which is 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 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 0therwise its 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<10points

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.