Three-track Volatility Strategy

Place order after K line is done, open or close position when closing price is determined

Data Level: Daily K Line

  • Main chart:
    MIDTR^^MA(C,CN); // Determine MIDTR
    UPTR^^MIDTR+2STD(C,CN); // Determine UPTR
    DOWNTR^^MIDTR-2STD(C,CN); // Determine DOWNTR
    HPOINT^^HV(H,CN), DOT, COLORRED;
    // Calculate the maximum value of the highest price in the CN cycle of the previous cycle.
    LPOINT^^LV(L,CN), DOT, COLORBLUE;
    // Calculate the minimum value of the lowest price in the CN cycle of the previous cycle.
  • Secondary chart:
    none
(*backtest
start: 2017-07-01 00:00:00
end: 2018-11-30 00:00:00
period: 1d
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*)

// Determine CN 
VOLAT:=STD(C,N);                  // VOLAT(volatility): Standard deviation of closing price in M-cycle 
VOLATCHANGE:=(VOLAT-REF(VOLAT,1))/VOLAT;    // Change rate of two VOLATs
N1:=(1+VOLATCHANGE)*MINN;                   // VOLATCHANGE : Volatility change
N2:=INTPART(N1);                            //  Rounding off an integer
N3:=MIN(N2,MAXN);                           // Confirm that CN is no more than 60
CN:=MAX(N3,MINN);                           // Confirm that CN is no less than 20

MIDTR^^MA(C,CN);                            // Determine MIDTR
UPTR^^MIDTR+2*STD(C,CN);                    // Determine UPTR
DOWNTR^^MIDTR-2*STD(C,CN);                  // Determine DOWNTR
HPOINT^^HV(H,CN),DOT,COLORRED;           // see main chart
LPOINT^^LV(L,CN),DOT,COLORBLUE;            // see main chart

// open position
L<=LPOINT AND L<DOWNTR AND BARPOS>MINN,SK(AMOUNT); 
 // when the lowest price <  the lowest point and DOWNTR
and the K-line position > 60, sell short the closing price
H>=HPOINT AND H>UPTR AND BARPOS>MINN,BK(AMOUNT);   
 // when the highest price > UPTR and the highest point, 
and the K-line position > 60, buy long the closing price
// start stop loss
C>=SKPRICE*(1+STOPRANGE*0.001),BP(SKVOL);
C<=BKPRICE*(1-STOPRANGE*0.001),SP(BKVOL);

// close position
C<MIDTR,SP(BKVOL);         // when closing price < MIDTR, sell the closing price
C>MIDTR,BP(SKVOL);         // when closing price > MIDTR, buy to cover the closing price

// Dynamic stop loss
REF(BKHIGH,1)>BKPRICE*(1+2*0.001*STOPRANGE) AND C<HV(C,BARSBK)*(1-STOPRANGE*0.001),SP(BKVOL);  
// the highest price after buying long > buy long price*(1+2*0.001*STOPRANGE), 
and closing price < the highest closing price after buying long*(1-STOPRANGE*0.001), 
then sell closing price.

REF(SKLOW,1)<SKPRICE*(1-2*0.001*STOPRANGE) AND C>LV(C,BARSSK)*(1+STOPRANGE*0.001),BP(SKVOL);   
// the lowest price after sellong short < sell short price *(1-2*0.001*STOPRANGE), 
and closing price > the lowest closing price after selling short*(1+STOPRANGE*0.001), 
then buy to cover closing price.

Backtest on FMZ Quant to know more

Source Code: https://www.fmz.com/strategy/128129

Add a Comment

Your email address will not be published. Required fields are marked *