[TOC]
Commodity futures contract, cryptocurrency contract
Commodity futures/cryptocurrency contract
this_week OKEX futures contract for current week
next_week OKEX futures contract for next week
quarter OKEX futures contract for quarter
XBTUSD BITMEX Perpetual Contract
rb888 Rebar main contract
MA000 Methanol Index Contract
rb1901 Rebar contract
…and so on.
When setting the contract, you can choose rb1901/rb1905 The market data is rb1901, the order trading contract is rb1905
A variable is a space opened in the computer memory to store data. Simply put, it is used to save data.
Declare the first variable
// Assign 1 to the variable a
a:=1;
In “M Language”, a simple distinction is made from the “data volume”:
Distinguish from “variable type”
INFO(CLSOE>OPEN,'OK!');
// integer
int:=2;
// decimal
float:=3.1;
// The current period closing price is greater than -999, you will find that the return value of each cycle is 1, representing true, because the closing price is almost impossible to be negative
Is_true:=Close>-999;
VARIABLE:VALUE1:10; // Declare a global variable with a value of 10 and execute only once.
In most systems, variable naming does not allow the use of system “reserved words” (built-in variable names, function names), such as the well-known Close, C. In addition, pure numbers are not allowed, or numbers begin with, and cannot be too long, different systems, and different length limits are different. In fact, you don’t have to entangle the efficiency of the mainstream system for English analysis. I believe that “M Language” is very friendly to English speakers. I recommend you use the following naming convention:
English + underline
// output
Move_avg_5:=MA(C,5);
If you prefer English, please let people understand the meaning of your variables as much as possible. Do not use naming methods such as: A1, AAA, BBB… Believe me, after a few days, when you review your indicator code again, you will be very painful due to the lack of memory. Similarly, when you export code to others, the reader’s mindset must have collapsed.
Then, from now on, embrace the “M Language” as much as you can! I hope it will be a powerful tool for your analysis and decision making.
The data type is a basic concept. In programming, when we assign an explicit data to a variable, the variable becomes the type of the data itself.
1、2、3、1.1234、2.23456 ……
'1' 、'2' 、'3' ，string type must be wrapped with ''
a collection of data consisting of a series of single-valued data
Use 1 for true and 0 for false
Example
// Declare a variable of a numeric type
var_int := 1;
// Declare a variable of sequence data
var_arr := Close;
// String type can not be declared separately, you need to combine functions
INFO(C>O, 'rising line');
The operation and calculation used to execute the indicator code, which is the symbol of the participation operation.
Used to assign a value to a variable
:
a colon, representing the assignment and outputting to the diagram (deputy diagram)
Close1:Close; // Assign Close to the variable Close1 and output it to the diagram
:=
The “colon equal”, representing the assignment, but is not output to the diagram (main diagram, subgraph…) and is not displayed in the status bar table.
Close2:=Close; // Assign Close to the variable Close2
^^
^^ ,two ^ symbols represent assignments, assign values to variables and output them to the diagram (main diagram).
lastPrice^^C;
..
… ,two dot, The symbol represents the assignment, assigns a value to the variable and displays it in the status bar table, but does not output it to the diagram (main diagram, sub- diagram…).
openPrice..O
Relational operators are binocular operators that are used in conditional expressions. Used to determine the relationship between two data
Return value: Boolean type, not true (1), must be false (0)
// Assign the result of 2 > 1 to the rv1 variable, at this time rv1=1
Rv1:=2>1;
// returns false, which is 0, because 2 is greater than 1. :-)
rv3:=2<1;
x:=Close;
// Assign the result of the operation with a closing price greater than or equal to ¥ 10 to the variable rv2
// Note that since “close” is a sequence of data, when the close>=10 operation is performed, the essence is that each cycle is performed, so each cycle will have a return value of 1, 0.
rv2:=Close>=10;
Omitted here
A:=O=C; // Determine if the opening price is equal to the closing price.
1<>2 // Judgment weather 1 is equal to 2 or not, the return value is 1 (true)
Return value: Boolean type, not true (1), must be false (0)
// determine whether cond_a, cond_b, cond_c is true at the same time,
cond_a:=2>1;
cond_b:=4>3;
cond_c:=6>5;
cond_a && cond_b and cond_c; // return value 1, true
cond_a:=1>2;
cond_b:=4>3;
cond_c:=5>6;
cond_a || cond_b or cond_c; // return value 1, true
Return value: numeric type
It is the completion of the basic arithmetic operators symbol, which is the symbol used to process the four arithmetic operations.
Plus +
A:=1+1; // return 2
Subtract -
A:=2-1; // return 1
Multiply *
A:=2*2; // return 4
Divide by /
A:=4/2; // return 2
In the world of programming, a “function” is actually a piece of code that implements a certain function and can be called by other code. The general form is as follows
function(param1,param2,……)
Composition：
The function name (parameter 1, parameter 2, …), there may be no parameters, there may be multiple parameters, such as MA(x, n); represents a simple moving average of the inner x returning n cycles, where MA() is a The function, x and n are the parameters of the function.
When using a function, we need to understand the basic definition of the function, that is, what data can be obtained by calling the function. In general, functions have parameters. When we pass in parameters, we need to ensure that the data type passed in is compliant. At current stage, the code hinting function of most IDEs is very imperfect. They are not showing the certain data types for the parameters given, which gives us some troubles. The interpretation of MA(x,n) is:
Return a simple moving average
usage：
AVG:=MA(X,N): N's simple moving average of X, algorithm (X1+X2+X3+...+Xn)/N,N supports variables
This is very unfriendly explanation for beginners. Next, we thoroughly analyze the function and try to find a way to quickly learn and use the function.
In order to learn the function quickly, we first need to understand a concept called “return value”. Return, as the name implies, is “return”, the value represents “concrete value”, the data that can be obtained.
// Because it will be used in the following code, use the variable return_value to receive and save the return value of function()
// retrun_value := function(param1,param2);
// for example：
AVG:=MA(C,10); // AVG is retrun_value , “function” function is: MA function, param1 parameter: C is the closing price sequence data, param2 parameter: 10.
Second, the second important concept of the function is the parameter, passing in different parameters, you can get different return values.
// variable ma5 receives 5 day closing price moving average
ma5:=MA(C,5);
// variable ma10 receives 10 day closing price moving average
ma10:=MA(C,10);
The first parameter X of the above variables ma5, ma10 is C (closing price), in fact C is also a function (returning the closing price sequence since the opening), but it has no parameters. The second parameter 5, 10，This is used to tell the MA () function, we want to get the moving average of the closing price for how many days, through the parameters, the function becomes more flexible.
In the following function introduction, use, follow the above three principles.
Mixed programming between M language and JavaScript language
%%
// here you can call any API function of FMZ Quant.
scope.TEST = function(obj) {
return obj.val * 100;
}
%%
Closing price: C; The closing price is magnified 100 times: TEST©; The previous closing price is magnified 100 times: TEST(REF(C, 1)); // The mouse moves to the backtest K line and the variable value is displayed.
- scope object
scope object, you can add attributes and assign anonymous functions to attributes. An anonymous function referenced by this attributes can be called in the M language code section.
- scope.getRefs(obj) function
In the JavaScript code block, call the scope.getRefs(obj) function, which returns the data of the incoming obj object.
The following %%%% of the symbolic package's JavaScript code will get the incoming C closing price when the TEST(C) function is called in the M language code.
The scope.getRefs function returns all closing prices for this K-line data. Since the throw "stop" interrupt routine is used, the variable “arr” contains only the closing price of the first Bar of k-line. You can try to delete throw "stop" and it will execute the last return of the JavaScript code, returning all the closing price data.
```
%%
scope.TEST = function(obj){
var arr = scope.getRefs(obj)
Log("arr:", arr)
throw "stop"
return
}
%%
TEST(C);
```
- scope.bars
In the JavaScript code block, access all K line bars.
The TEST function returns a value, 1 is the falling k-line and 0 is the rising line.
```
%%
scope.TEST = function(){
var bars = scope.bars
return bars[bars.length - 1].Open > bars[bars.length - 1].Close ? 1 : 0 // can only return values
}
%%
arr:TEST;
```
```
# Note:
# TEST Received anonymous function, the return value must be a numeric value
# If the anonymous function has no parameters, write VAR:=TEST directly when calling TEST; write VAR:=TEST(); will report an error.
# TEST in #scope.TEST must be uppercase.
```
- scope.bar
In the JavaScript code block, access the current bar.
Calculate the average of “opening high but closing low” of k-line’s prices.
```
%%
scope.TEST = function(){
var bar = scope.bar
var ret = (bar.Open + bar.Close + bar.High + bar.Low) / 4
return ret
}
%%
avg^^TEST;
```
- scope.depth
Access the market depth data (order book)
```
%%
scope.TEST = function(){
Log(scope.depth)
throw "stop" // Throw an exception after printing the depth data, pause.
}
%%
TEST;
```
- scope.symbol
Get the current trading pair name string
```
%%
scope.TEST = function(){
Log(scope.symbol)
throw "stop"
}
%%
TEST;
```
- scope.barPos
Get the K line Bar location.
```
%%
scope.TEST = function(){
Log(scope.barPos)
throw "stop"
}
%%
TEST;
```
- scope.get\_locals('name')
This function is used to get the variables in the M language code part
```
V:10;
%%
scope.TEST = function(obj){
return scope.get_locals('V')
}
%%
GET_V:TEST(C);
```
```
# Note:
# If a variable does not calculate data when the period is insufficient, this time the scope.get_locals function is called in the JavaScript code.
# When get this variable, it will give an error: line:XX - undefined locals a variable name undefined
```
Use: #EXPORT Formula Name … #END to create a formula. If you only want to get data for different periods, you can also write an empty formula without formula calculation.
The empty formula is:
#EXPORT TEST
NOP;
#END // End
Use: #IMPORT [MIN, period, formula name] AS variable value, reference formula, get the data of the set period (closing price, opening price, etc., obtained by variable value).
Code example:
// this code demonstrates how to reference formulas of different cycles in the same code
// #EXPORT extends the syntax, ending with #END as a formula, you can declare multiple
#EXPORT TEST
Mean 1:EMA(C, 20);
Mean 2:EMA(C, 10);
#END // End
#IMPORT [MIN,15,TEST] AS VAR15 // Reference formula, K line cycle is 15 minutes
#IMPORT [MIN,30,TEST] AS VAR30 // Reference formula, K line cycle is 30 minutes
CROSSUP(VAR15.Mean1, VAR30.Mean1),BPK;
CROSSDOWN(VAR15.Mean2, VAR30.Mean2),SPK;
The highest price of 15 mins:VAR15.HIGH;
The highest price of 30 mins:VAR30.HIGH;
AUTOFILTER;
In the model, by writing the AUTOFILTER function to control and realize the signal filtering of one opening and one closing. When multiple opening position signals satisfy the condition, the first signal is taken as the effective signal, and the same signal on the subsequent k line will be filtered out.
Filtering model supported commands: BK, BP, BPK, SK, SP, SPK, CLOSEOUT, does not support BK (5) and other instructions with lots
E.g：
MA1:MA(CLOSE,5);
MA2:MA(CLOSE,10);
CROSSUP(C,MA1),BK;
CROSSUP(MA1,MA2),BK;
C>BKPRICE+10||C<BKPRICE-5,SP;
AUTOFILTER;
The AUTOFILTER function is not written in the model, allowing continuous opening position signal or continuous closing position signal, which can be used to increase or decrease the position.
Supported commands: BK(N), BP(N), SK(N), SP(N), CLOSEOUT, BPK(N), SPK(N), do not support open and close position without lot. （1）Support instruction grouping。 （2）When multiple instruction conditions are satisfied at the same time, the signals are executed in the order in which the conditional statements are written. E.g：
MA1:MA(CLOSE,5);
MA2:MA(CLOSE,10);
CROSSUP(C,MA1),BK(1);
CROSSUP(MA1,MA2),BK(1);
C>BKPRICE+10||C<BKPRICE-5,SP(BKVOL);
One K-line with one signal model can be subdivided into a closing price model and an instruction price model.
1）Closing price model
The K line goes through the calculation signal to place an order (the calculation is also performed during the formation of a K line. At this time, the signal will uncertain, and the signal that appears when the k line is not finished will be ignored, and no order will be placed)
The signal direction is consistent with the direction of the holding position, and there is no signal disappearing condition.
E.g：
MA1:MA(CLOSE,5);
MA2:MA(CLOSE,10);
CROSSUP(MA1,MA2),BPK;//5 cycle moving average line up cross 10 cycle moving average line to buy long.
CROSSDOWN(MA1,MA2),SPK;//5 cycle moving average line down cross 10 cycle moving average line to sell short.
AUTOFILTER;
2）Instruction price model
Regardless of whether the k-line is finished or not, the signal is calculated and the order is placed in real time, that is, the order is placed before the K-line is completed;
When the K line ends, it will be checked. If the direction of the position does not match the direction of the signal at the end of the k line, the position will be automatically synchronized.
E.g：
MA1:MA(CLOSE,5);
MA2:MA(CLOSE,10);
CROSSUP(MA1,MA2),BPK;//5 cycle moving average line up cross 10 cycle moving average line to buy long.
CROSSDOWN(MA1,MA2),SPK;//5 cycle moving average line down cross 10 cycle moving average line to sell short.
AUTOFILTER;
The model uses a multsig or multsig_min to control and implement multiple signals from a single K-line.
Regardless of whether the k line is finished, calculate the signal and place a real-time order.
The signal will not be reviewed, there is no signal disappearing condition, and the signal direction is consistent with the direction of the position.
Repeated multiple executions in a K line if multiple signal conditions are met
E.g:
MA1:MA(CLOSE,5);
MA2:MA(CLOSE,10);
CROSSUP(MA1,MA2),BK;
C>BKPRICE+10||C<BKPRICE-5,SP;
AUTOFILTER;
MULTSIG(0,0,2,0);
supplement: 1、Adding and subtracting position model, two methods of one k-line signal: the closing price placing order and the instructing price placing order are all supported.
2、Adding and subtracting position model，also supports a single k-line signal to place orders.
Adding and subtracting position model，write the multsig or multsig_min function, realize multiple times of Adding and subtracting position on one k line, or reduce the position multiple times.
Use the operator “^^” to set the indicator to be displayed on the main image while assigning values to the variable.
MA60^^MA(C, 60); // Calculate the moving average indicator with a parameter of 60
Use the operator “:” to set the indicator to be displayed on the secondary diagram while assigning values to the variable.
ATR:MA(MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW)),26); // Assign a value to the ATR variable, The ":" symbol is followed by the formula for calculating the ATR
If you don’t want to display on the main or sub-diagram Use the “…” operator
MA60..MA(C, 60); // Calculate the moving average indicator with a parameter of 60
You can use DOT and COLORRED to set the line type, color, etc. in line with the habits of users who are familiar with the M language.
Introduce the “problems” commonly encountered in the preparation of indicators, usually the points that need attention when writing the indicators. (To be continue)
Pay attention to the end of “;”.
Note that system keywords cannot be declared as variables.
Note that the string uses single quotes, for example: ‘opening’ only one quote.
Annotation
// The content of the comment
(the input method can be typed in both English and Chinese), which means that the code is not compiled during the execution process, that is, it does not execute // the content behind it. Usually we use the meaning of the code to facilitate the code review. Understanding, recall
{ Comment content }
Block comment.
A:=MA(C,10);
{The previous line of code is the calculation of the moving average.}
(* Comment content *)
Block comment.
A:=MA(C,10);
(*The previous line of code is the calculation of the moving average.*)
When writing code, it often causes a symbol error because the input method switches between Chinese and English. Common types are as follows: colon:, terminator; comma, parenthesis (), etc., these different characters in Chinese and English need to pay attention.
>=
<=
Get the opening price of the K-line chart
Opening Price
Function：OPEN，shorthand as O
Parameters: None
Explanation: Return the opening price of the cycle
Sequence data
OPEN obtained the opening price of the K-line chart.
Note:
1、can be shorthand as O.
example 1：
OO:=O; //Define OO as the opening price; pay attention to the difference between O and 0.
example 2：
NN:=BARSLAST(DATE<>REF(DATE,1));
OO:=REF(O,NN); //Get the opening price of the day
example 3：
MA5:=MA(O,5); //Define the 5-period moving average of the opening price (O is OPEN shorthand).
Get the highest price of the K-line chart
Highest price
Function：HIGH，shorthand as H
Parameters: None
Explanation: return the highest price of the cycle
Sequence data
HIGH Get the highest price of the K-line chart.
Note：
1、can be shorthand as H.
example 1：
HH:=H; //Define HH as the highest price.
example 2：
HH:=HHV(H,5); //Take the maximum value of the highest price within 5 cycles.
example 3：
REF(H,1); //Take the highest price of the previous K line
Get the lowest price of the K-line chart
Lowest Price
Function：LOW，shorthand as L
Parameters: None
Explanation: Return the lowest price of the cycle.
Sequence data
LOW gets the lowest price of the K-line chart.
Note：
1、can be shorthand as L.
example 1：
LL:=L; //Define LL as the lowest price.
example 2：
LL:=LLV(L,5); //Get the minimum value of the lowest price in 5 cycles.
example 3：
REF(L,1); //Get the lowest price of the previous K line
Get the closing price of the K-line chart
Closing Price
Function：CLOSE，shorthand as C
Parameters: None
Explanation: Return the closing price of the cycle
Sequence data
CLOSE Get the closing price of the K-line chart.
Note：
1、When the k-line in the market is not finished, get the latest price.
2、Can be shorthand as C.
example 1：
A:=CLOSE; //Define the variable A as the closing price (A is the latest price when the k line is not finished).
example 2：
MA5:=MA(C,5); //Define the 5-period moving average of the closing price (C is short for CLOSE).
example 3：
A:=REF(C,1); //Get the closing price of the previous k line.
Get the volume of the K-line chart
Trading Volume
Function：VOL，shorthand as V
Parameters: None
Explanation: Return the volume of this cycle.
Sequence data
VOL gets the volume of the K-line chart.
Note：
Can be shorthand as V.
The return value of this function on the root TICK is the cumulative value of all TICK transactions for the day.
example 1：
VV:=V; //Define VV as volume
example 2：
REF(V,1); //indicates the volume of the previous cycle
example 3：
V>=REF(V,1); //The volume is greater than the volume of the previous cycle, indicating that the volume increases (V is short for VOL).
Forward Reference
Reference the value of X before N cycles.
Note：
1、When N is a valid value, but the current number of k lines is less than N, a null value is returned;
2、When N is 0, the current X value is returned;
3、When N is null, it returns a null value.
4、N can be a variable
example 1:
REF(CLOSE,5); indicates the closing price of the 5th cycle before the current cycle
example 2：
AA:=IFELSE(BARSBK>=1,REF(C,BARSBK),C);//Take the closing price of the K line of latest buying long of the open position signal
//1) When the k-line BARSBK of the BK signal returns a null value, the k-line REF(C, BARSBK) of the BK signal is returned.
Null value；
//2）When the BK signal is sent, the k-line BARSBK returns a null value, and if the BARSBK>=1 is not satisfied, then send the closing price of the k-line.
//3）The k-line BARSBK after the BK signal is sent returns the number of cycles of the K-line of the open position from the current K-line, REF(C, BARSBK)
Returns the closing price of the opening k line.
//4）Example: 1, 2, 3 three k lines, 1 K line is the opening position signal K line, then return the closing price of this k line, 2, 3
K line returns the closing price of the 1 K line.
Take the transaction unit of the data contract
Take the trading unit of the data contract.
usage：
UNIT takes the trading unit of the data loading contract.
Commodity Future
UNIT value is related to the contract
rb contract - 1 hand, 10 (tons)
Cryptocurrency Spot
UNIT value is 1
Cryptocurrency futures UNIT value is related to contract currency
OKEX Futures: 1 BTC contract represents $100, and 1 contract in other currencies represents $10
Minimum price change for data contracts
Take the minimum price change of the data contract.
usage:
MINPRICE; Take the minimum price change for loading data contracts.
Minimum change in trading contract
Take the minimum price change of the trading contract.
usage：
MINPRICE1; Take the minimum price change of the trading contract.
Take the position of the K line
BARPOS，returns the number of cycles from the first K line to the current cycle.
Note：
1、BARPOS returns the number of existing K lines in the local area, starting from the data existing on the local machine.
2、The return value of the first K line already on the local machine is 1.
example 1：LLV(L,BARPOS);//Find the minimum value of the local existing data.
example 2：IFELSE(BARPOS=1,H,0);//The current K line is the highest value of the first K line already in the local machine, otherwise it is 0.
The period value is the number of minutes.
1, 3, 5, 15, 30, 60, 1440
DATE
Function：DATE
Parameters: None
Explanation : Obtain the date of the cycle from 1900
Sequence data
Take the time of the K line
TIME，take the K line time.
Note：
1、The function returns in real time on the real-market, and returns the start time of the K line after the K line is finished.
2、The function returns the exchange data reception time, which is the exchange time.
3、The TIME function returns a six-digit form when used in the second period, ie: HHMMSS, which is displayed in four-digit form on other periods, namely: HHMM.
4、The TIME function can only be loaded in the period below the daily period. The return value of the function is always 1500 in the period above the daily period (Included the daily period).
5、use the TIME function to close the position of the tail operation needs attention
（1） The time set by the end of the closing position is recommended to be set to the actual time that can be taken in the K line return value (eg, the RB index is 5 minutes, the last K line return time is 1455, and the tail closing position is set to TIME> =1458, CLOSEOUT; the signal that the tail is closed can not appear in the effect test)
（2） Using the TIME function as the condition for closing the position at the end of the market, it is recommended to open position condition also to make the corresponding time limit (such as setting the closing condition of the tail to TIME>=1458, CLOSEOUT; then the corresponding opening conditions are required Add condition TIME<1458; avoid opening the position again after closing the position)
example 1:
C>O&&TIME<1450,BK;
C<O&&TIME<1450,SK;
TIME>=1450,SP;
TIME>=1450,BP;
AUTOFILTER;
//Close the position after 14:50.
example 2：
ISLASTSK=0&&C>O&&TIME>=0915,SK;
Years
YEAR，the year is obtained.
Note：
YEAR ranges from 1970—2033。
example 1：
N:=BARSLAST(YEAR<>REF(YEAR,1))+1;
HH:=REF(HHV(H,N),N);
LL:=REF(LLV(L,N),N);
OO:=REF(VALUEWHEN(N=1,O),N);
CC:=REF(C,N);//take the highest price, the lowest price, the opening price, and the closing price of the previous year.
example 2：
NN:=IFELSE(YEAR>=2000 AND MONTH>=1,0,1);
Returns the month of a cycle
MONTH, returns the month of a cycle.
Note：
MONTH has a value range of 1-12.
example 1：
VALUEWHEN(MONTH=3&&DAY=1,C);//The closing price is taken when the K-line date is March 1.
example 2：
C>=VALUEWHEN(MONTH<REF(MONTH,1),O),SP;
Get the number of days in a cycle
DAY, returns the number of days in a cycle.
Note：
The DAY value ranges from 1-31.
example 1：
DAY=3&&TIME=0915，BK;//From the date of 3 days, the time is 9:15, buy long.
example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;
CC:=IFELSE(DAY=1,VALUEWHEN(N=1,O),0);//When the date is 1, the opening price is taken, otherwise the value is 0.
HOUR
HOUR，Returns the number of hours in a cycle.
Note：
HOUR ranges from 0 to 23
example 1：
NX:=BARSLAST(CROSS(HOUR=9,0.5));
DRAWLINE3(CROSSDOWN(HOUR=14,0.5),REF(H,NX),NX,CROSSDOWN(HOUR=14,0.5),REF(H,1),1,0),COLORGREEN;
//Connect 9:00 to the latest k-line high point before the market close.
example 2：
HOUR=10;//The return value is 1 on the K line at 10:00, and the return value on the remaining K lines is 0.
MINUTE
MINUTE, Returns the number of minutes in a cycle.
Note：
1：MINUTE has a value range of 0-59
2：This function can only be loaded on the minute period, returning the number of minutes since the current K line.
example 1：
MINUTE=0；//The return value on the minute K line at the beginning of an hour is 1, and the remaining K lines return a value of 0.
example 2：
TIME>1400&&MINUTE=50,SP;//close position at 14:50.
Get the number of weeks
WEEKDAY, get the number of weeks.
Note：
1：WEEKDAY has a value range of 0-6.
2：The value displayed by the function on the weekly cycle is always 5, and the number of weeks on the day of the end of the K line is returned on the monthly cycle.
example 1：
N:=BARSLAST(MONTH<>REF(MONTH,1))+1;
COUNT(WEEKDAY=5,N)=3&&TIME>=1450,BP;
COUNT(WEEKDAY=5,N)=3&&TIME>=1450,SP;
AUTOFILTER;//each month delivery date is automatically closed all position at the end of that day.
example 2：
C>VALUEWHEN(WEEKDAY<REF(WEEKDAY,1),O)+10,BK;
AUTOFILTER;
Returns the position status of the current cycle
BARSTATUS returns the position status of the current cycle.
Note：
The function returns 1 to indicate that the current cycle is the first cycle, return 2 to indicate the last cycle, and return 0 to indicate that the current cycle is in the middle position.
example:
A:=IFELSE(BARSTATUS=1,H,0); //If the current K line is the first cycle, the variable A returns the highest value of the K line, otherwise it takes 0.
Between
BETWEEN(X,Y,Z) indicates whether X is between Y and Z, and returns 1 (Yes), otherwise returns 0 (No).
Note：
1、If X=Y, X=Z, or X=Y and Y=Z, the function returns a value of 1 (Yse).
example 1：
BETWEEN(CLOSE,MA5,MA10); //indicates that the closing price is between the 5-day moving average and the 10-day moving average.
Cross Function
CROSS(A,B) means that A passes B from the bottom to up, and returns 1 (Yes), otherwise it returns 0 (No).
Note：
1、The conditions for crossing must satisfy A<=B of pervious k line, and it is confirmed as crossing when the current k-line satisfies A>B.
example 1：
CROSS(CLOSE,MA(CLOSE,5)); //means the crossing line from below through the 5-period moving average
Crossing down
CROSSDOWN(A,B)：indicates that when A down crossing B from above, it returns 1 (Yes), otherwise it returns 0 (No).
Note：
1、CROSSDOWN (A, B) is equivalent to CROSS (B, A), CROSSDOWN (A, B) is written to better understand
example 1：
MA5:=MA(C,5);
MA10:=MA(C,10);
CROSSDOWN(MA5,MA10),SK; //MA5 down cross MA10, sell short
//CROSSDOWN(MA5,MA10),SK; and CROSSDOWN(MA5,MA10)=1, SK; express the same meaning
Crossing up
CROSSUP(A,B) When A passes up from bottom to B, it returns 1 (Yes), otherwise it returns 0 (No)
Note：
1、CROSSUP (A, B) is equivalent to CROSS (A, B), CROSSUP (A, B) is written to better understand.
example 1：
MA5:=MA(C,5);
MA10:=MA(C,10);
CROSSUP(MA5,MA10),BK;//MA5 cross up MA10, buy long.
//CROSSUP(MA5,MA10),BK; and CROSSUP(MA5,MA10)=1, BK; express the same meaning
Determine whether it continues to meet the requirement
EVERY(COND,N)，judge whether the COND condition is always satisfied in the N period. If it is, the function returns a value of 1; if it is not, the function returns a value of 0;
Note：
1、N contains the current k line.
2、If N is a valid value, but there are not many K lines in front of it, or N is a null value, the condition is not satisfied, and the function returns 0.
3、N can be a variable
example 1：
EVERY(CLOSE>OPEN,5);//indicates that it has been a positive line for 5 cycles.
example 2：
MA5:=MA(C,5);//Define a 5-cycle moving average
MA10:=MA(C,10);//Define the 10-cycle moving average
EVERY(MA5>MA10,4),BK;//MA5 is greater than MA10 in 4 cycles, then buy long.
//EVERY(MA5>MA10,4),BK; and EVERY(MA5>MA10,4)=1, BK; express the same meaning
Determine if there is satisfaction
EXIST(COND,N) determines whether there are conditions for satisfying COND in N cycles
Note:
1、N contains the current k line.
2、N can be a variable.
3、If N is a valid value, but there are not many K lines in front of it, calculate according to the actual number of cycles.
example 1：
EXIST(CLOSE>REF(HIGH,1),10);indicates whether there is a maximum price in the 10 cycles that is greater than the previous period, if it exist, return 1, and if it does not exist, returns 0.
example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;
EXIST(C>MA(C,5),N);//Indicates whether there is a k line that meets the closing price greater than the 5-period moving average. If it exist, return 1, and if it does not exist, return 0.
Conditional Function
IF(COND,A,B) Returns A if the COND condition is true, otherwise returns B
Note：
1、COND is a judgment condition; A and B can be conditions or numerical values.
2、the function supports the variable loop to reference the previous period of its own variable, that is, support the following writing method Y: IF (CON, X, REF (Y, 1));
example 1：
IF(ISUP,H,L);// k line is the rising line, take the highest price, otherwise take the lowest price
example 2：
A:=IF(MA5>MA10,CROSS(DIFF,DEA),IF(CROSS(D,K),2,0));//When MA5>MA10, take whether DIFF is cross up the DEA, otherwise (MA5 Not greater than MA10), when K, D is down crossing, let A be assigned a value of 2. If the above conditions are not met, A is assigned a value of 0.
A=1,BPK;//When MA5>MA10, use DIFF cross up DEA as the buying long condition
A=2,SPK;//When MA5 is not greater than MA10, K D down crossing are used as selling short conditions
Conditional Function
IFELSE(COND,A,B) Returns A if the COND condition is true, otherwise returns B
Note：
1、COND is a judgment condition; A and B can be conditions or numerical values.
2、the function supports the variable loop to refer to the previous period of its own variable, that is, supports the following writing method Y: IFELSE (CON, X, REF (Y, 1));
example 1：
IFELSE(ISUP,H,L);//k line is the rising line, take the highest price, otherwise take the lowest price
example 2：
A:=IFELSE(MA5>MA10,CROSS(DIFF,DEA),IFELSE(CROSS(D,K),2,0)); //When MA5>MA10, whether DIFF up cross DEA, otherwise (MA5 Not greater than MA10), when K, D down cross, let A be assigned a value of 2. If the above conditions are not met, A is assigned a value of 0.
A=1,BPK;//When MA5>MA10, use DIFF up cross DEA as the buying long condition
A=2,SPK;//When MA5 is not greater than MA10, K, D down cross are used as selling short conditions
weather the currently contract a designated contract
weather ISCONTRACT(CODE) is currently the specified contract.
Usage：ISCONTRACT(CODE); is the current contract returns 1, not the current contract returns 0.
Note：
1、When judging whether it is a specified contract, CODE can be the transaction code of the contract.
example:
ISCONTRACT('MA888');
ISCONTRACT('rb1901');
ISCONTRACT('this_week'); // cryptocurrency OKEX Futures Contract
ISCONTRACT('XBTUSD'); // cryptocurrency BITMEX Futures Contract
Support for regular expressions
Determine contract
ISCONTRACT('this_week'); // Determine if the current contract is OKEX futures this_week (week) contract
Judging the name of the exchange
ISCONTRACT('@Futures_(CTP|BitMEX)'); // Determine whether the current exchange object is a commodity futures or a cryptocurrency BITMEX futures exchange
ISCONTRACT('@(OKEX|Bitfinex|Futures_CTP)'); // To determine the exchange, you need to add @ character at the beginning
Falling K line
ISDOWN determines whether the cycle is falling
Note：
1、ISDOWN is equivalent to C<O
example：
ISDOWN=1&&C<REF(C,1),SK;//When the current k line is finished and the closing price is lower than the closing price of the previous period, then selling short
//ISDOWN=1&&C<REF(C,1),SK; is equivalent to ISDOWN&&C<REF(C,1),SK;
The opening price equal to closing price
ISEQUAL determines if the cycle is "The opening price equal to closing price"
Note：
1、ISEQUAL is equivalent to C=O
example 1：
EVERY(ISEQUAL=1,2),CLOSEOUT; //continue for 2 k lines are “The opening price equal to closing price
“, then close all position.
```
Determine if the cycle is the last K line
ISLASTBAR determines if the cycle is the last k line
example 1：
VALUEWHEN(ISLASTBAR=1,REF(H,1));//The current k-line is the last k-line, taking the highest price of the previous cycle.
Determine null
ISNULL determine whether it is null or not
Usage：ISNULL(N);if N is null, the function returns 1; if N is non-null, the function returns 0.
Example: MA5:=IFELSE(ISNULL(MA(C,5))=1, C,MA(C,5));//Define a five-period moving average. When the number of K-lines is less than five, return the current K-line closing price.
Rising line
ISUP determines whether the cycle is rising
Note：
1、ISUP is equivalent to C>O
example：
ISUP=1&&C>REF(C,1),BK; //If the current k line is a rising k line and the closing price is greater than the closing price of the previous period, then buying long.
//ISUP=1&&C>REF(C,1),BK; and ISUP&&C>REF(C,1),BK;
//Express the same meaning
Determine Function
LAST(COND,N1,N2) Determines whether the COND condition has been met for the past N1 to N2 cycles.
Note：
1、If N1 and N2 differ by only one cycle (eg, N1=3, N2=2), the function judges whether the condition is satisfied on the cycle closest to the current K line (ie, whether the K line in the past N2 cycles is meeting the conditions)
2、When N1/N2 is a valid value, but the current k-line number is less than N1/N2, or N1/N2 null, means is not true, and the function returns 0.
3、N1 and N2 cannot be variables.
example 1：
LAST(CLOSE>OPEN,10,5); // indicates that it has been a rising line from the 10th cycle to the 5th cycle in the past.
example 2：
MA5:=MA(C,5);
LAST(C>MA5,4,3);//determine whether the K line from the current k-line 3 cycles satisfies “C greater than MA5”.
Maintain Cross Function
LONGCROSS(A,B,N) indicates that A is less than B in N cycles, and this cycle A up cross B from bottom to top.
Note：
1、When N is a valid value, but the current k-line number is less than N, the LONGCROSS function returns a null value.
2、N does not support variables.
example 1：
LONGCROSS(CLOSE,MA(CLOSE,10),20); //indicates that the closing price continues below the 10-day moving average for 20 cycles and then up cross the 10-day moving average from bottom to top.
non-
NOT(X)：Take a non. Returns 1 when X=0, otherwise returns 0.
example 1：
NOT(ISLASTBK); If the previous signal is not a BK signal, the NOT (ISLASTBK) returns a value of 1; the previous signal is a BK signal, and the NOT (ISLASTBK) returns a value of 0.
example 2：
NOT(BARSBK>=1)=1;//The BK signal is sent to the current K line to satisfy the condition.
//NOT(BARSBK>=1)=1 is equivalent to NOT (BARSBK>=1).
Return null
Return null
usage：
MA5:=MA(C,5);
MA10:=MA(C,10);
A:=IFELSE(MA5>MA10,MA5,NULL),COLORRED;//When MA5>MA10, draw the five-day moving average MA5, when MA5>MA10 is not satisfied, return null value, no drawing line.
Value
VALUEWHEN(COND,X) Takes the current value of X when the COND condition is true. If the COND condition is not true, take the value of X when the COND condition is established last time.
Note：
X can be either a numerical value or a condition.
example 1
VALUEWHEN(HIGH>REF(HHV(HIGH,5),1),HIGH);indicates that the current highest price is greater than the maximum value of the highest price of the first five cycles and returns the current highest price.
example 2：
VALUEWHEN(DATE<>REF(DATE,1),O);indicates the opening price of the first k-line of the day
example 3：
VALUEWHEN(DATE<>REF(DATE,1),L>REF(H,1));//indicates whether the current lowest price on the first k line of the day is greater than the highest price of the last K line yesterday. Returns 1, indicating that there is a price gap on that day. Returns 0, indicating that there are no price gap on that day.
Loop condition function
LOOP2(COND,A,B); loop condition function Returns A if the COND condition is true, otherwise returns B
Note：
1、COND is a judgment condition; A and B can be conditions or numerical values.
2、the function supports variable loop reference to the previous period of its own variable, that is, support the following writing method Y: = LOOP2 (CON, X, REF (Y, 1));
example 1：
X:=LOOP2(ISUP,H,REF(X,1));//k line is the rising line, take the highest price of the current K line, otherwise take the highest price of the pervious K line that is a rising k line; if it has not appeared before, X returns null
example 2:
BB:=LOOP2(BARSBK=1,LOOP2(L>LV(L,4),L,LV(L,4)),LOOP2(L>REF(BB,1),L,REF(BB,1)));//When holding long position, the lowest price in the first 4 cycles of opening position k line is the starting stop loss point BB, if the lowest price of the subsequent K line is higher than the previous lowest price, taking the current lowest price as stop loss point, otherwise take the previous lowest point to be the stop loss point.
SS:=LOOP2(BARSSK=1,LOOP2(H<HV(H,4),H,HV(H,4)),LOOP2(H<REF(SS,1),H,REF(SS,1)));// When holding short position, the highest price in the first 4 cycles of opening position k line is the starting stop loss point SS, if the highest price is lower than the previous highest price, taking the current highest price as stop loss point, Otherwise take the previous high point as stop lose points
H>HV(H,20),BK;
L<LV(L,20),SK;
C<BB,SP;
C>SS,BP;
AUTOFILTER;
The number of cycles that the first valid period to the current one
BARSCOUNT(COND) The number of cycles that the first valid period to the current one
Note：
1、The return value is the number of cycles from which the COND is calculated from the first valid period and up to now.
2、The return value of BARSCOUNT(COND) on the current k line on the condition that the condition is first established is 0.
example：
BARSCOUNT(MA(C,4));//The calculation MA(C,4) has the first return value to the current number of cycles.
Last condition established true
BARSLAST(COND)：The last condition COND was established to the current number of cycles
Note：
1、The return value of BARSLAST(COND) on the current k line is 0.
example 1：
BARSLAST(OPEN>CLOSE); //The number of cycles from the previous falling k line to the present
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k line on the current day.
//Because the condition is established, the return value of BARSLAST(COND) on the current k line is 0, so "+1" is the k-line number of current day.
The first condition is established to the current number of cycles
BARSSINCE(COND) The first condition is established to the current number of cycles.
Note：
1、the return value is the first time the COND is established to the current number of cycles
2、The return value of BARSSINCE (COND) on the current k-line of the condition established for the first time is 0.
example ：
BARSSINCE(CLOSE>OPEN);
//Statistics of the number of cycles from the K line that satisfies the condition of the first line to the present.
Statistics The first condition in the N period is established until the current number of cycles
BARSSINCEN(COND,N) counts the first condition is true in the N cycle to the current number of cycles
Note：
1、N contains the current k line.
2、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k lines;
3、If N is 0, return an invalid value;
4、N can be a variable
example：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of K lines on the day.
BARSSINCEN(ISUP,N);//Statistics for the first time in the N cycle to meet the number of cycles from the rising line to the current
Get the number of K-line cycles that have recently met the A, B conditions
CONDBARS(A,B);obtain the latest number of k-line cycles that satisfy the conditions of A and B
note：
1、The function returns the number of cycles does not contain the K line that finally meets the condition
2、The condition that is closest to the current K line is the B condition, and the return value of the function is the number of cycles from the K line that satisfies the A condition for the last time to the K line that satisfies the B condition (the first time after the condition A satisfies B)
The condition that is closest to the current K line is the A condition, and the return value of the function is the number of cycles of the K line that satisfies the condition B for the last time to the K line that satisfies the condition A (the first condition that satisfies the condition A after the condition B is satisfied)
For this part, it’s a little bit complicated above, let’s put it in short, the above expression is trying to calculating how many k lines are there between cross up and cross down. However, sometime is cross up first, sometimes is cross down first.
example 1：
MA5:=MA(C,5);//5 cycle moving average
MA10:=MA(C,10);//10 cycle moving average
CONDBARS(CROSSUP(MA5,MA10),CROSSDOWN(MA5,MA10));//The number of cycles(k lines) between the 5 moving average line cross up the 10 moving average line and the 5 moving average line cross down the 10 moving average line.
Total number of statistics
COUNT(COND,N)：Counts the number of cycles in the N cycle that satisfy the COND condition.
Note：
1、N contains the current k line.
2、If N is 0, it starts from the first valid value;
3、When N is a valid value, but the current number of k lines is less than N, from the first k line to the current cycle.
4、When N is null, the return value is null.
5、N can be a variable
example 1：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days on the day
M:=COUNT(ISUP,N);//Statistically count the number of rising lines since the opening of the minute period.
Example 2：
MA5:=MA(C,5);//Define a 5-cycle moving average line
MA10:=MA(C,10);//Define a 10-cycle moving average line
M:=COUNT(CROSSUP(MA5,MA10),0);//Count the number of times the 5-cycle moving average line up cross the 10-cycle average line from the time the quoted market data is available.
Dynamic moving average
DMA(X,A)：Find the dynamic moving average of X, where A must be less than 1 and greater than zero.
Note：
1、A can be a variable
2、If A<=0 or A>=1, return an invalid value.
Calculation formula：DMA(X,A)=REF(DMA(X,A),1)*(1-A)+X*A
example 1：
DMA3:=DMA(C,0.3);//The result of the calculation is REF(DMA3,1)*(1-0.3)+C*0.3
Exponentially weighted moving average
EMA(X,N)：Find the exponentially weighted moving average of the N-cycle X value (smooth moving average).
Note：
1、N contains the current k line.
2、Give a larger weight to the k line that is closer to the current distance.
3、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k lines.
4、When N is 0 or a null value, the return value is null.
5、N can be a variable
EMA(X,N)=2*X/(N+1)+(N-1)*REF(EMA(X,N),1)/(N+1)
example 1：
EMA10:=EMA(C,10);//Getting the closing price 10 cycles exponentially weighted moving average
Linear weighted moving average
EMA2(X,N);//To obtain a linearly weighted moving average of the N-cycle X value (also known as WMA)
EMA2(X,N)=[N*X0+(N-1)*X1+(N-2)*X2+...+1*X(N-1)]/[N+(N-1)+(N-2)+...+1],X0 represents the value of this period, and X1 represents the value of the previous period
Note：
1、N contains the current k line.
2、When N is a valid value, but the current number of k lines is less than N, the return value is null.
3、When N is 0 or a null value, the return value is null.
4、N can be a variable
example 1：
EMA2(H,5);//Find the linear weighted moving average of the highest price over 5 cycles.
Index exponentially weighted moving average
EMAWH(C,N), an index exponentially weighted moving average, also called a smooth moving average, uses an exponential weighting method to give a larger weight to the K line that is closer to the current.
Note：
1、When N is a valid value, the current k-line number is less than N, or the value of the previous period is still applied to the current period, the EMAWH return value is null.
Because the EMAWH calculation formula focuses on the weight of the period, when the period is long, the previous period value has less influence on the current, and the EMAWH starts to display the value when the previous data no longer affects the current period, so even The selected data start time is different, and the value of the currently displayed K line EMAWH will not change.
2、When N is 0 or a null value, the return value is null.
3、N can not be a variable
EMAWH(C,N)=2*C/(N+1)+(N-1)*REF(EMAWH(C,N),1)/(N+1)
Note：
EMAWH usage is the same as EMA (C, N)
Harmonic average
HARMEAN(X,N) finds the harmonic mean of X over N cycles.
Algorithm example：HARMEAN(X,5)=1/[(1/X1+1/X2+1/X3+1/X4+1/X5)/5]
Note：
1、N contains the current k line.
2、The simple average of the harmonic mean and the reciprocal are reciprocal.
3、When N is a valid value, but the current number of k lines is less than N, the function returns a null value.
4、When N is 0 or a null value, the function returns a null value.
5、When X is 0 or a null value, the function returns a null value.
6、N can be a variable.
example：
HM5:=HARMEAN(C,5);//To find the harmonic mean of the 5-period closing price.
Highest value
HHV(X,N)：Find the highest value of X in N cycles.
Note：
1、N contains the current k line.
2、If N is 0, it starts from the first valid value;
3、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k lines;
4、When N is null, it returns a null value.
5、N can be a variable.
example 1：
HH:=HHV(H,4);//Find the maximum value of the highest price of 4 cycles, that is, the 4-cycle high point (including the current k-line).
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
HH1:=HHV(H,N);//In the minute period, the intraday highest price
The highest value except the current K line
HV(X,N)： Find the highest value of X in N cycles (excluding the current k line).
Note：
1、If N is 0, it starts from the first valid value (does not include the current K line);
2、When N is a valid value, but the current number of k lines is less than N, the first k line returns a null value according to the actual number of k lines;
3、When N is null, it returns a null value.
4、N can be a variable.
example 1：
HH:=HV(H,10);//Find the highest point of the most recent 10 k lines.
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;
NN:=REF(N,N);
ZH:=VALUEWHEN(DATE<>REF(DATE,1),HV(H,NN));//On the minute period, ask for the highest price of yesterday.
Example 3：
HV(H,5) and REF(HHV(H,5),1) are the same, and it is more convenient to write with HV.
Previous highest point
HHVBARS(X,N)： Find the highest value of X in the N period to the current number of cycles
Note：
1、If N is 0, it starts from the first valid value (does not include the current K line);
2、When N is a valid value, but the current number of k lines is less than N, the first k line returns a null value according to the actual number of k lines;
3、When N is null, it returns a null value.
4、N can be a variable.
example 1：
HHVBARS(VOL,0); Find the period with the largest historical volume to the current number of cycles (the maximum k-line HHVBARS(VOL,0); the return value is 0, the first k-line returns after the maximum value The value is 1, and so on).
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
ZHBARS:=REF(HHVBARS(H,N),N)+N;//In the minute period, find the number of cycles between the k line where the highest price was yesterday and the current k line.
Lowest value
LLV(X,N)： Find the minimum value of X over N cycles.
Note：
1、N contains the current k line.
2、If N is 0, it starts from the first valid value;
3、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k lines;
4、When N is null, it returns a null value.
5、N can be a variable.
example 1：
LL:=LLV(L,5);//Find the lowest point of 5 k lines (including the current k line).
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
LL1:=LLV(L,N);//On the minute period, find the minimum value of the lowest price of all k lines from the first k line to the current period.
The lowest value except the current K line
LV(X,N) Find the minimum value of X in N cycles (excluding the current k line)
Note：
1、If N is 0, it starts from the first valid value;
2、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k lines;
3、When N is null, it returns a null value.
4、N can be a variable.
example 1：
LL:=LV(L,10);//get the lowest point of the most recent 10 k lines. (does not include the current k line)
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
NN:=REF(N,N);
ZL:=VALUEWHEN(DATE<>REF(DATE,1),LV(L,NN));//On the minute period, get the lowest price of yesterday.
Example 3：
LV(L,5) and REF(LLV(L,5),1) are the same, and it is more convenient to write in LV.
Previous lowest point position
LLVBARS(X,N)：Find the lowest value of X in the N period to the current number of cycles
Note：
1、If N is 0, it starts from the first valid value (does not include the current K line);
2、When N is a valid value, but the current number of k lines is less than N, the first k line returns a null value according to the actual number of k line;
3、When N is null, it returns a null value.
4、N can be a variable.
example 1：
LLVBARS(VOL,0); Find the period with the smallest historical volume to the current number of cycles (the smallest value on the k-line LLVBARS(VOL,0); the return value is 0, the first k-line returns after the minimum value The value is 1, and so on).
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
ZLBARS:=REF(LLVBARS(L,N),N)+N;//On the minute period, find the number of cycles between the k-line where the lowest price was yesterday and the current k-line.
Arithmetic moving average
MA(X,N) Find the simple moving average of X over N cycles
Algorithm：MA(X,5)=(X1+X2+X3+X4+X5)/5
Note：
1、N contains the current k line.
2、the simple moving average follows the simplest statistical method, taking the average price of a certain time in the past.
3、When N is a valid value, but the current number of k lines is less than N, the function returns a null value.
4、When N is 0 or a null value, the function returns a null value.
5、N can be a variable
example 1：
MA5:=MA(C,5);//To find a simple moving average of the 5-period closing price.
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
M:=IFELSE(N>10,10,N);//k line exceeds 10, M takes 10, otherwise M takes the actual number of k line
MA10:=MA(C,M);//In the minute period, there are less than 10 k lines on the day, MA10 is calculated according to the actual number of k line, and more than 10 are calculated according to 10 cycles.
Mean value
MV(A,...P) takes the mean of A to P.
Note：
1、support the average of 2-16 values
2、A...P can be a number or a variable
example 1：
MV(CLOSE,OPEN);
//Take the average of the closing price and the opening price
Natural number power sum
NUMPOW(X,N,M);natural number power sum
algorithm：
NUMPOW(x,n,m)=n^m*x+(n-1)^m*ref(x,1)+(n-2)^m*ref(x,2)+...+2^m*ref(x,n-2)+1^m*ref(x,n-1)
note:
1、N is a natural number, M is a real number; and N and M cannot be variables
2、X is the base variable
example：
JZ:=NUMPOW(C,5,2);
Parabolic steering
SAR(N,STEP,MAX) Returns the parabolic steering value.
Calculated according to the formula SAR(n)=SAR(n-1)+AF*(EP(n-1)-SAR(n-1))
among them：
SAR(n-1)：the absolute value of the last K-line SAR
AF：Acceleration factor. When AF is less than MAX, it is accumulated by AF+STEP in every k line. When the conversion occurs, the AF is recalculated.
EP：the extreme value within a rise and fall, the highest price of the last K-line in the rising market; the lowest price of the last K-line in the falling market
Note：
1、the parameters N, Step, Max do not support variables
example 1：
SAR(17,0.03,0.3);// indicates that 17 cycles of parabolic steering are calculated with a step size of 3% and a limit of 30%.
Extended index exponential weighted moving average
SMA(X,N,M) finds the extended exponential weighted moving average over N periods of X. M is the weight.
Calculation formula：SMA(X,N,M)=REF(SMA(X,N,M),1)*(N-M)/N+X(N)*M/N
Note：
1、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k line.
2、When N is 0 or a null value, the function returns a null value.
example 1：
SMA10:=SMA(C,10,3);//Find the extended index exponential weighted moving average of the 10-period closing price. The weight is 3.
Smooth moving average
SMMA(X,N)，where X is a variable, N is a period, and SMMA(X,N) is the smooth moving average line of X on the current K line at N cycles.
Algorithm：SMMA(X,N)=(SUM1-MMA+X)/N
Where SUM1=X1+X2+.....+XN
MMA=SUM1/N
example 1：
SMMA(C,5);//5-period smooth moving average of closing price
Take the value sorted at the corresponding position
SORT(Type,POS,N1,N2,...,N16); arranged in ascending (descending) order, taking the value corresponding to the POS parameter
Note：
1、When Type is 0, it is sorted in ascending order, when Type is 1, it is sorted in descending order;
2、TYPE, POS, does not support variables
3、N1, ..., N16 are parameters, support constants, variables, support up to 16 parameters
example：
SORT(0,3,2,1,5,3);//2, 1, 5, 3 are arranged in ascending order, taking the third number 3
Summation
SUM(X,N) finds the sum of X over N cycles.
Note:
1、N contains the current k line.
2、If N is 0, it starts from the first valid value.
3、When N is a valid value, but the current number of k lines is less than N, it is calculated according to the actual number of k line.
4、When N is null, it returns a null value.
5、N can be a variable.
example 1：
SUM(VOL,25);indicates the sum of the volume of the statistics within 25 cycles
Example 2：
N:=BARSLAST(DATE<>REF(DATE,1))+1;//minute period, the number of k-days in the day
SUM(VOL,N);//minute cycle, take the sum of the day trading volume.
The number of cycles added to the specified value
SUMBARS(X,A)：the number of cycles to add to the specified value
Note：
Parameter A supports variables
example 1：
SUMBARS(VOL,20000); The volume is accumulated forward until it is greater than or equal to 20000, and the number of cycles in this interval is returned.
Triangular moving average
TRMA(X,N)：Find the triangular moving average of X over N cycles.
Algorithm: The triangular moving average formula uses the arithmetic moving average and applies the arithmetic moving average to the first moving average again.
TRMA(X,N) algorithm is as follows
ma_half= MA(X,N/2)
trma=MA(ma_half,N/2)
Note：
1、N contains the current k line。
2、When N is a valid value, but the current number of k lines is less than N, the function returns a null value.
3、When N is 0 or a null value, the function returns a null value.
4、N supports the use of variables
example 1：
TRMA5:=TRMA(CLOSE,5);//Calculate the triangular moving average of the closing price within 5 cycles. (N cannot be divisible by 2)
// TRMA(CLOSE,5)=MA(MA(CLOSE,(5+1)/2)),(5+1)/2);
Example 2:
TRMA10:=TRMA(CLOSE,10);//Calculate the triangular moving average of the closing price in 10 cycles. (N can be divisible by 2)
// TRMA(CLOSE,10)=MA(MA(CLOSE,10/2),(10/2)+1));
Time series moving average
TSMA(X,N)：Find the time series triangular moving average of X in N cycles
TSMA(a,n) algorithm is as follows:
ysum=a[i]+a[i-1]+...+a[i-n+1]
xsum=i+i-1+..+i-n+1
xxsum=i*i+(i-1)*(i-1)+...+(i-n+1)*(i-n+1)
xysum=i*a[i]+(i-1)*a[i-1]+...+(i-n+1)*a[i-n+1]
k=(xysum -(ysum/n)*xsum)/(xxsum- xsum/n * xsum) //slope
b= ysum/n - k*xsum/n
forcast[i]=k*i+b //linear regression
tsma[i] = forcast[i]+k //linear regression + slope
Note：
1、When N is a valid value, but the current number of k lines is less than N, the function returns a null value.
2、When N is 0 or a null value, the function returns a null value.
3、N supports the use of variables
example 1：
TSMA5:=TSMA(CLOSE,5);//Calculate the sequence triangle moving average of the closing price within 5 cycles
Average absolute deviation
AVEDEV(X,N)：Returns the average absolute deviation of X over the N period.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, and the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is a null value, the function returns a null value;
5、N can not be a variable
Algorithm example: Calculate AVEDEV(C,3); the value on the nearest K line.
The M language function can be expressed as follows:
(ABS(C-(C+REF(C,1)+REF(C,2))/3)+ABS(REF(C,1)-(C+REF(C,1)+REF(C,2))/3)+ABS(REF(C,2)-(C+REF(C,1)+REF(C,2))/3))/3;
example：
AVEDEV(C,5);//Returns the average absolute deviation of the closing price within 5 cycles.
//Indicates the average of the absolute value of the difference between the closing price of each cycle in 5 cycles and the average value of the closing price of 5 cycles, and determines the degree of deviation of the closing price from its mean
Pearson correlation coefficient
COEFFICIENTR(X,Y,N) Find the Pearson correlation coefficient of X and Y in N cycles.
Note：
1、N contains the current k line.
2、N is a valid value, but the current number of k lines is less than N, and the function returns a null value.
3、When N is 0, the function returns a null value.
4、N is null and the function returns a null value.
5、N can be a variable.
Algorithm example: Calculate COEFFICIENTR(O, C, 3); the value on the nearest K line.
The M language function can be expressed as follows:
(((O-MA(O,3))*(C-MA(C,3))+(REF(O,1)-MA(O,3))*(REF(C,1)-MA(C,3))+(REF(O,2)-MA(O,3))*(REF(C,2)-MA(C,3))) /(STD(O,3)*STD(C,3)))/(3-1);
example：
COEFFICIENTR(C,O,10); //Find the Pearson correlation coefficient in 10 cycles.
//The Pearson correlation coefficient is an indicator of the degree of correlation between two random variables.
Correlation coefficient
CORRELATION(X,Y,N) Find the correlation coefficient of X and Y in N cycles.
Note：
1、N contains the current k line.
2、N is a valid value, but the current number of k lines is less than N, and the function returns a null value.
3、When N is 0, the function returns a null value.
4、N is null and the function returns a null value.
5、N can be a variable.
Algorithm example: Calculate CORRELATION (O, C, 3); the value on the nearest K line.
The M language function can be expressed as follows:
(((O-MA(O,3))*(C-MA(C,3))+(REF(O,1)-MA(O,3))*(REF(C,1)-MA(C,3))+(REF(O,2)-MA(O,3))*(REF(C,2)-MA(C,3))))/SQRT((SQUARE(O-MA(O,3))+SQUARE(REF(O,1)-MA(O,3))+SQUARE(REF(O,2)-MA(O,3)))*(SQUARE(C-MA(C,3))+SQUARE(REF(C,1)-MA(C,3))+SQUARE(REF(C,2)-MA(C,3))));
example：
CORRELATION(C,O,10);//Find the correlation coefficient in 10 cycles.
//Correlation coefficient is an indicator to measure the degree of correlation between two random variables
Covariance
COVAR(X,Y,N) Find the covariance of X and Y over N cycles.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, and the function returns a null value.
3、When N is 0, the function returns a null value.
4、N is null and the function returns a null value.
5、N can be a variable.
Algorithm example：Calculate COVAR(O, C, 3); the value on the nearest K line.
The M language function can be expressed as follows:
(((O-MA(O,3))*(C-MA(C,3))+(REF(O,1)-MA(O,3))*(REF(C,1)-MA(C,3))+(REF(O,2)-MA(O,3))*(REF(C,2)-MA(C,3))) )/3;
example：
COVAR(C,O,10);//Find the covariance in 10 cycles.
//The variance between two different variables is the covariance. If the trends of the two variables are the same, then the covariance between the two variables is positive; if the two variables change in opposite directions, then the two variables The covariance between them is a negative value.
Get the square of the data deviation
DEVSQ(X,N)： Calculates the sum of squared data deviations for N periods of data X.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is a null value, the function returns a null value;
5、N does not support as a variable
Algorithm example: Calculate DEVSQ(C,3); the value on the nearest K line.
The M language function can be expressed as follows:
SQUARE(C-(C+REF(C,1)+REF(C,2))/3)+SQUARE(REF(C,1)-(C+REF(C,1)+REF(C,2))/3)+SQUARE(REF(C,2)-(C+REF(C,1)+REF(C,2))/3);
example：
DEVSQ (C, 5); Calculate the sum of the squares of the data deviations of the data closing price of 5 cycles.
// Indicates that the deviation between the closing price and the closing price is squared separately, and DEVSQ(C, 5) indicates that the five-period closing price and the closing price mean are respectively squared and then summed.
Linear regression
FORCAST(X,N)：is the N-period linear regression predictor of X.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, and the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is a null value, the function returns a null value;
5、N can be a variable
Algorithm example: Calculate the value of FORCAST(C,3) on the nearest K line using the least squares method
1、Establish a linear equation：y=a+b*i+m
2、Estimated value of y：y(i)^=a+b*i
3、Find the residual：m^=y(i)-y(i)^=y(i)-a-b*i
4、The sum of squared errors:
Q=m(1)*m(1)+...+m(3)*m(3)=[y(1)-a-b*1]*[y(1)-a-b*1]+...+[y(3)-a-b*3]*[y(3)-a-b*3]
5、Find the first-order partial derivative of the parameters a, b in the linear equation:
2*{[y(1)-a-b*1]+...+[y(3)-a-b*3]}*(-1)=0
2*[y(1)-a-b*1]*(-1)+...+[y(3)-a-b*3]*(-3)=0
6、the two formulas above, solve the value of a, b:
a=(y(1)+y(2)+y(3))/3-b(i(1)+i(2)+i(3))/3
b=(y(1)*i(1)+y(2)*i(2)+y(3)*i(3)-(3*((i(1)+i(2)+i(3))/3)*((y(1)+y(2)+y(3))/3))/((i(1)^2+i(2)^2+i(3)^2)-3*((i(1)+i(2)+i(3))/3)^2)
7、Bring the a, b, and i values into 1, and find the y value.
The above formula can be expressed as follows using the M language grammar function:
BB:=(3*C+2*REF(C,1)+REF(C,2)-(3*((1+2+3)/3)*MA(C,3)))/((SQUARE(1)+SQUARE(2)+SQUARE(3))-3*SQUARE((1+2+3)/3));
AA:=MA(C,3)-BB*(1+2+3)/3;
YY:=AA+BB*3;
example:
FORCAST(CLOSE,5);//indicates the prediction of 5-cycle linear regression
Kurtosis coefficient
KURTOSIS(X,N) finds the kurtosis coefficient of X over N cycles.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, and the function returns a null value.
3、When N is 0, the function returns a null value.
4、N is null and the function returns a null value.
5、N can be a variable.
6、N is at least 4, if it less than 4, it will returns a null value.
Algorithm example: Calculate KURTOSIS (C, 4); the value on the nearest K line.
The M language function can be expressed as follows:
((POW(C-MA(C,4),4)+POW(REF(C,1)-MA(C,4),4)+POW(REF(C,2)-MA(C,4),4)+POW(REF(C,3)-MA(C,4),4)) /POW(STD(C,4),4))*(4*(4+1)/((4-1)*(4-2)*(4-3)))-3*SQUARE(4-1)/((4-2)*(4-3));
example：
KURTOSIS(C,10);
//Indicates the 10-cycle peak of the closing price. The peak reflects the sharpness or flatness of a distribution compared to a normal distribution. Positive peaks indicate a relatively sharp distribution. A negative peak indicates a relatively flat distribution.
Normal distribution probability density
NORMPDF(X, MU, SIGMA): Returns the value of the normal distribution density function at X at parameters MU and SIGMA
Note：
1、MU or SIGMA is null, and the function returns a null value.
2、MU and SIGMA support variables.
Algorithm example: The random variable X obeys a probability distribution with a position parameter of MU and a scale parameter of SIGMA, and its probability density is NORMPDF (X, MU, SIGMA).
The M language function can be approximated as follows:
(1/(SQRT(2*3.14)*SIGMA))*EXP((-SQUARE(X-MU))/(2*SQUARE(SIGMA)));
example：
TR:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
ATR:=MA(TR,26);//To find the simple moving average of TR in 26 cycles
ZZ..NORMPDF(ATR,0,1);//Define the variable ZZ to return the probability density of the ATR obeying the standard normal distribution.
Skewness coefficient
SKEWNESS(X,N) finds the skewness coefficient of X in N cycles.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value.
3、When N is 0, the function returns a null value.
4、N is null and the function returns a null value.
5、N can be a variable.
6、N is at least 3, and less than 3 returns a null value.
Algorithm example: Calculate SKEWNESS(C,3); the value on the nearest K line.
The M language function can be expressed as follows:
((POW(C-MA(C,3),3)+POW(REF(C,1)-MA(C,3),3)+POW(REF(C,2)-MA(C,3),3)) /POW(STD(C,3),3))*3/((3-1)*(3-2));
example:
SKEWNESS(C,10);
//Indicates the 10-cycle skew of the closing price. Skewness reflects the asymmetry of the distribution. The degree of asymmetry reflects the degree of asymmetry of the distribution centered on the mean. The positive asymmetry indicates that the distribution of the asymmetric portion tends to be more positive. Negative asymmetry means that the distribution of the asymmetric portion tends to be more negative.
Slope of linear regression
SLOPE (X, N): The slope of the linear regression of the N period of X is obtained.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is a null value, the function returns a null value;
5、N can be a variable.
Example：
Calculate the value of SLOPE(CLOSE,5) on the nearest K line using the least squares method:
1、Establish a linear equation: close=a+slope*i+m
2、close estimate: close (i) ^ = a + slope * i
3、Find the residual: m^=close(i)-close(i)^=close(i)-a-slope*i
4、The sum of squared errors:
Q=m(1)*m(1)+...+m(5)*m(5)=[close(1)-a-slope*1]*[close(1)-a-slope*1]+...+[close(5)-a-slope*5]*[close(5)-a-slope*5]
5、Find the first-order partial derivative of the parameter a, slope in the linear equation:
2*{[close(1)-a-slope*1]+...+[close(5)-a-slope*5]}*(-1)=0
2*{[close(1)-a-slope*1]+...+[close(5)-a-slope*5]}*(-5)=0
6、the two formulas above, the inverse solution of the slope value:
slope={[5*close(1))+...+1*close(5)]-[close(1)+...+close(5)]*(1+2+3+4+5)/5}/[(1*1+...+5*5)-(1+...+5)(1+...+5)/5]
The above formula can be expressed as follows using the M language grammar function:
((5*C+4*REF(C,1)+3*REF(C,2)+2*REF(C,3)+1*REF(C,4))-SUM(C,5)*(1+2+3+4+5)/5)/((SQUARE(1)+SQUARE(2)+SQUARE(3)+SQUARE(4)+SQUARE(5))-SQUARE(1+2+3+4+5)/5);
example：
SLOPE(CLOSE,5);indicates the slope of the linear regression line of 5 cycles of the closing price
Sample standard deviation
STD(X,N)：Find the sample standard deviation of X in N cycles.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value；
3、When N is 0, the function returns a null value；
4、N is null and the function returns a null value.
5、N can be a variable
Algorithm example: Calculate STD(C,3); the value on the nearest K line.
The M language function can be expressed as follows:
SQRT((SQUARE(C-MA(C,3))+SQUARE(REF(C,1)-MA(C,3))+SQUARE(REF(C,2)-MA(C,3)))/2);
example：
STD(C,10)seeks the sample standard deviation of the closing price in 10 cycles.
//Standard deviation represents the square root of the arithmetic mean of the square of the unit value of the population and its mean deviation, which reflects the degree of dispersion of a data set. STD (C, 10) represents the arithmetic square root of the average of the sum of the squares of the difference between the closing price and the 10-period moving average of the closing price. The sample standard deviation is the square root of the sample variance.
Overall standard deviation
STDP(X,N)：is the N standard total standard deviation of X.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is null and the function returns a null value.
5、N can be a variable
Algorithm example: Calculate STDP (C, 3); the value on the nearest K line.
The M language function can be expressed as follows:
SQRT((SQUARE(C-MA(C,3))+SQUARE(REF(C,1)-MA(C,3))+SQUARE(REF(C,2)-MA(C,3)))/3);
example：
STDP (C, 10) is the 10-cycle overall standard deviation of the closing price.
//The overall standard deviation is a statistical indicator reflecting the degree of difference between individuals in the study population. The population variance is the average of the sum of the squares of the values of the arithmetic mean in a set of data, and the population standard deviation is the population variance.
Sample variance
VAR(X,N) finds the sample variance of X over the N period.
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is a null value, the function returns a null value;
5、N supports the use of variables
Algorithm example: Calculate VAR(C,3); the value on the nearest K line.
The M language function can be expressed as follows:
(SQUARE(C-MA(C,3))+SQUARE(REF(C,1)-MA(C,3))+SQUARE(REF(C,2)-MA(C,3)))/(3-1);
example：
VAR(C,5) finds the sample variance of the closing price within 5 cycles.
//represents N/(N-1) times the population variance, and VAR(C, 5) represents 5/4 times the variance of the 5-cycle total sample of the closing price.
Overall variance
VARP(X,N): the N-period population variance of X
Note：
1、N contains the current k line.
2、N is a valid value, when the current number of k lines is less than N, the function returns a null value;
3、When N is 0, the function returns a null value;
4、N is a null value, the function returns a null value;
5、N supports the use of variables
Algorithm example: Calculate VARP(C,3); the value on the nearest K line.
The M language function can be expressed as follows:
(SQUARE(C-MA(C,3))+SQUARE(REF(C,1)-MA(C,3))+SQUARE(REF(C,2)-MA(C,3)))/3;
example：
VARP(C,5) is the 5-cycle overall variance of the closing price
//indicates the sum of the square of the data deviation divided by the total number of cycles N, VARP (C, 5) represents the square of the data deviation of the closing price of 5 cycles divided by 5.
Absolute value
ABS (X): The absolute value of X
Note：
1、The absolute value of a positive number is itself;
2、The absolute value of a negative number is its opposite;
3、the absolute value of 0 is still 0;
example 1：
ABS(-10);//return 10.
Example 2：
ABS(CLOSE-10);//return the absolute value of the closing price and the 10 price difference.
Example 3：
ABS(C-O);//current K line entity length
Inverse cosine
ACOS(X)：Returns the inverse cosine of X.
Note：
1、X value range [-1, 1].
2、If X is not in the range of values, the return value is null.
example 1：
ACOS(-1);// find the inverse cosine of -1;
Example 2：
ACOS(1);// find the inverse cosine of 1;
Arc sine
ASIN(X)：Returns the inverse sine of X.
Note：
1、X value range [-1, 1].
2、If X is not in the range of values, the return value is null.
example 1：
ASIN(-1);//find the inverse sine of -1;
Example 2：
ASIN(1);//find the inverse sine of 1;
Inverse tangent
ATAN(X)：Returns the arctangent of X.
Note: The value of X is R (real number set)
example 1：
ATAN(-1.75);//find the inverse tangent of -1.75;
Example 2：
ATAN(1.75);//find the inverse tangent of 1.75;
Round up
CEILING(X,Y) Returns the value of the first real divisible (Y) in the direction along which the absolute value (X) is divisible.
Note：
1、If the X and Y symbols are the same, round the value in a direction away from 0.
2、When the X and Y symbols are different:
（1）If X is negative and Y is positive, the value is rounded up in the direction of 0.
（2）If X is positive and Y is negative, CEILING returns an invalid value.
3、X and Y can both be variables.
4、If any of X and Y is null, the function returns a null value.
example 1：
CEILING(2.1,1);//seeking 3。
Example 2：
CEILING(-8.8,-2);//seeking -10.
Example 3：
CEILING(CLOSE*1.01,1);//to find the closing price of 1.01 times rounded up
Example 4：
CEILING(-7,2);//seeking -6.
Example 5：
CEILING(8,-2);//returns an invalid value.
Cosine
COS(X)：Returns the cosine of X.
Note：
1、the value of X is R (real number set)
2、The value range is [-1, 1]
example 1：
COS(-1.57);//return the cosine of -1.57
Example 2：
COS(1.57);//return the cosine of 1.57
Cubic function
CUBE(X)：Returns the cube of X.
example 1：
CUBE(4);//ask for the cube of 4.
index
EXP(X)：Find the power of e to the power of x
example 1：
C*EXP(0.01);//Find the closing price multiplied by the power of 0.01
Round down
FLOOR(A)：Rounds in the direction of decreasing value.
Note：
FLOOR(A) returns the nearest integer along the direction in which the value of A decreases. If A is an integer, return value is A.
example 1：
FLOOR(2.1);//return value is 2；
example 2：
FLOOR(-8.8);//return value is -9；
example 3：
FLOOR(5);//return value of 5；
example 4：
IFELSE(C-INTPART(C)>=0.5,CEILING(C),FLOOR(C));//Take the integer part after rounding off the closing price.
Rounding
INTPART(X)：Take the integer part of X.
example 1：
INTPART(12.3);//return value is 12;
example 2：
INTPART(-3.5);//return value is -3;
example 3：
INTPART(10);//return value of 10；
example 4：
INTPART(C);//to find the integer part of the closing price.
Natural logarithm
LN(X)：Find the natural logarithm of X.
Note：
1、The value range of X is non-zero natural number, ie 1, 2, 3, 4, 5...
2、If X is 0 or a negative number, the return value is null.
example：
LN(OPEN);// seeking the logarithm of the opening price.
Common logarithm
LOG(X) Find the common logarithm of X
Note：
1、The value of X in this function is X>0.
2、0 and negative numbers have no logarithm. When X is 0 or negative, the return value is null.
example 1：
LOG(100) returns 2.
example 2：
LOG(0) returns a null value。
Maximum
MAX(A,B): Take the maximum value. Take the larger of A and B.
Note：
If A=B, the return value is the value of A or B.
example 1：
MAX(CLOSE,OPEN);//indicates the larger of the opening and closing prices.
Example 2：
MAX(CLOSE-OPEN,0);//means that if the closing price is greater than the opening price to return their difference, otherwise return 0.
Example 3：
MAX(A,MAX(B,MAX(C,D)));//Seeking the maximum value of A B C D
Take the maximum
MAX1(A...P) takes the maximum value from A to P.
Note：
1、Support 2-16 values for comparison.
2、A...P can be either a number or a variable.
example 1：
MAX1(CLOSE,OPEN);//indicates the larger of the opening and closing prices.
example 2：
MAX1(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);// indicates the maximum value in the numbers 1-16.
Find the median
MEDIAN(X,N) finds the value of X in the middle of N cycles.
Note：
1、After all Xs are sorted in N cycles, if N is an odd number, then the (N+1)/2th is selected as the median. If N is even, the median is (N/2 and N/2).
2、N can be a variable.
example 1：
The closing price of soybean meal 1509 on the last 3 days is 2727, 2754, 2748, then the return value of current MEDIAN (C, 3) is 2748.
example 2：
The opening price of soybean meal 1509 on the last 4 days was 2752, 2743, 2730, 2728, then the current return value of MEDIAN (O, 4) is 2736.5
Find the median
MEDIAN1(A,...,P) Find the value in the middle of A to P.
Note：
1、Support up to 16 parameters for calculation.
2、A...P can be either a numeric value or a variable.
3、If the number of parameters is N, after sorting N parameters, N is an odd number, then the (N+1)/2 is selected as the median, and if N is even, the median is (N/2) And the average of (N/2+1).
example 1:
AA:=MEDIAN1(O,C,H);//Opening price, closing price, highest price are sorted by value, taking the median value.
example 2：
BB:=MEDIAN1(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);//indicates the median of the numbers 1-16 , BB returns 8.5
Minimum value
MIN(A,B)：Take the minimum value. Take the smaller of A and B
Note：
If A=B, the return value is the value of A or B.
example 1：
MIN(OPEN,CLOSE);//indicates the smaller of the opening and closing prices.
example 2：
MIN(C,MIN(O,REF(C,1)));//Find the opening price of the current period, the closing price, and the minimum value between the closing prices of the previous period.
Take the minimum
MIN1(A...P) takes the minimum value from A to P.
Note：
1、Support 2-16 values for comparison.
2、A...P can be either a number or a variable.
example 1：
MIN1(CLOSE,OPEN);//indicates the smaller of the opening and closing prices.
example 2：
MIN1(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);//indicates the minimum value in the numbers 1-16。
Molding
MOD(A,B)：modulo. Return A to B for modulo。
example 1：
MOD(26,10);//return 6, 26 divided by 10, the remainder is 6, that is, the modulus of 26 to 10 is 6.
example 2：
MOD(A,2)=0;//judge if A is an even number.
Seeking the majority
MODE(X,N) finds the most frequently occurring value of X in N cycles.
Note：
1、If there are no repeated values in N cycles, the function returns a null value.
2、N can be a variable.
power
POW(X,Y)：Find the X power of Y.
Note：
1、When X is a negative number, Y must be an integer. Because the base is negative, the square root operation cannot be performed, and the return value is null.
2、X, Y can be numeric or variable.
example 1：
POW(CLOSE,2);//Get the closing price of the 2nd power.
example 2：
POW(10,2);//The return value is 100
Example 3：
POW(1/2,-2);//return value is 4
例4：
POW(100,O-C);//return 100 O-C power
Random function that generates random numbers
RAND(X,Y) Generates a random function of random numbers and returns a random number between X and Y.
Note：
1、The X and Y parameters are all supported as variables.
2、the function only supports return integers
3、When X>Y, the function returns a null value.
4、When the range of X and Y is less than 1, the function returns an invalid value.
example 1：
RAND(1,60);//return a random number between 1 and 60
例2：
RAND(C,O);//Return the random value between the closing price and the opening price
range
RANGE(X,Y,Z)：Within a certain range. Returns 1 if X is greater than Y and less than Z, otherwise returns 0
example 1：
RANGE(5,4,6);//return value is 1;
Example 2：
RANGE(8,3,6);//return value is 0;
Example 3：
MA5:=MA(C,5);
MA10:=MA(C,10);
MA20:=MA(C,20);
RANGE(MA10,MA20,MA5),BK;//10 cycle moving average between the 5-period moving average and the 20-period moving average to open the position
//RANGE (MA10, MA20, MA5) = 1, BK; and RANGE (MA10, MA20, MA5), BK; expression of the same meaning
Opposite value
REVERSE(X)：Take the opposite value and return -X.
example 1：
REVERSE(LOW);//return - LOW。
example 2：
REVERSE(-55);//return value is 55
example 3：
REVERSE(0);//return value is 0
The specified number of digits is rounded off
ROUND(N,M) Rounds the number N by the number of M digits.
Note：
1、N supports writing as variables and parameters; M does not support writing as variables and can be written as parameters.
2、If M>0, the M digits after the decimal point are rounded off.
3、If M=0, the number N is rounded to an integer.
4、If M<0, the first M digits on the left side of the decimal point of the number N are rounded off.
example 1：
ROUND(125.345,2);//return 125.35.
example 2：
ROUND(125.345,0);//returns to 125.
example 3：
ROUND(125.345,-1);//return 130
Taking positive or negative symbol
SGN (X): Take the “+/-” symbol. If X>0 returns 1, if X<0 returns -1, otherwise it returns 0.
example 1：
SGN(5);//return value is 1
example 2：
SGN(-5);//return value is -1
example 3：
SGN(0);//return value is 0
Sine
SIN(X)：Find the sine of X.
Note：
1、The value of X is R (real number set);
2、The value range is (-1, 1).
example 1：
SIN(-1.57);//returns the sine of -1.57
example 2：
SIN(1.57);//returns the sine of -1.57
Square root
SQRT(X)：Find the square root of X.
Note：
The value of X is a positive number, and when X is a negative number, it returns a null value.
example 1：
SQRT(CLOSE);//square root of the closing price.
square
SQUARE(X) finds the square of X.
example 1：
SQUARE(C);//The square of the closing price.
example 2：
SQUARE(2);//The square of 2.
Tangent
TAN(X)：Returns the tangent of X.
example 1：
TAN(0);//returns the tangent of 0;
example 2：
TAN(-3.14);//return the tangent value of -3.14.
BK
BK buy long
BP
buy to cover (close the short position)
SK
sell short
SP
sell (close the long position)
BPK
Open a new buying long position after sell (SP)
SPK
Open a new selling short position after buy to cover (BP)
CLOSEOUT
Close all position, no matter the long or short position
SELECT
SELECT formula stock picking
TRADE_AGAIN(N)
，in the addition and subtraction model with this function, the same command line can continuously output N signals
AUTOFILTER
，enables one open position and one close position signal filtering mechanism.
MULTSIG(Sec1, Sec2, N)
，set a k-line multi-signal command price method (TICK one-by-one backtest, you can set the backtest accuracy)
The opening position signal is sent out in Sec1 seconds, and no review is made;
The closing position signal is sent out in Sec2 seconds, and no review is made;
FILTER(COND,N) filters successively occurring signals When the COND condition is met, the data in the next N cycles returns 0.
E.g:
a:=FILTER(CLOSE>OPEN, 3) // Find the rising line, and the rising line that appears again within 3 cycles is not recorded.
Note: Cannot be used with BKPRICE, BARSBK, SKPRICE, BARSSK.
Enable one open position and one close position signal filtering mechanism
AUTOFILTER Enables an open position and close position signal filtering mechanism.
usage：
The model contains the AUTOFILTER function, which enables an open-and-close signal filtering mechanism.
If the function is not written in the model, each instruction is valid and supports adding and subtracting positions.
Model filtering rules:
1、The consecutive same direction instructions are only valid for the first one, and the others will be filtered;
2、The trading order must be opening position first then closing position, and the opening and closing must appear as a pair:
When the BK instruction appears, and the next instruction only allows the SP\SPK instruction to appear;
When the SK instruction appears, and the next instruction only allows the BP\BPK instruction to appear;
When there is a closing position instruction such as SP/BP/CLOSEOUT, and the next one can be any one of BK/SK/SPK/BPK instructions;
The reverse instruction SPK and BPK appear crosswise.
example：
CLOSE>OPEN,BK;
CLOSE<OPEN,SP;
AUTOFILTER; //Enable one open position and one close position signal filtering mechanism
Limit signal function
TRADE_AGAIN(N) N signals can be output continuously on the same command line.
usage:
TRADE_AGAIN(N) In the addition and subtraction position model with this function, N signals can be output continuously from the same command line.
Note：
1、the function is only applicable to the addition and subtraction position model
2、Write the function in the model. one K line only supports one signal. Cannot be used with the MULTSIG function.
3、N signals must be executed continuously. If other signals appear during the period, N is recalculated.
4、N cannot be written as a variable.
example：
C>O,BK(1);//K line is the rising line, buy long 1 hand
C<O,SP(BKVOL);//K line is a falling line, sell the long position to close the position
TRADE_AGAIN(3);//The same command line can be executed 3 times in a row (if three consecutive rising lines, three consecutive long positions are opened)
Return the data contract of the last buy signal price
BKPRICE returns the price of the last buying signal of the data contract.
usage:
BKPRICE returns the latest price of the market when the data was last issued.
Note：
1、When the data contract and the transaction contract are the same, the BKPRICE value is equal to the BKPRICE1 value.
2、When there are multiple open positions (adding positions) in the model, the function returns the price of the last open signal, not the average price of the open position.
3、Different signal execution modes, the return values are:
（1）Signal execution mode is not signal review
Historical backtest: BKPRICE return signal when the data contract price is the latest price
（2）Signal execution mode selection K line completion confirmation signal order
Historical backtest: BKPRICE return signal when the data contract is the closing price of the current K line
（3）Signal execution mode is set to K line to complete signal review
Historical backtest: BKPRICE return signal when the data contract is the closing price of the current K line
example:
BKPRICE-CLOSE>60 && BKPRICE>0 && BKVOL>0, SP; //If the buy price is 60 higher than the current price, and the long position exists, sell the position (closing position).
Return data contract long position average price
BKPRICEAV returns the average price of long position for data contracts.
usage：
BKPRICEAV returns the average price of long position for data contracts.
Note：
1、One opening position and one closing position signal filtering model:
（1） After the opening position signal is issued, when the closing signal is not issued: the value of BKPRICEAV is the same as the value of BKPRICE.
（2） After closing position signal: BKPRICEAV returns a value of 0.
2、Adding and subtracting position models:
（1）When the position is not 0: BKPRICEAV returns the average price of the opening position of the data contract (theoretically).
（2）When the adding or subtracting position model is 0: BKPRICEAV returns 0.。
Note：
The calculation of this function takes into account the slippage of price.
example：
CLOSE-BKPRICEAV>60,SP(BKVOL);//The current price is 60 higher than the average price of the long position, and all the long positions are closed.
Buy long opening position signal
Buy long opening position signal lot
usage：
BKVOL returns the current theoretical long position of the model.
1、loading and running：
（1）During the backtesting system operation, BKVOL is not subject to the restriction of funds, and the number of open positions is displayed according to the signal.
2、In the back test run：
（1）If the funds are not enough to open the position, the open lot size is 0, and the BKVOL return value is 0.
（2）After the BK (BPK) signal appears and the signal is confirmed, the value of BKVOL increases the value of the number of opening positions; after the SP (SPK) signal appears and the signal is confirmed, the value of BKVOL decreases the value of the number of closing positions.
example：
BKVOL=0&&C>O,BK(1);//The theoretical long position is 0 and the closing price is greater than the opening price, buy long 1 hand
BKVOL>=1&&H>HV(H,5),BK(2); //The long position is greater than or equal to 1, and when the highest price of the current K line is greater than the highest of the previous 5 periods, 2 positions are added.
BKVOL>0&&L<REF(L,5),SP(BKVOL); //The long position is greater than 0, and when the lowest price of current K line is less than the lowest price of the K line of the previous 5 periods, sell all long positions (close position)
Return the highest price since the data contract bought long (opened a long position)
Return the highest price since the data contract was bought (opened a long position)
usage：
BKHIGH returns the highest price of the most recent model opened long position to the current.
1、Different signal execution modes, the return values are:
（1）Signal execution mode is to order the K line to confirm the signal
a.In the historical signal calculation, the K line after the BK (BPK) signal returns the highest price of the data contract quote since the order sent.
b.During the loading operation, the BK (BPK) signal returns the latest price of the data contract quote when the signal is sent from the current K line, and the highest price of the data contract quote since the K line after the BK is returned.
The highest price of the statistical contract market is started when the BK (BPK) signal is sent; when the signal disappears, and the highest price of the data contract quote since the last purchase is returned. The signal confirms the existence and returns the highest data contract price recorded as the current K line.
Note: After the BK signal is sent, the signal disappears in the middle, and the highest price of the statistical contract starts from the last signal.
（3）Signal execution mode selection does not perform signal review (for example: writing MULTSIG in the model)
The current K line of the BK (BPK) signal returns the highest price of the data contract from the signal to the K line; the highest price of the data contract since the K line return signal after the BK (BPK) signal.
example：
C>O,BK;
C>BKPRICE&&C<BKHIGH-5,SP;
AUTOFILTER;//The latest price is lower than the highest price of the data contract since the buying long of the open position 5 points, take profit and close the position.
Returns the lowest price since the data contract was bought (opened a long position).
Returns the lowest price since the data contract was bought (opened a long position).
usage：
BKLOW returns the data model's most recent model buy position to the current lowest price.
1、Different signal execution modes, the return values are:
（1）The K line goes through the confirmation signal to place an order
a.In the historical signal calculation, the K line after the BK (BPK) signal returns the lowest price of the data contract quote since the commission
b.During the loading operation, the BK (BPK) signal returns the latest price of the data contract quote when the signal is sent from the root K line, and the lowest price of the data contract quote since the K line after the BK is returned.
When the BK (BPK) signal is sent, the lowest price of the statistical contract market is started; the signal disappears, and the lowest price of the data contract quote since the last purchase is returned. The signal confirms the existence and returns the data contract price recorded as the root K line.
Note: After the BK signal is sent, the signal disappears in the middle, and the lowest price of the statistical contract starts from the last signal.
（3）Signal execution mode selection does not perform signal review (for example: writing MULTSIG in the model)
The lowest price of the data contract quote when the BK (BPK) signal returns from the signal to the K line when the K line returns; the lowest price of the data contract quote since the K line return signal after the BK (BPK) signal.
example：
C>O,BK;
C>BKLOW+5,SP;
AUTOFILTER;//The latest price is higher than the lowest price of the data contract since buying long position 5 points, close the position.
Returns the latest price of the data contract that selling short
SKPRICE returns the price of the most recent sell short signal for the data contract.
usage：
SKPRICE returns the latest price of the market quotes when the last selling short signal was issued.
Note：
1、The SKPRICE value is equal to the SKPRICE1 value when the data contract and the trading contract are the same.
2、When there are multiple open positions (adding positions) signal in the model, the function returns the price of the last opening position signal, not the average price of the opening position.
3、Different signal execution modes, the return values are:
（1）Signal execution mode is not signal review
a.Historical backtest: the latest price of the data contract quote when the SKPRICE return signal is sent
（2）Signal execution mode selection K line completion confirmation signal order
a.Historical backtest: the closing price of the data contract when the SKPRICE return signal is issued as the current K line
（3）Signal execution mode is set to K-line to complete signal review
a.Historical backtest: the closing price of the data contract when the SKPRICE return signal is issued as the current K line
example:
CLOSE-SKPRICE>60 && SKPRICE>0 && SKVOL>0, BP; //If the selling price is 60 lower than the current price, and the short position exists, buy to cover. (close the position)
Return data contract short position average price
SKPRICEAV returns the average price of open contracts for data contracts.
usage：
SKPRICEAV returns the average price of the open contract for the return data contract.
Note：
1、One open and close position signal filtering model:
（1）When the opening signal is issued, the closing signal doesn’t appear, the SKPRICEAV value is the same as the SKPRICE value.
（2）After the closing signal is appeared: SKPRICEAV returns 0.
2、Add and subtract position models:
（1）When the position is not 0: SKPRICEAV returns the average price of the opening position of the data contract (theoretically).
（2）When the plus or minus position model position is 0: SKPRICEAV returns 0.
Note：
The calculation of this function takes into account the slippage of price.
example：
SKPRICEAV-CLOSE>60, BP(SKVOL);//The current price is 60 lower than the average price of short positions, closing all short positions
Selling short open position signal lot
Selling short open position signal lot
usage：
SKVOL returns the model's current short position theoretical position.
1、loading and running：
（1）During the operation of the backtesting system, SKVOL is not subject to the restriction of funds, and the number of open positions is displayed according to the signal.
2、In the backtest run:
（1）If the funds are not enough to open the position, the number of open positions is 0, and the return value of SKVOL is 0.
（2）After the SK (SPK) signal appears and signal is confirmed, the value of SKVOL increases the value of the number of opening positions; after the BP (BPK) signal appears and the signal is confirmed, the value of SKVOL is reduced by the number of the closing positions.
example：
SKVOL=0&&C<O,SK(1);//when the short position is 0 and the closing price is less than the opening price, sell short 1 hand.
SKVOL>=1&&L<LV(L,5),SK(2); //The short position is greater than or equal to 1, and when the lowest price of the root K line is less than the lowest of the lowest of the previous 5 periods, the 2 positions are added.
SKVOL>0&&H>REF(H,5),BP(SKVOL); //The short position is greater than 0, and when the highest price of the K line is greater than the highest price of the K line of pervious 5 cycles, buy to cover all short positions (close all short position)
Returns the highest price since the data contract was short sell (opened a short position)
Returns the highest price since the data contract was short sell (opened a short position)
usage：
SKHIGH returns the data contract the most recent model sell short position to the current highest price.
1、Different signal execution modes, the return values are:
（1）The K line goes through the confirmation signal to place an order
a.In the historical signal calculation, the K line after the SK (SPK) signal returns the highest price of the data contract quote since the order sent
b.During the loading operation, the SK (SPK) signal returns the latest price of the data contract when the signal is sent from the current K line, and the highest price of the data contract quoted since the K line after the SK returns.
The highest price of the statistical contract market is started when the SK (SPK) signal is sent; when the signal disappears, the highest price of the data contract quote since the last sale is returned. The signal confirms the existence and returns the highest data contract price recorded as the current K line.
Note: After the SK signal is sent, the signal disappears in the middle, and the highest price of the statistical contract starts from the last signal.
（3）Signal execution mode selection does not perform signal review (for example: writing MULTSIG in the model)
The highest price of the data contract market when the SK (SPK) signal returns from the signal to the K line when the K line returns; the highest price of the data contract since the K line return signal after the SK (SPK) signal.
example：
C<O,SK;
C<SKHIGH-5,BP;
AUTOFILTER;//The latest price is lower than the highest price of the data contract since the sale of open positions 5 points, close the position.
Returns the lowest price since the data contract was selling short (opened a short position)
Returns the lowest price since the data contract was selling short (opened a short position)
usage：
SKLOW returns the data contract last time the model was selling short to the current lowest price.
1、Different signal execution modes, the return values are:
（1）The K line goes through the confirmation signal to place an order
a.In the historical signal calculation, the K line after the SK (SPK) signal returns the lowest price of the data contract quote since the order sent
b.During the loading operation, the SK (SPK) signal returns the latest price of the data contract quote when the signal is sent from the current K line, and the lowest price of the data contract quote since the return of the SK line after the SK line.
When the signal is sent, the lowest price of the statistics contract is started. The signal disappears and returns the lowest price of the data contract since the last sale. The signal confirms the existence and returns the lowest price of the data contract quoted by the K-line.
Note: After the SK signal is sent, the signal disappears in the middle, and the lowest price of the statistical contract starts from the last signal.
（3）Signal execution mode selection does not perform signal review (for example: writing MULTSIG in the model) The lowest price of the data contract market when the SK (SPK) signal returns from the signal to the K line when the K line returns; the lowest price of the data contract after the K line return signal after the SK (SPK) signal
example：
C<O,SK;
C<SKPRICE&&C>SKLOW+5,BP;
AUTOFILTER;//The latest price is higher than the lowest price of the data contract since the sale of open positions 5 points, stop profit and close the position.
Determine if the previous signal is BK
ISLASTBK determines if the last trading signal is BK.
usage：
ISLASTBK returns 1 (Yes) when the previous trading signal is BK, otherwise returns 0 (No)
ISLASTBK returns a value of 0 when the BK signal is not acknowledged;
ISLASTBK returns 1 after the BK signal is confirmed
b.Signal execution mode selection does not perform signal review (for example: writing MULTISIG in the model), BK signal returns the value as current ISLASTBK
Note: When the model contains BPK conditions, and the previous signal is the close position signal, the BK signal generated by the BPK instruction, ISLASTBK returns 0, and ISLASTBPK returns 1.
example:
C>O,BK;
ISLASTBK&&C>BKPRICE,SP;
AUTOFILTER;//The last signal is the BK signal, and the latest price is greater than the opening price, selling the position (close position)
Determine if the last signal is SK
ISLASTSK determines if the last trading signal is SK.
usage：
ISLASTSK returns 1 (Yes) when the last trading signal is SK, otherwise returns 0 (No)
ISLASTSK returns a value of 0 when the SK signal is not acknowledged;
ISLASTSK returns 1 after SK signal is confirmed
b.Signal execution mode selection does not perform signal review (for example: writing MULTISIG in the model), SK signal when the current ISLASTSK returns a value of 1
Note: When the model contains SPK conditions, and the previous signal is the close position signal, the SK signal generated by the SPK instruction, ISLASTSK returns 0, ISLASTSPK returns 1.
example:
C<O,SK;
ISLASTSK&&C<SKPRICE,BP;
AUTOFILTER;//the last signal is SK signal, and the latest price is less than the opening price, buy to cover (close position)
Determine if the previous signal is BP
ISLASTBP determines if the last trading signal is BP.
usage：
ISLASTBP returns 1 (Yes) when the last trading signal is BP, otherwise returns 0 (No)
ISLASTBP returns a value of 0 when the BP signal is not acknowledged;
After the BP signal is confirmed, ISLASTBP returns 1
b.The signal execution mode is selected without signal review for example: writing MULTISIG in the model), and the BP signal returns a value of 1 when the current ISLASTBP returns
example:
C<O,SK(2);
C>O,BP(1);
ISLASTBP,BP(1);//The last signal is to buy to cover signal (close position), then subtract 1 hand position.
Determine if the previous signal is SP
ISLASTSP determines if the last trading signal is an SP.
usage：
ISLASTSP returns 1 (Yes) when the previous trading signal is SP, otherwise returns 0 (No)
ISLASTSP returns a value of 0 when the SP signal is not acknowledged;
ISLASTSP returns 1 after the SP signal is confirmed
b.The signal execution mode is selected without signal review (for example: writing MULTISIG in the model), and the SP signal returns a value of 1 when the current ISLASTSP returns
example:
C>O,BK(2);
C<O,SP(1);
ISLASTSP,SP(1);//the last signal is the closing position signal, subtract 1 hand position
Determine if the previous signal is BPK
ISLASTBPK determines if the last trading signal is BPK.
usage：
ISLASTBPK returns a 1 (Yes) on BPV, but returns 0 (No)
ISLASTBPK returns a value of 0 when the BPK signal is not acknowledged;
After the BPK signal is confirmed, ISLASTBPK returns 1
b.Signal execution mode selection does not perform signal review (for example: writing MULTISIG in the model), BPK signal returns the value as current ISLASTBPK
Note: When the model contains BPK conditions, and the previous signal is the close position signal, the BK signal generated by the BPK instruction, ISLASTBK returns 0, and ISLASTBPK returns 1.
example:
C>O,BPK;
ISLASTBPK&&C<O,SPK;
AUTOFILTER;//the last signal is BPK signal, then reverse SPK
Determine if the previous signal is SPK
ISLASTSPK determines if the last trading signal is SPK.
usage：
The last trading signal of ISLASTSPK is 1 (Yes) for SPK, otherwise it returns 0 (No)
ISLASTSPK returns a value of 0 when the SPK signal is not acknowledged;
ISLASTSPK returns 1 after SPK signal is confirmed
b.Signal execution mode selection does not perform signal review (for example: writing MULTISIG in the model), SPK signal when the current ISLASTSPK returns a value of 1
Note: When the model contains SPK conditions, and the previous signal is the close position signal, the SK signal generated by the SPK instruction, ISLASTSK returns 0, ISLASTSPK returns 1.
example:
C<O,SPK;
ISLASTSPK&&C>O,BPK;
AUTOFILTER;//the last signal is SPK signal, then reverse BPK
Determine if the previous signal is STOP
ISLASTSTOP determines if the last trading signal is STOP.
usage：
ISLASTSTOP returns 1 (Yes) when the last trading signal is STOP, otherwise returns 0 (No)
Note: The closing price model STOP signal has a return value of 1 for the K-line ISLASTSTOP; the command price model STOP signal returns 1 for the current K-line ISLASTSTOP.
example:
CROSS(C,MA(C,5)),BK(2);
STOP(0,5);
ISLASTSTOP&&CROSS(C,MA(C,10)), BK(1);//The last signal is the STOP signal, and the price up cross the 10-cycle moving average line, opening a position(1 hand)
Determine if the previous signal is CLOSEOUT
ISLASTCLOSEOUT determines if the previous signal is CLOSEOUT.
usage：
ISLASTCLOSEOUT The last trading signal is CLOSEOUT returns 1 (Yes), otherwise it returns 0 (No)
ISLASTCLOSEOUT returns a value of 0 when the CLOSEOUT signal is not acknowledged;
ISLASTCLOSEOUT returns 1 after the CLOSEOUT signal is acknowledged
b. Signal execution mode selection does not perform signal review (for example: write MULTIC in the model), CLOSEOUT signal when the current ISLASTCLOSEOUT returns a value of 1
example:
ISLASTCLOSEOUT&&C>O, BK(1);//The last signal is the clearance signal, and when the current K line is the rising line, buy long 1 hand
The last buy long signal location
BARSBK last buy long signal location
usage：
BARSBK returns the number of cycles of the K line from the last buying long location to the current K line (excluding the K line where the BK signal appears)
To take the number of cycles from the K line that appears in the BK signal to the current K line, you need to +1 after this function, that is, BARSBK+1; since the current k line of the BK signal returns the null value, the BARSBK+1 When the BK signal is sent, the current k line returns a null value.
Note：
1、If there is no BK signal before the current K line, the function return value is null.
2、After the BK signal is confirmed, BARSBK returns a null value.
（1）Set the signal execution mode to order the K line to confirm the signal
The BARSBK return value is the number of the current K line from the previous BK signal (including the current K line)
（2）Set the signal execution mode to immediately place an order for the outgoing signal, without reviewing (for example, writing MULTSIG in the model)
a.In the historical signal calculation, the current K line of the BK signal appears, and the BARSBK returns a null value.
b.During the loading operation, BARSBK returns a null value after the signal is confirmed.
The BARSBK return value is the number of the current K line from the previous BK signal (including the current K line)
example：
1、BARSBK>10, SP; / / last time of buying long open positions (not including the K line that appears to the opening position signal) from the current K line cycle number is greater than 10, closing position;
2、HHV (H, BARSBK + 1); / / last time to selling short open positions (including the opening of the signal appears as the current k line) to the current maximum price.
When the BK signal appears on the current K line, AA returns a null value, and needs to return the highest price on the current K line. The model needs to be modified to:
AA:=IFELSE(BARSBK>=1,HHV(H,BARSBK+1),H);
（1）When the BK signal appears on the current K line, the BARSBK returns a null value, and if the condition of BARSBK>=1 is not satisfied, the value is the highest price of the current K line.
（2）After the BK signal is sent, the K line BARSBK returns the number of cycles of the K line of the open position from the current K line. If the condition of BARSBK>=1 is satisfied, the value is HHV(H, BARSBK+1), that is, the open position is buying long. (Includes the current k line that appears when the opening signal appears) to the current maximum price.
After the modification, if the value of AA is used in the closing position condition, when the current K line satisfies the closing position condition, the closing signal may appear.
3、AA:=IFELSE(BARSBK>=1,REF(C,BARSBK),C);//take the latest buying long position of the K-line closing price
（1）When the current k-line BARSBK of the BK signal returns a null value, when the current K-line does not satisfy the condition of BARSBK>=1, AA returns the closing price of the current k-line;
（2）After the BK signal is sent, the k line BARSBK returns the number of cycles of the K line of the open position from the current K line, then AA returns REF (C, BARSBK), that is, the closing price of the opened position k line;
（3）Example: 1, k2, 3, 3, k line, 1 K line is the current k line of the opening signal, then return the closing price of the current k line, 2, 3 K line AA return value is 1 K line Closing price.
Last selling short signal location
BARSSK last selling short signal location
usage:
BARSSK returns the number of cycles from the K line of the last sell short open position to the current K line (excluding the K line where the SK signal appears)
Take the number of cycles from the K line that appears in the SK signal to the current K line, which needs to be +1 after this function, that is, BARSSK+1; since the current k line BARSSK that sends the SK signal returns a null value, BARSSK+1 is The SK signal is sent when the current k line returns a null value.
Note:
1. If there is no SK signal before the current K line, the function return value is null.
2. After the SK signal is confirmed, BARSSK returns a null value.
(1) Set the signal execution mode to order the K line to confirm the signal
The BARSSK return value is the number of the current K line from the previous SK signal (including the current K line)
(2) Set the signal execution mode to immediately place an order for the outgoing signal, without reviewing (for example, writing MULTSIG in the model)
a. In the historical signal calculation, the SK signal appears as the current K line, BARSSK returns a null value
b. During the loading operation, the SK signal is the current K line, and the BARSKK returns a null value after the signal is confirmed.
The BARSSK return value is the number of the current K line from the previous SK signal (including the current K line)
example:
1, BARSSK>10, BP; / / last selling short open position (excluding the K line that appears to buy long signal) from the current K line cycle number is greater than 10, close position;
2, LLV (L, BARSSK + 1); / / last selling short position (including the opening k signal appears as the current k line) to the current minimum price.
When the SK signal appears on the current K line, AA returns a null value. If it is necessary to return the lowest price on the current K line, the model needs to be modified to:
AA:=IFELSE(BARSSK>=1, LLV(L, BARSSK+1), L);
(1) When the SK signal appears on the current K line, BARSSK returns a null value. If the condition of BARSSK>=1 is not satisfied, the value is the lowest price of the current K line.
(2) After the SK signal is sent, the K line SARSK returns the number of cycles of the K line that selling short position from the current K line. If the condition of BARSSK>=1 is satisfied, the value is LLV (L, BARSSK+1), that is, the selling short position (including the current k line that appears when the opening position signal appears) to the minimum value of the current lowest price.
After the modification, if the value of AA is used in the closing position condition, when the root K line satisfies the closing condition, the closing position signal may appear.
3, AA: = IFELSE (BARSSK> = 1, REF (C, BARSSK), C); / / take the closing price of the last selling short K line
(1) When the current k-line BARSSK of the SK signal returns a null value, when the current K line does not satisfy the condition of BARSSK>=1, AA returns the closing price of the current k-line;
(2) After the SK signal is sent, the k line BARSSK returns the number of cycles of the K line of the open position from the current K line, then AA returns REF (C, BARSSK), that is, the closing price of the opened k line;
(3) Example: 1, 2, 3 k line, 1 K line is the current k line of the opening signal, then return the closing price of the current k line, 2, 3K line AA return value is the closing price of 1K line.
Last sell to close position location
BARSSP last sell to close position location
usage：
BARSSP returns the number of cycles of the last K line that was selling short from the current K line (excluding the K line where the SP signal appears)
To take the number of cycles from the K line that appears in the SP signal to the current K line, you need to +1 after this function, that is, BARSSP+1. Since the current k-line BARSSP of the SP signal returns a null value, BARSSP+1 is issuing the SP signal when the current k line returns a null value.
Note：
1、If there is no SP signal before the current K line, the function return value is null.
2、After the SP signal is confirmed, BARSSP returns a null value.
（1）Set the signal execution mode to order the K line to confirm the signal
The BARSBP return value is the number of the current K line from the previous BP signal (including the current K line)
（2）Set the signal execution mode to immediately place an order for the outgoing signal, without reviewing (for example, writing MULTSIG in the model)
a.In the historical signal calculation, the SP signal appears as the current K line, and the BARSSP returns a null value.
b.During the loading process, when the signal is confirmed, the BARSSP returns a null value.
The BARSSP return value is the number of the current K line from the previous SP signal (including the current K line)
example：
1、BARSSP>10, BK; / / last selling short close position (not including the K line that appears closing position signal) from the current K line cycle number is greater than 10, buy long.
2、AA: = HHV (H, BARSSP + 1); / / Last time, the sell short of the closing position (including the current k line appearing in the closing signal) to the current maximum price maximum.
When the SP signal appears on the current K line, AA returns a null value. If it is necessary to return the highest price on the current K line, the model needs to be modified to:
AA:=IFELSE(BARSSP>=1,HHV(H,BARSSP+1),H);
（1）When the SP signal appears on the current K line, the BARSSP returns a null value, and if the condition of BARSSP>=1 is not satisfied, the value is the highest price of the current K line.
（2）After the SP signal is sent, the K-line BARSSP returns the number of cycles of the K-line of the buy long position from the current K-line. If the condition of BARSSP>=1 is satisfied, the value is HHV(H, BARSSP+1), that is, the sale is closed. (including the root k line appearing when the closing signal appears) to the maximum value of the current highest price.
3、AA:=IFELSE(BARSSP>=1,REF(C,BARSSP),C);//take the closing price of the last sale of closed K-line
（1）When the current signal of the SP signal returns the null value, the current K line does not satisfy the condition of BARSSP>=1, and AA returns the closing price of the current k line;
（2）After the SP signal is sent, the k line BARSSP returns the number of cycles of the K line of the selling position from the current K line, then AA returns REF (C, BARSSP), that is, the closing price of the closing k line;
（3）1, 2, 3 k line, 1 K line is the current k line of the closing position signal, then return the closing price of the current k line, 2, 3 K line AA return value is the closing price of 1 K line
Last time buy to cover signal location.
BARSBP last time buy to cover signal location
usage：
BARSBP returns the number of cycles from the last K line of the last buy to cover position to the current K line (excluding the K line where the BP signal appears)
To take the number of cycles from the K line that appears in the BP signal to the current K line, you need to +1 after this function, that is, BARSBP+1. Since the current k-line BARSBP of the BP signal returns a null value, BARSBP+1 is issuing a BP signal when the current k line returns a null value.
Note：
1、If there is no BP signal before the current K line, the function return value is null.
2、BARSBP returns a null value after the BP signal is confirmed.
（1）Set the signal execution mode to order the K line to confirm the signal
The BARSBP return value is the number of the current K line from the previous BP signal (including the current K line)
（2）Set the signal execution mode to immediately place an order for the outgoing signal, without reviewing (for example, writing MULTSIG in the model)
a. In the historical signal calculation, the BP signal appears as the current K line, and the BARSBP returns a null value.
b.During the loading operation, the BP signal is current at the K line, and the BARSBP returns a null value after the signal is confirmed.
The BARSBP return value is the number of the current K line from the previous BP signal (including the current K line)
example：
1、BARSBP>10,BK;//last time to buy to cover a position (not including the K line that appears to buy to cover signal) from the current K line cycle number is greater than 10, buy long.
2、AA:=HHV(H,BARSBP+1);//last time to buy to cover a position (including the current k line appear when the closing signal appears) to the current maximum price.
When the BP signal appears on the current K line, AA returns a null value. If it is necessary to return the highest price on the current K line, the model needs to be modified to:
AA:=IFELSE(BARSBP>=1,HHV(H,BARSBP+1),H);
（1）When the BP signal appears on the current K line, the BARSBP returns a null value, and if the condition of BARSBP>=1 is not satisfied, the value is the highest price of the current K line.
（2）After the BP signal is sent, the K-line BARSBP returns the number of cycles of the K-line of the buy long position from the current K-line. If the condition of BARSBP>=1 is satisfied, the value is HHV(H, BARSBP+1), that is, the long position is closed. (including the current k line appearing when the closing signal appears) to the maximum value of the current highest price.
3、AA:=IFELSE(BARSBP>=1,REF(C,BARSBP),C);//take the closing price of the last buy to cover closing position K line
（1）When the current k-line BARSBP of the BP signal returns a null value, when the current K line does not satisfy the condition of BARSBP>=1, AA returns the closing price of the current k-line;
（2）After the BP signal is sent, the k-line BARSBP returns the number of cycles of the K-line of the buy long position from the current K-line, then AA returns REF(C, BARSBP), that is, the closing price of the closed k-line;
（3）Example: 1, 2, 3 k line, 1 K line is the current k line of the closing signal, then return the closing price of the current k line, 2, 3 K line AA return value is 1 K line Closing price.
Get the number of sent orders
MYVOL Get the number of sent orders
Usage: Get the number of sent orders, which is used to calculate the lot size when loading the model, which include adding or subtracting positions.
Note：
Backtest: return the number of lots number in the backtest parameter
example：
//When the number of orders in the loading parameters is set to 3, the number of orders for writing BK is 6;
C>O,BK(2*MYVOL);
C<O,SP(BKVOL);
Account available funds
MONEY account available funds
Usage: MONEY returns the funds available for the account, used for calculation of positions, lots, etc.
Calculation method:
1. The initial value of MONEY in the account is the starting capital set in the margin parameter.
2. The initial value of MONEY in the historical backtest is the initial capital set in the backtest parameter.
3. Open the position signal as the MONEY value of the current k line: available funds before opening the position - position margin – commission fee, where position margin = opening price * margin ratio * trading unit * lot
4. MONEY value of the k line that has not been closed after opening the position = MONEY value of the k line before the opening signal + floating profit and loss PROFIT
5. The MONEY value of the closing signal as the current k line: the available funds before closing the position + the closing profit and loss + the margin released by the closing position - the commission fee, wherein the margin released by the closing position = the opening price * the margin ratio * the trading unit * the number of lots
Note:
1. The signal execution mode is: ‘K line is finished confirming the order’ or ‘XX is placed, K line is finished reviewing’:
a. Open the signal as the current K line, MONEY return value is the available funds of the upper current K line - open margin – commission fee.
b. The closing signal is the current K line, the MONEY return value is the available capital of the upper K line + the closing profit and loss + the margin released by the position - the commission fee.
2. Signal execution mode selection, ‘Outgoing signal is placed, no review is performed’:
a. Opening the signal When the current K line, the MONEY return value is the available funds before the opening of the k-line - opening margin – commission fee.
b. The closing signal is the current K line, and the MONEY return value is the available funds before the closing of the K line and the closing profit/loss of the closing position + the margin for releasing the position.
3. When the signal execution mode is ‘K line completes the confirmation signal to place an order’, the closing profit and loss = (closing price as the closing price of the K-line closing price - opening price) * lot number * trading unit - handling fee.
4. The signal execution mode is ‘When the signal is placed immediately, no review is made, the profit and loss of the position is closed==the order price of the closing signal-opening price*the number of lots* the trading unit-commission fee.
5. After the account is initialized, the MONEY return value is the available funds in the initialization box.
example:
K:=MONEY0.2/(CMARGIN*UNIT+FEE); // 20% of the funds available for the account can be opened (this is the same as the contract for a fixed lot), FEE custom, or Calculation. ```
Account equity
MONEYTOT Account equity
Usage: MONEYTOT returns the current account equity, and the model is used for fund management such as position control and order lot size.
Calculation method: MONEYTOT=Account available funds + position margin
Note:
example：
K:=MONEYTOT*0.2/(C*MARGIN*UNIT+FEE); // 20% of the account equity can be opened (this is the same as the contract for a fixed lot), FEE customization, or calculation
```
Cryptocurrency spot account available currency
1、For cryptocurrency spot, get the current available currency.
Leverage
Commodity Future
a := MARGIN; // Declare the variable a and assign a to the current contract leverage.
Cryptocurrency Spot
a := MARGIN; // fixed to a value of 1
Cryptocurrency Futures
Cryptocurrency futures set leverage
a := MARGIN; // Declare the variable a and assign a to the current contract leverage.
Get TICK’s latest selling price
Get TICK’s second latest selling price
Get TICK’s third latest selling price
Get TICK’s fourth latest selling price
Get TICK’s fifth latest selling price
Get the volume of latest selling price
Get the volume of second latest selling price
Get the volume of third latest selling price
Get the volume of fourth latest selling price
Get the volume of fifth latest selling price
Get TICK’s latest buying price
Get TICK’s second latest buying price
Get TICK’s third latest buying price
Get TICK’s fourth latest buying price
Get TICK’s fifth latest buying price
Get the volume of latest buying price
Get the volume of second latest buying price
Get the volume of third latest buying price
Get the volume of fourth latest buying price
Get the volume of fifth latest buying price
Get the latest price of TICK
exit the program
EXIT();
Log output
INFO(cond, param, ...);
1、cond is a condition variable and output log when it is true.
2、The condition variable can be followed by multiple variable parameters.
example：
INFO(1, C, '<-closing price');