Writing my language's cross-cycle model

Author: Goodness, Created: 2019-07-09 10:15:08, Updated: 2019-07-16 15:37:53

Why do we need to write cross-cycle models?

In trading, the major cyclical trend is up and the minor cyclical trend is down, in which direction should it go?

If the trading concept is done in sequence in the direction of the big trend, then there are two problems: first, when the small trend changes against the big trend, the chips in the hand can form a large loss, and even make people unable to cut. Second, if a small trend occurs, a large turn will also cause a turn in the big trend, until it is too late to cut the big trend when it turns.

img

As in the example shown above: the reversal signal of the M-head of the 30-minute cycle appears, a jump of more than 40 points is likely to trigger a blank order condition, while the short cycle of 1 minute starts to decline and starts to recover in no time, reaching a maximum of 43.8 points.

Therefore, the relationship between the size of the cycle and the optimal operating time is the problem to be studied. Cross-cycle analysis is essentially a problem of how small fluctuations affect large trends, or how large trends limit small trends.

Another application of transcyclicity is in resonance theory.

Let me tell you a little story: In World War I, a group of German soldiers stepped through a bridge with a steady pace and ended up trampling the bridge. The bridge itself was much heavier than the German soldiers' weight in terms of load capacity, but because the soldiers' steps were in tune, the resulting bridge collapsed under this force. This is what resonance does.

img

Symmetry theory is embodied in the trading market: market volatility, or intrinsic cyclical factors, arise from the multiplicative relationship between market time and price. When the frequency of the intrinsic fluctuation of the market is multiplied by the frequency of external market forces, a market resonance relationship occurs, which produces a huge upward or downward effect.

Application of functions in the cross-cycle model

// 本代码演示如何引用不同周期的公式在同一代码里
// #EXPORT扩展语法, 以#END结束标记为一个公式,可以声明多个
#EXPORT TEST 
均值1:EMA(C, 20);
均值2:EMA(C, 10);
#END // 结束

#IMPORT [MIN,15,TEST] AS VAR15 // 引用公式, K线周期用15分钟
#IMPORT [MIN,30,TEST] AS VAR30 // 引用公式, K线周期用30分钟
CROSSUP(VAR15.均值1, VAR30.均值1),BPK;
CROSSDOWN(VAR15.均值2, VAR30.均值2),SPK;
十五分最高价:VAR15.HIGH;
三十分最高价:VAR30.HIGH;
AUTOFILTER;

More details can be found at:https://www.fmz.com/digest-topic/2569

Structure and programming of cross-cycle models

The basic structure of the cross-cycle model:

  • Step 1: Create the reference model FORMULA

  • Step 2: Create a cross-cycle model that can be used as follows:

#IMPORT [PERIOD,N,FORMULA] AS VAR
A1:VAR.A;

A1>REF(A1,1),BPK;
A1<REF(A1,1),SPK;

…

AUTOFILTER;

Example 1: The closing price of yesterday's K line quoted in a five-minute cycle

  • The first step is to create indicator 1.
CC:REF(C,1);
  • Step two: Creating cross-cycle indicators
#IMPORT[DAY,1,A] AS A1
C1:A1.CC;
  • Step 3: Apply indicator 2 to the 5-minute K-string

The above is a simple example and code framework, and we'll write a more complex structure next.

Example 2: Based on a 30-minute cycle chart, the MACD indicator shows a red column when the 30-minute cycle is shown, and the volume of the trade is larger than the previous one; the average of the large-scale cycle (the day-line and the 1-hour line) has a multi-headed column; the KD indicator gold fork is the buy-in point according to the small-scale cycle (the 15-minute or 5-minute)

DIFF : EMA(CLOSE,12) - EMA(CLOSE,26);
DEA  : EMA(DIFF,9);
#IMPORT[DAY,1,MM] AS MM1
MD1:MM1.M1;
MD2:MM1.M2;
MD3:MM1.M3;
#IMPORT[HOUR,1,MM] AS MM2
MH1:MM2.M1;
MH2:MM2.M2;
MH3:MM2.M3;
#IMPORT[MIN,15,KD] AS KD1
K1:=KD1.K;
D1:=KD1.D;
#IMPORT[MIN,5,KD] AS KD2
K2:=KD2.K;
D2:=KD2.D;
TMP1:= DIFF>DEA&&VOL>REF(VOL,1);
TMP2:=(MD1>MD2&&MD2>MD3)&&(MH1>MH2&&MH2>MH3);
TMP3:=(CROSSUP(K1,D1)||CROSSUP(K2,D2);
TMP1&&TMP2&&TMP3,BK(10);

For explanations and usage of the misunderstood functions in the example, please refer to the official API documentation of the inventor quantification platform and the My language documentation:https://www.fmz.com/digest-topic/2569

Let's try another example of a straight-line cross-cycle.

Example 3: Three-screen trading system; do more when the monthly chart is trending up and the weekly chart is trending down; do nothing when the monthly chart is trending down and the weekly chart is trending up.

  • Step 1: Write the SPJY referenced
EMA1:EMA(C,13);
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100
K:SMA(RSV,3,1);
D:SMA(K,3,1);
J:3*K-2*D;
  • Step 2: Establish a three-screen trading system
#IMPORT [ MONTH,1,SPJY] AS VAR1
YMA:=VAR1.EMA1;
#IMPORT [ WEEK,1,SPJY] AS VAR2
ZJ:=VAR2.J;
LL:=VALUEWHEN(YMA>REF(YMA,1)&&ZJ<30,L);
HH:=VALUEWHEN(YMA<REF(YMA,1)&&ZJ>70,H);
YMA>REF(YMA,1)&&ZJ<30,BK;//月线的趋势向上,周线的振荡指标向下
YMA<REF(YMA,1)&&ZJ>70,SK;//月线的趋势向下,周线的振荡指标向上
C<LL,SP;//多头止损出场
C>HH,BP;//空头止损出场
C<LLV(L,20),SP;//多头出场条件
C>HHV(H,20),BP;//空头出场条件
AUTOFILTER;

Note: Cross-cycle indicators, models support small cycle references to large cycles, and large cycles can refer to small cycles, pay attention to data references.

The indicator is DAYBAR

N:=BARSLAST(DATE<>REF(DATE,1))+1;

#IMPORT[HOUR,1,DAYBAR] AS VAR1
N1:VAR1.N;
盘中3分钟引用1小时周期的当日K线根数,20个3分钟周期N1才变动。

#IMPORT[MIN,3,DAYBAR] AS VAR2
N2:VAR2.N;
盘中1小时引用3分钟周期的当日K线的根数N,1小时中存在20个N2值变动。

The following are some simple applications of My Language in the field of cross-cycle strategy writing, where the reader can flexibly play with various combinations of cycles and indicators to achieve the desired effect, especially in the field of digital currency, because of the emergence of perpetual contracts, the efficiency of using My Language can avoid the problem of replacing the main contract in similar commodity futures, as long as the reader focuses on the design of the strategic logic, without worrying about the issue of contract expiration.

Please note:

  • Indicators cited in the cross-cycle, cross-contract model cannot be cited in the model.

  • A cross-cycle, cross-contract model supports up to 6 citations.

  • The total number of cross-periodic, cross-contract data sources used throughout My language should not exceed 50.


More