A, in this paper,

This is a dynamic positioning strategy, which is favored by traders and has been successful in the ups and downs of the market with the principle of “positioning is more important than timing.” This is the Grid Trading Method, and in this article we will create a commodity futures Grid Trading strategy based on inventor Quantization (FMZ.COM) MY language.

2. What is a grid strategy

Grid strategy, also known as “fishing net strategy”, is the same as the fisherman fishing, it is based on a price as a benchmark, set the price line above and below it (net for fish), each time the price triggers the price line, by adding or subtracting the warehouse operation as much as possible profit. Grid strategy belongs to the left side of the trade. It does not need to predict the direction of price rise and fall, and does not want to chase the rise and fall like the right side of the trade. Instead, it works against the trend, buying when the price falls and selling when the price rises.

The blue line represents the price and the dark line in the middle represents the trader’s expected price. The spread between each grid line is $10. When the price breaks the grid line, a lot is sold and when the price breaks the grid line, a lot is bought. On the left side, the net profit of the account is 50 yuan by buying low and selling high, with 3 short positions and an average price of 130 yuan. On the right side, the net profit is 100 yuan by buying low and selling high. The average position is 80 yuan with 5 short positions.

Third, the risk of grid strategy

As we can see from the above chart, no matter whether the market is going up or down, it can open and close the position at an average price. This trading method does not increase the risk, but reduces it. The trades that have been closed are all positive returns, and the capital curve is relatively stable, which is also one of the advantages of the grid strategy. Another advantage is that the grid strategy does not require a correct judgment of the market direction, which saves a lot of time and effort for lazy or less sensitive traders.

There is no holy grail for quantitative trading strategies. Grid strategies also have risks, such as when the market continues to rise or fall, the strategy will continue to open positions, increasing risk exposure. Grid strategy is suitable for the volatility is low, the trend is not obvious variety, is a magic weapon volatile market profit, which requires the traders in the futures varieties have a slight hold, such as industrial products, especially the black is more easy to get out of the trend of prices is not suitable for grid strategy, instead of agricultural products often fluctuations within a price range for the grid strategy.

Iv. Strategy logic

Step 1: Set the backtest configuration

(*backtest
start: 2015-02-22 00:00:00
end: 2021-04-18 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
args: [["ContractType","RM888",126961]]
*)
Copy the code

Step 2: First trigger the grid

VARIABLE : WG : 1;
IF BKVOL=0 THEN BEGIN 1, 
BK;
WG := CLOSE;
END
Copy the code

Step 3: Open long positions

IF BKVOL > 0 AND CLOSE < wargame * (1-0.1) THEN BEGIN, BK; WG := CLOSE; ENDCopy the code

Step 4: Unwind long positions

IF BKVOL > 0 AND CLOSE > WARgaming/(1-0.1) THEN BEGIN, SP; WG := CLOSE; ENDCopy the code

Step 5: Open short positions

IF SKVOL > 0 AND CLOSE > WARgaming * (1 + 0.1) THEN BEGIN, SK; WG := CLOSE; ENDCopy the code

Step 6: Close short positions

IF SKVOL > 0 AND CLOSE < WARgaming/(1 + 0.1) THEN BEGIN, BP; WG := CLOSE; ENDCopy the code

Step 7: Place an order

MULTSIG(0, 0, 60, 0);
TRADE_AGAIN(100);
Copy the code

It should be noted that the grid policy can be set at will the width and quantity of the grid, can be set by the price of equal width grid, can also be set by proportion of the grid. In addition: the grid spacing is too large, the profit is too slow; The grid spacing is too small and too risky.

5. Strategy backtest

  • Back test start date: 2015-02-22
  • Back test end date: 2021-04-18
  • Data variety: rapeseed meal main continuous
  • Data cycle: daily line
  • Sliding point: open positions 2 jump each

Back to the test configuration To measure performance Money curve

Vi. Complete policy code

(*backtest start: 2015-02-22 00:00:00 end: 2021-04-18 00:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}] args: [["ContractType","RM888",126961]] *) VARIABLE : WG : 1; IF BKVOL=0 THEN BEGIN 1, BK; WG := CLOSE; END IF BKVOL > 0 AND CLOSE > WARgaming/(1-0.1) THEN BEGIN, SP; WG := CLOSE; END IF BKVOL > 0 AND CLOSE < WG * (1-0.1) THEN BEGIN, BK; WG := CLOSE; END IF SKVOL > 0 AND CLOSE < WARgaming/(1 + 0.1) THEN BEGIN 1, BP; WG := CLOSE; END IF SKVOL > 0 AND CLOSE > WARgaming * (1 + 0.1) THEN BEGIN, SK; WG := CLOSE; END MULTSIG(0, 0, 60, 0); TRADE_AGAIN(100);Copy the code

The complete policy code and the backtest configuration are attached above, or you can copy the complete policy code by clicking the link below: www.fmz.com/strategy/27…