金字塔决策交易系统

 找回密码
 

微信登录

微信扫一扫,快速登录

搜索
12
返回列表 发新帖
楼主: PIN

求助:股票日内策略代码实现

[复制链接]

33

主题

145

帖子

145

积分

等级: 免费版

注册:
2023-10-12
曾用名:
 楼主| 发表于 2023-10-25 17:22 | 显示全部楼层
只需要执行掉先产生的那个就行了
回复

使用道具 举报

21

主题

1万

帖子

1万

积分

Rank: 8Rank: 8

等级: 超级版主

注册:
2021-5-18
曾用名:
FireScript
发表于 2023-10-26 13:56 | 显示全部楼层
[PEL] 复制代码
variable:firsthd:=0;//初始底仓
variable:iszy:=0;//标记是否止盈了
variable:fx:=0;//记录最近一次操作的方向 .1 是加仓,-1是减仓

if todaybar=1 and holding<>0 then firsthd:=holding;//始终在每天开始时候更新 初始底仓

if todaybar=1  then //始终在每天开始时候更新 全局变量记录
begin 
iszy:=0;
fx:=0;
end 

ma5:=ma(c,5);
ma120:=ma(c,120);
//底仓逻辑
if holding=0 and cross(ma5,ma120) and iszy=0 then
begin 
buy(1,1000,market);
firsthd:=holding;//首次底仓的赋值
end 

s1:=0.5*firsthd;//提前计算好按照初始仓位百分比的加减仓手数
s2:=0.1*firsthd;


o1:=callstock('',vtopen,6,0);//当日开盘价
ozd:100*(c-o1)/o1;//基于开盘价的涨跌幅

v1:=ozd-fracpart(ozd);
if v1>=3 and fx=0 then fx:=-1;
if v1<=-3 and fx=0 then fx:=1;


tcd:=time<145600;//时间限制

//减仓
if  fx=-1 and iszy=0 and tcd then 
begin 
hdx:=firsthd-s1-(v1-3)*s2;//根据当前涨跌幅计算当前应该有的仓位情况
if holding>hdx and hdx>=0 then 减仓:sell(1,holding-hdx,market);	
		
end 

//加仓,加仓上限默认不超过总仓位,否则收盘无法平到初始仓位的程度
if  fx=1  and iszy=0 and tcd then 
begin 
hdx:=firsthd+s1-(v1+3)*s2;
if holding<hdx and hdx<=2*firsthd  then 加仓:buy(1,hdx-holding,market);		
end 

老仓:holding-dayholding,nodraw;
浮动盈亏:if(avgenterprice<>0,c/avgenterprice,0);

if c/avgenterprice>=1.05 and 老仓>0 and iszy=0 and tcd then 
begin 
止盈:sell(1,老仓,market);
iszy:=1;
end 

if not(tcd) and  holding<>firsthd  then 
begin 
if holding-firsthd>0 and holding-dayholding>0 then 收盘减仓:sell(1,holding-firsthd,market);
if firsthd-holding>0 then 收盘补仓:buy(1,firsthd-holding,market);	
end 


持仓:holding,nodraw;


供参考
金字塔提供一对一VIP专业技术指导服务,技术团队实时响应您的日常使用问题与策略编写。联系电话:021-20339086
回复

使用道具 举报

33

主题

145

帖子

145

积分

等级: 免费版

注册:
2023-10-12
曾用名:
 楼主| 发表于 2023-10-26 14:05 | 显示全部楼层
收到,感谢,我研究一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 微信登录

本版积分规则

手机版|小黑屋|上海金之塔信息技术有限公司 ( 沪ICP备13035422号 )

GMT+8, 2025-8-1 07:33 , Processed in 0.138796 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表