The needs of strategy developers
Different markets require different benchmarks. Can I set different stop loss spreads based on different opening conditions?
For example, the traditional model of writing the settlement conditions does not distinguish between different opening conditions.
The following code is a simple strategy for traditional indistinguishable storage conditions:
MA5^^MA(C,5);
MA10^^MA(C,10);
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
K..SMA(RSV,3,1);
D..SMA(K,3,1);
CROSS(MA5,MA10)||CROSS(K,D),BK;
C>HV(H,10)||C<BKPRICE-5*MINPRICE,SP;
AUTOFILTER;
And it's not the same with the grouping command.
The subgrouping instruction can be used to divide the open condition into n groups, where the open position of one group is only open for the corresponding open condition of the other group, and the open position of the other group is not signalled or assigned.
For example:
The first group was multi-conditional.
MA5^^MA(C,5);
MA10^^MA(C,10);
CROSS(MA5,MA10),BK;
CROSS(MA10,MA5),SP;
The second group was multi-conditional.
RSV:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
K..SMA(RSV,3,1);
D..SMA(K,3,1);
CROSS(K,D),BK;
C>HV(H,10)||C<BKPRICE-5*MINPRICE,SP;
How do we distinguish between different groups of conditions in the same model? Let's implement them.
First, the models are divided into filtered and non-filtered models:
Filtering model: Different open conditions want to be leveled with different breakeven conditions, which can be implemented using instruction clustering.
Non-filtering model: The first entry strategy is different from the leverage strategy, which can be implemented using instruction clustering.
Filtering model
//A组指令
A组的开多条件,BK('A');
A组的开空条件,SK('A');
A组的平多条件,SP('A');
A组的平空条件,BP('A');
//B组指令
B组的开多条件,BPK('B');
B组的开空条件,SPK('B');
B组的平多条件,SP('B');
B组的平空条件,BP('B');
AUTOFILTER;//过滤函数
Note: A filtering model's grouping requires that the grouping be added after the transaction instruction and enclosed with a single quotation mark. For example, BK (
Unfiltered model
//A组指令
A组的开多条件1,BK('A',2);
A组的开空条件1,SK('A',2);
A组的加多条件2,BK('A',1);
A组的加空条件2,SK('A',1);
A组的平多条件,SP('A',GROUPBKVOL('A'));
A组的平空条件,BP('A',GROUPSKVOL('A'));
//B组指令
B组的加多条件,BK('B',1);
B组的加空条件,SK('B',1);
B组的平多条件1,SP('B',GROUPBKVOL('B'));
B组的平空条件1,BP('B',GROUPSKVOL('B'));
Note: The grouping of non-filtered models requires the addition of groups and hand numbers after the transaction instructions, and groups need to be enclosed by single quotes.
For example, BK ((
Filtering model: first group filter, then signal filter
Group filtering means: if the previous K-line signal is an opening signal from group A (BK SK BPK SPK), the current K-line can only be a placement signal from group A. If the previous K-line signal is a placement signal from group A (BP SP), the current K-line can be an opening signal from any group.
Uncoupled settlement conditions can only open uncoupled settlement conditions.
Signal filtering refers to:
The priority order is:
This is a non-filter model:
In the following, we'll use a few strategies to show how these instructions are grouped when writing code.
Filtering model
Trading ideas: Using 20-cycle and 60-cycle straightforward gold forks as trend judging criteria.
The code is:
MA20^^MA(C,20);
MA60^^MA(C,60);
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;
HH:=HV(H,10);
LL:=LV(L,10);
MA20>MA60&&H>HH&&C>O,BK('A');
MA20<MA60&&L<LL&&C<O,SK('A');
L<LV(L,5)||CROSSDOWN(MA20,MA60)||C<BKPRICE-5*MINPRICE,SP('A');
H>HV(H,5)||CROSSUP(MA20,MA60)||C>SKPRICE+5*MINPRICE,BP('A');//只平A组开仓
MA20>MA60&&CROSSUP(K,D)&&C>O,BK('B');
MA20<MA60&&CROSSDOWN(K,D)&&C<O,SK('B');
C>BKPRICE+5*MINPRICE||C<BKPRICE-2*MINPRICE||C<REF(L,BARSBK),SP('B');
C<SKPRICE-5*MINPRICE||C>SKPRICE+2*MINPRICE||C>REF(H,BARSSK),BP('B');//只平B组开仓
//不同的开仓条件开仓,用不同的平仓条件,有针对性的平仓。达到不同行情试用不同策略的目的。
AUTOFILTER;
Unfiltered model
Trading idea: Opening a position for the first time with a 5-cycle and 10-cycle straightforward gold fork as a condition.
The code is:
MA5^^MA(C,5);
MA10^^MA(C,10);
MA20:=MA(C,20);
MA60^^MA(C,60);
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;
HH:=HV(H,10);
LL:=LV(L,10);
CROSSUP(MA5,MA10)&&BKVOL=0&&C>=O,BK('A',2);
CROSSDOWN(MA5,MA10)&&SKVOL=0&&C<=O,SK('A',2);
CROSSUP(MA5,MA60)&&ISLASTBK&&BKVOL=2,BK('A',1);
CROSSDOWN(MA5,MA60)&&ISLASTSK&&SKVOL=2,SK('A',1);
MA5>MA60&&H>HH&&ISLASTSP&&REF(GROUPBKVOL('A'),BARSSP+1)>0,BK('B',1);
MA5<MA60&&L<LL&&ISLASTBP&&REF(GROUPSKVOL('A'),BARSBP+1)>0,SK('B',1);
L<LV(L,5)||C<REF(L,BARSBK)&&(C<BKPRICE-2*MINPRICE),SP('A',GROUPBKVOL('A'));
H>HV(H,5)||C>REF(H,BARSSK)&&(C>SKPRICE+2*MINPRICE),BP('A',GROUPSKVOL('A'));
C>BKPRICE+10*MINPRICE||CROSSDOWN(MA5,MA60),SP('B',BKVOL);
C<SKPRICE-10*MINPRICE||CROSS(MA5,MA60),BP('B',SKVOL);
The above is a specific case analysis of these two models, from which the reader can see how My language handles grouping instructions, and how each person can develop different grouping requirements according to their own strategy logic, so that they can try to express the strategy logic they want to express in the code in the clearest and least error-prone way possible.