Commodity futures in the CTA strategy

Author: Zer3192, Date: 2021-04-23 21:06:05
Tags:

A summary

The Martingale strategy originated in France in the 18th century, but it was first used at the table and soon became popular in Europe. In theory, it was a strategy with a winning rate close to 100%, and until now it has been used in many trading markets, such as the foreign exchange, futures and digital currency markets. However, is it really reliable?

Second, the Martinegall strategy

Martingale is neither a trading strategy nor a trading mechanism, but a money management method. Its principle is simple: the trader doubles the next order amount every time he loses a certain amount, until the next order amount is restored to its original value when it is profitable. In this way, only one profit is needed, not only to recover the previous loss, but also to get the first order amount.

Now suppose we have a coin with the same weight on both sides, and continuously toss the coin, the probability of a positive and opposite is about 50%, and then we bet with this coin toss, the initial bet amount is 1 yuan, if the positive appears to win 1 yuan, if the opposite appears to lose 1 yuan. Theoretically, the probability of a coin appearing is the same, because each occurrence is independent of each other, i.e. 50%.

According to Martin's strategy, every time you lose money, you adjust the bet amount to twice the amount of the last bet, you only need to win once to recover all the previous losses. But when you lose consecutively, you will also lose nothing. If the capital is only 10 yuan, the first bet is 1 yuan, there is a reverse loss of 1 yuan, the account balance is 9 yuan; the second bet is 2 yuan, there is a reverse loss of 2 yuan, the account balance is 7 yuan; the third bet is 4 yuan, there is a reverse loss of 4 yuan, the account balance is 3 yuan; then there is not enough money deposited.

Third, strategic retesting

  • Date of start of the retest: 2015-06-01
  • The end of the review date: 2021-04-01
  • The data type: dishes index
  • The data cycle: the calendar
  • Slide point: 2 jumps to the open position

Repeat the configuration img Re-tested performance img The funding curve img Log information img

Four, Martinel's strategy is upgraded

The biggest risk of Martingale's strategy is that the market is always in a one-sided market, and if the trader's holding direction is opposite to the market direction, then the accumulated position is very terrible. If the trader's initial capital is 10,000 yuan and the loss is doubled, then it only takes 7 consecutive losses to blow the position. But if the spread is changed to 1.5, the situation will be much better, and the loss will be 12 consecutive times; If the spread is changed to 1.1, it will take 49 consecutive losses to blow the position.

img

The chart above is a graph of the ratio of the multiplier and the investment of funds, which can be seen by using a lower multiplier, the funds occupied are very small, the stronger the strategic risk resistance, so in order to ensure the security of funds, the real market is recommended to use a low multiplier, it is recommended to calculate the multiplier well before the real market, it is best to be able to make a continuous loss of ten or more times.

5 and Summary

Trading probabilities are the nature of trading, and no one can guarantee a 100% profit every time you place an order. It can be said that when you place an order with the best reasons and timing, the risk is already there. The Martingale strategy is especially applicable to trending markets, as long as traders are able to reasonably judge the trend, open positions along the direction of the trend, and set a good risk-return ratio, they can also get very solid returns.


/*backtest
start: 2015-06-01 00:00:00
end: 2022-04-01 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_usdt"}]
*/

MarginLevel =20//合约杠杆 
unit =0.015//初始下单量
profits =1//盈亏间距
bei =1//倍率



function main() {
    exchange.SetContractType("swap")
    exchange.SetMarginLevel(MarginLevel)
    while (true) {
        let depth = exchange.GetDepth();
        if (!depth) return;
        let ask = depth.Asks[0].Price==-1;
        let bid = depth.Bids[0].Price==-1;
        let position = exchange.GetPosition()
        if (position.length == 0) {
            let redom = Math.random()
            unit =0.015
            if (redom > 0.5) {
                exchange.SetDirection("sell")
                exchange.Sell(-1, unit, "开空")
            }
            if (redom < 0.5 ) {
                exchange.SetDirection("buy")
                exchange.Buy(-1, unit, "开多")
            }
        }
        if (position.length > 0) {
            let type = position[0].Type;
            let profit = position[0].Profit;
            let amount = position[0].Amount;
            if (type == 0) {
                if (profit > profits) {
                    exchange.SetDirection("closebuy")
                    exchange.Sell(-1, amount, "多头止盈,当前盈利:" + profit)
                      unit = 0.015
                }       
            
                if (profit <-profits ) {
                    unit = unit * bei
                    exchange.SetDirection("buy")
                    exchange.Buy(-1, unit, "多头加仓,当前盈利:" + profit)
                }
            }
        
        
            if (type == 1) {
                if (profit > profits) {
                    exchange.SetDirection("closesell")
                    exchange.Buy(-1, amount, "空头止盈,当前盈利:" + profit)
                    unit = 0.015
            }
                    
                
                if (profit < -profits) {
                    unit = unit * bei
                    exchange.SetDirection("sell")
                    exchange.Sell(-1, unit, "空头加仓,当前盈利:" + profit)
                }
            
              }
          } 

        Sleep(1000 )
    }
}




More