MyLanguage Document

Author: , Created: 2018-12-14 17:33:09, Updated: 2019-04-10 09:11:27

ished 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
```
  • CONDBARS

    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.
    
  • COUNT

    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.
    
  • DMA

    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
    
  • EMA

    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
    
  • EMA2

    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.
    
  • EMAWH

    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)
    
  • HARMEAN

    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.
    
  • HHV

    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
    
  • HV

    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.
    
  • HHVBARS

    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.
    
  • LLV

    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.
    
  • LV

    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.
    
  • LLVBARS

    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.
    
  • MA

    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.
    
  • MV

    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
    
  • NUMPOW

    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);
    
  • SAR

    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%.
    
  • SMA

    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.
    
  • SMMA

    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
    
  • SORT

    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
    
  • SUM

    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.
    
  • SUMBARS

    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.
    
  • TRMA

    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));
    
  • TSMA

    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
    
  • Mathematical Statistics Function

    • AVEDEV

      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
      
    • COEFFICIENTR

      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

      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
      
    • COVAR

      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.
      
    • DEVSQ

      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.
      
    • FORCAST

      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

      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.
      
    • NORMPDF

      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

      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

      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
      
    • STD

      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.
      
    • STDP

      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.
      
    • VAR

      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.
      
    • VARP

      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.
      
  • Mathematical Function

    • ABS

      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
      
    • ACOS

      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;
      
    • ASIN

      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;
      
    • ATAN

      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;
      
    • CEILING

      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.
      
    • COS

      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
      
    • CUBE

      Cubic function

      CUBE(X):Returns the cube of X.
      
      example 1:
      CUBE(4);//ask for the cube of 4.
      
    • EXP

      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
      
    • FLOOR

      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.
      
    • INTPART

      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.
      
    • LN

      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.
      
    • LOG

      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。
      
    • MAX

      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
      
    • MAX1

      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.
      
    • MEDIAN

      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
      
    • MEDIAN1

      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
      
    • MIN

      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.
      
    • MIN1

      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。
      
    • MOD

      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.
      
    • MODE

      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.
      
    • POW

      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
      
    • RAND

      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

      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
      
    • REVERSE

      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
      
    • ROUND

      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
      
    • SGN

      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
      
    • SIN

      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
      
    • SQRT

      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

      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.
      
    • TAN

      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.
      
  • Trading Order

    • BK

      BK BK buy long

    • BP

      BP buy to cover (close the short position)

    • SK

      SK sell short

    • SP

      SP sell (close the long position)

    • BPK

      BPK Open a new buying long position after sell (SP)

    • SPK

      SPK Open a new selling short position after buy to cover (BP)

    • CLOSEOUT

      CLOSEOUT Close all position, no matter the long or short position

    • SELECT

      SELECT SELECT formula stock picking

    • TRADE_AGAIN

      TRADE_AGAIN(N),in the addition and subtraction model with this function, the same command line can continuously output N signals

    • AUTOFILTER

      AUTOFILTER,enables one open position and one close position signal filtering mechanism.

    • MULTSIG

      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;
      
  • Calculation Control Function

    • FILTER

      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.

    • AUTOFILTER

      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
      
    • TRADE_AGAIN

      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

More