求问,具体怎么控制每日最多只进行一次换股交易 [MC]
-
MC用户求助:
inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: var0( 0 ), var1( 0 ) ;
once value1=pmms_strategies_get_by_symbol_name(getsymbolname);
{将当前策略的编号存储到变量value1上}
var0 = AverageFC( Price, FastLength ) ;
var1 = AverageFC( Price, SlowLength ) ;
if value1=0 then begin
if currentbar=1 or date[1]<>date then
pmm_set_global_named_num("num",1);
end;
{由于策略的执行是从策略编号0开始依次到最大策略编号,然后再循环执行,所以这里通过在策略编号为0时,对全局变量“num”进行赋值1,即当天可交易的次数}
condition1 = CurrentBar > 1 and var0 crosses above var1 ;
if pmm_get_global_named_num("num")=1 and value1=pmm_get_global_named_num("entry") then begin
Buy ( "MA2Cross_Long" ) 1 shares next bar at market ;
pmm_set_global_named_num("num",0);
pmm_set_global_named_num("entry",-1);
end;
//进场
if value1=pmm_get_global_named_num("exit") then begin
Sell ( "MA2Cross_Exit" ) next bar at market ;
pmm_set_global_named_num("exit",-1);
end;
//出场
pmm_set_my_named_num("status",-1);
if marketposition=0 and condition1 then
pmm_set_my_named_num("status",0)
else if marketposition=1 and openentrydate(0)=date then
pmm_set_my_named_num("status",1)
else if marketposition=1 then
pmm_set_my_named_num("status",2);
{通过变量"status"来存储当前策略的状态}
if value1=pmms_strategies_count-1 then begin
value3=-1;
value4=-1;
value5=-1;
for value2=0 to pmms_strategies_count-1 begin
if pmms_get_strategy_named_num(value2,"status")=0 then
value3=value2
else if pmms_get_strategy_named_num(value2,"status")=2 then
value4=value2
else if pmms_get_strategy_named_num(value2,"status")=1 then
value5=value2;
end;
if value3<>-1 and value4<>-1 then begin
pmm_set_global_named_num("entry",value3);
pmm_set_global_named_num("exit",value4);
end
else if value3<>-1 and value5=-1 then
pmm_set_global_named_num("entry",value3);
end;
{在最后一个策略的执行的末尾对前期所有的策略进行遍历,将当前可以进场的股票的策略编号赋值给value3,并且存储到全局变量"entry“上;将当前可以出场的股票的策略编号赋值给value4,并且存储到全局变量”exit“上}
这里只是举个例子,通过双均线轮动选股,每天最多只交易一次(换股一次);当某个股票满足进场条件(若有若干个股票同时满足进场条件,那么会选择最后一个股票进场),即出现金叉时,并且当前有已有持仓的股票是可卖的或者当前无任何持仓股票,当这两个条件同时满足时(即一个股票满足进场,另一个股票满足出场)进行换股。图1. 股票投资组合换股
-
MC回复讨论一:
inputs: Price( Close ), FastLength( 9 ), SlowLength( 18 ) ;
variables: var0( 0 ), var1( 0 ) ;
once value1=pmms_strategies_get_by_symbol_name(getsymbolname);
{将当前策略的编号存储到变量value1上}
var0 = AverageFC( Price, FastLength ) ;
var1 = AverageFC( Price, SlowLength ) ;
if value1=0 then begin
if currentbar=1 or date[1]<>date then
pmm_set_global_named_num("num",1);
end;
{由于策略的执行是从策略编号0开始依次到最大策略编号,然后再循环执行,所以这里通过在策略编号为0时,对全局变量“num”进行赋值1,即当天可交易的次数}
condition1 = CurrentBar > 1 and var0 crosses above var1 ;
if pmm_get_global_named_num("num")=1 and value1=pmm_get_global_named_num("entry") then begin
Buy ( "MA2Cross_Long" ) 1 shares next bar at market ;
pmm_set_global_named_num("num",0);
pmm_set_global_named_num("entry",-1);
end;
//进场
if value1=pmm_get_global_named_num("exit") then begin
Sell ( "MA2Cross_Exit" ) next bar at market ;
pmm_set_global_named_num("exit",-1);
end;
//出场
pmm_set_my_named_num("status",-1);
if marketposition=0 and condition1 then
pmm_set_my_named_num("status",0)
else if marketposition=1 and openentrydate(0)=date then
pmm_set_my_named_num("status",1)
else if marketposition=1 then
pmm_set_my_named_num("status",2);
{通过变量"status"来存储当前策略的状态}
if value1=pmms_strategies_count-1 then begin
value3=-1;
value4=-1;
value5=-1;
for value2=0 to pmms_strategies_count-1 begin
if pmms_get_strategy_named_num(value2,"status")=0 then
value3=value2
else if pmms_get_strategy_named_num(value2,"status")=2 then
value4=value2
else if pmms_get_strategy_named_num(value2,"status")=1 then
value5=value2;
end;
if value3<>-1 and value4<>-1 then begin
pmm_set_global_named_num("entry",value3);
pmm_set_global_named_num("exit",value4);
end
else if value3<>-1 and value5=-1 then
pmm_set_global_named_num("entry",value3);
end;
{在最后一个策略的执行的末尾对前期所有的策略进行遍历,将当前可以进场的股票的策略编号赋值给value3,并且存储到全局变量"entry“上;将当前可以出场的股票的策略编号赋值给value4,并且存储到全局变量”exit“上}
这里只是举个例子,通过双均线轮动选股,每天最多只交易一次(换股一次);当某个股票满足进场条件(若有若干个股票同时满足进场条件,那么会选择最后一个股票进场),即出现金叉时,并且当前有已有持仓的股票是可卖的或者当前无任何持仓股票,当这两个条件同时满足时(即一个股票满足进场,另一个股票满足出场)进行换股。图1. 股票投资组合换股
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容