1.建议在模拟上先测试下程序逻辑
2.后台程序化的操作不同于图表程序化,建议先看下帮助说明:https://www.weistock.com/docs/HE ... BA%8F%E5%8C%96.html
3.你这种半自动的,除了初始开仓之外最好不要有其他的手工干预。否则程序是无法知晓你手工操作了什么的。
[PEL] 复制代码
if not(TACCOUNT(53)) then exit;//账户没登陆直接退出
inital_str:stklabel&'_lots';//记录初始持仓数量的全局变量字符串变量
base_str:stklabel&'_lots';//记录初始基准价的全局变量字符串变量
全部持仓:tbuyholdingex('','',2);
可用:tbuyholdingex('','',1);
initial_lots:=extgbdata(inital_str);//读值
if tbuyholdingex('','',2)<>0 and initial_lots=0 and tglobalsubmitex(0,'','',0)=0 then
begin
extgbdataset(inital_str,全部持仓); // 记录初始买入量
extgbdataset(base_str,callstock('',vtclose,6,-1));//记录基准价
end
if tbuyholdingex('','',2)=0 and initial_lots<>0 then
begin
extgbdataset(inital_str,0);
extgbdataset(base_str,0);
end
initial_lots:=extgbdata(inital_str);//初始持仓量
基准价:=extgbdata(base_str);//基准价格
涨幅:=(close / 基准价 - 1);//基于基准价的涨幅
跌幅:=(1 - close / 基准价);
if time>=093500 and time<=145500 then
begin
// 卖出条件1:价格上涨8%,卖出一半持仓,仅执行一次
if 可用 > 0 and 涨幅>= 0.08 and 涨幅<0.2 and 基准价>0 and 可用 = initial_lots then
begin
tsell(1, initial_lots / 2, mkt);
end
// 卖出条件2:价格上涨20%以上,卖出全部持仓
if 可用> 0 and 涨幅>= 0.2 then
begin
tsell(1,0, mkt);
extgbdataset(inital_str,0);// 清空初始持仓量
extgbdataset(base_str,0);
end
// 卖出条件3:价格下跌8%,卖出全部持仓
if 可用> 0 and 跌幅>= 0.08 then
begin
tsell(1, 0, mkt);
extgbdataset(inital_str,0);
extgbdataset(base_str,0);
end
end
|