资源加载中... loading...

MyLanguage Doc

Author: 发明者量化-小小梦, Created: 2022-06-30 18:24:06, Updated: 2024-02-06 17:36:19

(2)After the BP signal is sent, the K-line BARSBP returns to the number of periods from the K-line for buying and closing positions to the current K-line. If the condition of BARSBP>=1 is satisfied, the value is HHV(H, BARSBP+1), that is, the maximum value of the buying and closing positions (including the current K-line when the close signal appears) to the current highest price. 3.AA:=IFELSE(BARSBP>=1,REF(C,BARSBP),C);//Take the closing price of the last K-line to buy and close the position: (1)When the BARSBP of the current K-line that sends the BP signal returns null, then when the K-line does not meet the condition of BARSBP>=1, AA returns to the closing price of the current K-line. (2)The K-line BARSBP after the BP signal is sent returns to the period number of the K-line for buying and closing the position from the current K-line, then AA returns to REF(C, BARSBP), which is the closing price of the closing K-line. (3)For example: three K-lines: 1, 2, and 3, the K-line in 1 is the current K-line of the closing signal, then returns to the closing price of the current K-line, and the K-line AA in 2 and 3 returns to the closing price of the K-line in 1. ```

  • REFSIG_VOL

    Returns to the number of signal lots for the Nth fixed Sig signal counted down from the current K-line (backhand orders take the number of open position lots).

    Usage: REFSIG_VOL(Sig,N);, determine the lot size of the Nth fixed Sig signal counting from the current K-line. If there is no sig signal, or if there is no fixed sig signal, the function returns 0.

    Remarks: 1.The signals supported by the Sig position are: BK, SK, BP, SP, BPK, SPK,CLOSEOUT,STOP. 2.If the countdown to the Nth fixed Sig signal is on the current K-line, then the function returns to the current signal lot. 4.When N is 0 or null, the function returns 0. 5.The parameter N supports variables.

    Examples:

    // If there are 5 K-lines from the current K-line where the third fixed BK signal is located from the bottom of the current K-line, and the number of signal lots is greater than 2, close all positions
    REFSIG_PLACE(BK,3)=5&&REFSIG_VOL(BK,3)>2,SP(BKVOL);
    
  • REFSIG_PRICE

    Returns to the signal price of the Nth fixed Sig signal from the beginning of the current K-line.

    Usage: REFSIG_PRICE(Sig,N);, determine the signal price of the Nth fixed Sig signal from the current K-line. If there is no Sig signal, or if there is no fixed Sig signal, the function returns 0.

    Remarks: 1.The signals supported by the Sig position are: BK, SK, BP, SP, BPK, SPK,CLOSEOUT,STOP. 2.If there is a fixed Sig signal on the current K-line, then when the function calculates the signal, the signal of the current K-line is included. 3.When N is 0 or null, the function returns null. 4.The parameter N supports variables.

    Examples:

    // If the opening price of the 3rd last fixed BK signal from the current K-line is 3000, and the long position is greater than 0, sell and close the position
    REFSIG_PRICE(BK,3)=3000&&BKVOL>0,SP;
    
  • COUNTSIG

    Count the number of X signals in N periods.

    Usage: COUNTSIG(X,N);Count the number of X signals in N periods. X can be BK, SK, SP, BP, SPK, BPK ,CLOSEOUT,STOP.

    Remarks: 1.During the statistical period, (1)Contains the current K-line. (2)If N is 0, then count from the first valid value. (3)When N is a valid value, but the current number of K-line is less than N, count from the first one to the current period. (4)The return value is null when N is null. (5)N can be a variable. 2.When counting signals: (1)The signal execution method is selected as the confirmation signal after the K-line is completed or the review after the K-line is completed (for example: write CHECKSIG(SIG,‘A’,0,‘D’,0,0); in the model), excluding the Signals that are not fixed on the current K-line, that is, return to the number of signals that have been fixed. (2)The signal execution method is selected not to perform signal review (for example: write MULTSIG or MULTSIG_MIN; in the model), including the signal when the current K-line is sent and fixed. 3.The BK signal generated by the BPK command is processed as the BPK signal, and the SK signal generated by the SPK command is the same.

    Examples:

    N:=BARSLAST(DATE<>REF(DATE,1))+1;
    BKN:=COUNTSIG(BK,N);
    MA5:=MA(C,5);
    BKN=0&&C>MA5,BK;                        // There is no BK signal in the day and the latest price is greater than the 5-period moving average, then buy and open a position
    
  • ENTRYSIG_PLACE

    Take the K-line position of the specified opening position signal.

    Usage: ENTRYSIG_PLACE(N);, take the position of the K-line where the Nth position opening signal is located in a complete trading. If there is no signal to open a position, the function returns null.

    Remarks: 1.Signals for opening positions are: BK, SK, BPK, SPK. 2.A position is considered a full trade from the time it is opened until it is held at 0. 3.If the number of open signals in a complete trade is less than N, the function returns null. 4.The K-line position is the number from the current K-line to the K-line where the specified opening signal is located. 5.When N is 0 or null, the function returns null. 6.Parameter N is not supported as a variable.

    Examples:

    ENTRYSIG_PLACE(3)=5&&BKVOL>0,SP;        // If the K-line of the third position opening signal is 5 K-lines away from the current K-line, and the long position is greater than 0, sell and close the position
    
  • ENTRYSIG_PRICE

    Take the price of the specified open position signal.

    Usage: ENTRYSIG_PRICE(N);, take the price of the Nth opening signal in a complete trade. If there is no signal to open a position, the function returns null.

    Remarks: 1.Signals for opening positions are: BK, SK, BPK, SPK. 2.A position is considered a full trade from the time it is opened until it is held at 0. 3.If the number of open signals in a complete trade is less than N, the function returns null. 4.When N is 0 or null, the function returns null. 5.Parameter N is not supported as a variable. 6.The calculation of this function includes slippage. 7.Closing price model: The value of the current K-line function of the specified signal will not change. Command price model: Return to the price of the Nth opening signal of the current trading at the current K-line of the specified signal.

    Examples:

    ENTRYSIG_PRICE(3)=3000&&BKVOL>0,SP;     // If the opening price of the 3rd fixed opening signal is 3000, and the long position is greater than 0, sell and close the position
    
  • ENTRYSIG_VOL

    Take the signal lot of the specified position opening signal.

    Usage: ENTRYSIG_VOL(N);, take the signal lot size of the Nth opening signal in a complete trade. If there is no signal to open a position, the function returns null.

    Remarks: 1.Signals for opening positions are: BK, SK, BPK, SPK. 2.A position is considered a full trade from the time it is opened until it is held at 0. 3.If the number of open signals in a complete trade is less than N, the function returns null. 4.When N is 0 or null, the function returns null. 5.Parameter N is not supported as a variable. 6.Closing price model: The value of the current K-line function of the specified signal will not change. Command price model: At the current K-line of the specified signal, it returns to the signal lot number of the Nth opening signal of the current trading.

    Examples:

    ENTRYSIG_PRICE(3)=3000&&ENTRYSIG_VOL(3)>2,SP;     // If the opening price of the 3rd fixed opening signal is 3000, and the signal lot number of the 3rd fixed opening signal is greater than 2, sell and close the position
    
  • EXITSIG_PLACE

    Take the K-line position of the specified closing signal.

    Usage: EXITSIG_PLACE(N);, take the position of the K-line of the Nth closing signal in a complete trading. If there is no close signal, the function returns null.

    Remarks: 1.Signals for closing positions are: BP, SP, CLOSEOUT, STOP. 2.A position is considered a full trade from the time it is opened until it is held at 0. 3.When the number of closing signals is less than N, the function returns null. 4.The K-line position refers to the number of K-lines from the current K-line to the designated closing signal. 5.When N is 0 or null, the function returns null. 6.Parameter N is not supported as a variable.

    Examples:

    EXITSIG_PLACE(3)=5&&BKVOL<=0,BK;                  // If the K-line of the third closing signal is 5 K-lines away from the current K-line, and there is no long position, buy to open a position
    
  • EXITSIG_PRICE

    Take the price of the specified closing position signal.

    Usage: EXITSIG_PRICE(N);, take the price of the Nth closing signal in a complete trade. If there is no close signal, the function returns null.

    Remarks: 1.Signals for closing positions are: BP, SP, CLOSEOUT, STOP. 2.A position is considered a full trade from the time it is opened until it is held at 0. 3.When the number of closing signals in a complete trading is less than N, the function returns null. 4.When N is 0 or null, the function returns null. 5.Parameter N is not supported as a variable. 6.The calculation of this function includes slippage. 7.Closing price model: The value of the current K-line function of the specified signal will not change. Command price model: Return to the price of the Nth opening signal of the current trading at the current K-line of the specified signal.

    Examples:

    EXITSIG_PRICE(3)=3000&&BKVOL>0,SP;               // If the closing price of the 3rd fixed closing signal is 3000, and the long position is greater than 0, sell and close the position
    
  • EXITSIG_VOL

    Take the signal lot of the specified closing position signal.

    Usage: EXITSIG_VOL(N)Take the signal lot size of the Nth closing signal in a complete trade. If there is no close position signal, the function returns null.

    Remarks: 1.Signals for closing positions are: BP, SP, CLOSEOUT, STOP. 2.A position is considered a full trade from the time it is opened until it is held at 0. 3.When the number of closing signals in a complete trading is less than N, the function returns null. 4.When N is 0 or null, the function returns null. 5.Parameter N is not supported as a variable. 6.Closing price model: The value of the current K-line function of the specified signal will not change. Command price model: At the current K-line of the specified signal, it returns to the signal lot number of the Nth closing signal of the current trading.

    Examples:

    EXITSIG_PRICE(3)=3000&&EXITSIG_VOL(3)>2,BK;      // If the closing price of the 3rd fixed closing signal is 3000, and the signal lot number of the 3rd fixed closing signal is greater than 2, buy to open the position
    
  • Position functions

    • MYVOL

      Take the lot number of orders.

      MYVOL take the lot number of orders.
      
      Usage: Take the lot number of orders, it is mostly used for lot calculation when multiple contracts are loaded in the scale in/dump model.
      
      Remark:
      Backtesting: Return to the lot size set in the backtesting parameters.
      
      Examples:
      // When the order lot size in the loading parameter is set to 3, the order lot size of BK written following is 6
      C>O,BK(2*MYVOL);
      C<O,SP(BKVOL);
      
    • MONEY

      Funds available in the account.

      MONEY funds available in the account.
      
      Usage: MONEY returns to the available funds in the account for calculation of positions, lot sizes, etc.
      
      Calculation methods:
      1.The initial value of MONEY in the account is the starting capital set in the margin parameters.
      2.The initial value of MONEY in the historical backtesting is the initial capital set in the backtesting parameters.
      3.The MONEY value of the current K-line of the position opening signal: available funds before opening a position - margin for holding positions - handling fee, where margin for holding positions = opening price * margin ratio * trading unit * lot size.
      4.Money value of K-line not closed after opening = money value of K-line before opening signal + floating profit and loss profit.
      5.The MONEY value of the current K-line of the closing signal: available funds before closing the position + profit and loss of closing the position + margin released by closing the position - handling fee, where the margin released by closing the position = opening price * margin ratio * trading unit * lot size.
      
      Remarks:
      1.The signal execution method is 'confirm the order after the K-line is completed' or 'XX order and review after the K-line is completed':
        a.When the signal to open a position is a K-line, the return value of MONEY is the available funds of the previous K-line - margin for opening a position - handling fee.
        b.When the closing signal is a K-line, the return value of MONEY is the available funds of the previous K-line + closing profit and loss + margin released by the position - handling fee.
      2.Select the signal execution method as 'send a signal to place an order without reviewing':
        a.When the signal to open a position is a K-line, the return value of MONEY is the available funds of the previous K-line - margin for opening a position - handling fee.
        b.When the closing signal is a K-line, the return value of MONEY is the available funds of the previous K-line + closing profit and loss + margin released by the position - handling fee.
      3.The signal execution method is 'When the K-line is completed to confirm the signal to place an order', the closing profit and loss = (the closing price of the K-line of the closing signal - the opening price) * lot size * trading unit - handling fee.
      4.When the signal execution method is 'the signal is placed immediately without review', the closing profit and loss = (the order price of the closing signal - the opening price) * lot size * trading unit - handling fee.
      5.After the account is initialized, the return value of MONEY is the funds available in the initialization box.
      
      Examples:
      K:=MONEY*0.2/(C*MARGIN*UNIT+FEE);               // The number of lots that can be opened with 20% of the account's available funds (this writing method is applicable to contracts that charge a fee based on a fixed number of lots), FEE custom, or calculated
      
    • MONEYTOT

      Account Equity.

      MONEYTOT account Equity.
      
      Usage: MONEYTOT returns to the current account equity, and the model performs position control. It is used for fund management such as order lot size.
      
      Calculation method: MONEYTOT=Account available funds + position margin.
      
      Remarks:
      1.The initial value of MONEYTOT in the account is the initial capital set in the margin parameters.
      2.The initial value of MONEYTOT in the historical backtesting is the initial capital set in the backtesting parameters.
      3.When the account is initialized:
        a.The current signal is the opening signal, and the return value of MONEYTOT is the available funds of the account in the initialization box.
        b.The current signal is the closing signal, then MONEYTOT returns to the available funds of the account + margin in the initialization box.
      4.The signal to open a position is the K-line: MONEYTOT = available funds in the account + margin for holding positions.
      5.After opening a position and before closing a position: MONEYTOT returns to the available funds in the current account + margin for holding positions.
      6.The current k-line of the closing signal: when the position is 0, MONEYTOT = available funds; when the position is not 0, MONEYTOT = available funds + margin occupied by the position.
      Remark:
      The available funds in the position list are the available funds including floating profit and loss (= current equity - margin occupied by positions).
      
      Examples:
      K:=MONEYTOT*0.2/(C*MARGIN*UNIT+FEE); // The number of lots that can be opened with 20% of the account equity(this writing method is applicable to contracts that charge a fixed lot size), FEE customization, or calculation.
      
    • ACCOUNTMONEY

      Returns to the available funds in the trading account, equivalent to MONEY.

      Usage: ACCOUNTMONEYReturns to the available funds in the trading account.

    • ACCOUNTMONEYTOT

      Returns to the equity in the trading account, equivalent to MONEYTOT.

      Usage: ACCOUNTMONEYTOTReturns to the equity in the trading account.

    • COINS

      The number of coins available in the digital currency spot account.

      1.It is used for digital currency spot to obtain the current number of available coins.
      
    • MARGIN

      Leverage.

      Digital currency spot

      a := MARGIN;   // Fixed as value 1
      

      Digital currency futures

      Digital currency futures set leverage.

      img

      a := MARGIN;   // Declare the variable a and assign the current contract leverage to a
      
  • TICK data function

    • ASK1

      Obtain the selling price of TICK for one.

    • ASK2

      Obtain the selling price of TICK for two.

    • ASK3

      Obtain the selling price of TICK for three.

    • ASK4

      Obtain the selling price of TICK for four.

    • ASK5

      Obtain the selling price of TICK for five.

    • ASK1VOL

      Obtain the selling volume of TICK for one.

    • ASK2VOL

      Obtain the selling volume of TICK for two.

    • ASK3VOL

      Obtain the selling volume of TICK for three.

    • ASK4VOL

      Obtain the selling volume of TICK for four.

    • ASK5VOL

      Obtain the selling volume of TICK for five.

    • BID1

      Obtain the bid price of TICK for one.

    • BID2

      Obtain the bid price of TICK for two.

    • BID3

      Obtain the bid price of TICK for three.

    • BID4

      Obtain the bid price of TICK for four.

    • BID5

      Obtain the bid price of TICK for five.

    • BID1VOL

      Obtain the bid volume of TICK for one.

    • BID2VOL

      Obtain the bid volume of TICK for two.

    • BID3VOL

      Obtain the bid volume of TICK for three.

    • BID4VOL

      Obtain the bid volume of TICK for four.

    • BID5VOL

      Obtain the bid volume of TICK for five.

    • NEW

      Obtain the latest price of TICK.

  • System

    • EXIT

      An error text is thrown and the program exits.

      EXIT('msg');   // Parameters need to be passed in, string parameters need to be wrapped with '', an error is thrown, the error text is string msg
      
    • INFO

      Log output

      INFO(cond, param, ...);
      
      1.cond is a condition variable, output log if true.
      2.A condition variable can be followed by multiple variadic parameters.
      Example:
      INFO(1, C, '<-closing price');
      
    • CONTRACT

      Use CONTRACT to get the exchange contract code of the currently set contract mapping.

      INFO(1, CONTRACT);
      

      img

    • DATA

      Use the DATA command to load data.

      (*backtest
      start: 2020-01-21 00:00:00
      end: 2020-02-12 00:00:00
      period: 1d
      basePeriod: 1h
      exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
      *)
      A:DATA('https://www.fmz.com/upload/asset/32bf73a69fc12d36e76.json');
      INFO(1, CONTRACT, A);
      C>HV(H, 10),SPK;
      C<LV(L, 15),BPK;
      AUTOFILTER;
      

      Use ['attribute name'] to take the value of an attribute in the data.https://www.fmz.com/upload/asset/1ef31d778467ed9dd00.json is the external data links, it can be a link to data provided by other service programs, or it can be data provided by the data center of the FMZ Quant trading platform, such as the part of the comments in the example (*Consumption Index: DATA('CPI')[ 'city'];*), use the code CPI to get data (the data is not all opened yet).

      (*backtest
      start: 2018-01-21 00:00:00
      end: 2020-02-12 00:00:00
      period: 1d
      basePeriod: 1d
      exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
      *)
      
      Consumption index: DATA('https://www.fmz.com/upload/asset/1ef31d778467ed9dd00.json')['city'];
      (*Consumption index: DATA('CPI')['city'];*)
      Consumption index > HV(Consumption index, 90),BPK;
      Consumption index < LV(Consumption index, 90),SPK;
      AUTOFILTER;
      

      img

  • Others

    • MyLanguage class library parameters

      • Minimum points of price

        img

        On the BITMEX futures exchange, the minimum points of price is 0.5. On the OKEX futures exchange, the minimum points of price is 0.01.

        When the price of some contracts is relatively low, it’s necessary to pay attention to whether the setting of parameters, such as pricing currency precision, trading variety precision are appropriate.

      • Maximum number of periods of the variable It affects the number of chart K-line BARs in the same way that calling the SetMaxBarLen function in the javascript strategy does.

      • MyLanguage strategy, the number of positions displayed on the table in the status column.

        All are the actual number of positions held.

        img

      • Conditional judgment (not recommended to write in this way).

        IF H > C THEN
        BEGIN
            X:=10;
        END
        
    • Example:

      • When the real-time price model is used, the new K-line Bar is detected:

        VARIABLE:N:0;
        IF N <> BARPOS AND ISLASTBAR = 1 THEN
        BEGIN
            N:=BARPOS;
            INFO(1, '123');
        END
        

Related

More