金字塔决策交易系统

标题: 关于全局变量的编写 [打印本页]

作者: 山水不惑    时间: 2025-1-10 08:56
标题: 关于全局变量的编写
使用全局变量,编写连续盈利中的第几次加仓,怎么编写?

作者: 技术008    时间: 2025-1-10 09:02
你这个具体是什么样的逻辑呢
什么教连续盈利中第几次加仓
作者: 山水不惑    时间: 2025-1-10 13:35
技术008 发表于 2025-1-10 09:02
你这个具体是什么样的逻辑呢
什么教连续盈利中第几次加仓

比如假设我有可能连续盈利5次,但是默认都是开1手仓。如果想在连续盈利2次后,开仓的时候开2手,而不是开1手。
作者: 技术006    时间: 2025-1-10 13:54
本帖最后由 技术006 于 2025-1-10 13:59 编辑

https://www.weistock.com/docs/PE ... 8F%98%E9%87%8F.html
这里有全局变量的一些应用的方法。
大致的处理逻辑如下,使用全局变量记录盈利的次数即可。
variable:num=0;

ma5:ma(close,5);
ma20:ma(close,20);
cond1:=cross(ma5,ma20);
cond2:=cross(ma20,ma5);

//根据统计的连续盈利的次数判断,当大于等于2次以上时,按2手下单。
ss:IF(NUM>=2,2,1);

if cond1 and holding=0 then
begin
        buy(1,ss,market);
end

if cond2 and holding>0 then BEGIN
        sell(1,ss,market);
        //判断当前平仓是否盈亏,盈亏+1,不盈利置0.
        if NUMPROFIT(1)>0 then
                num:=num+1;
        else
                num:=0;
        
end
aaa:NUMPROFIT(1);

作者: 技术009    时间: 2025-1-10 13:56
[PEL] 复制代码
variable:mark:=0;//使用全局变量进行记录


kd:TODAYBAR=3;
pd:TODAYBAR=5;

ss:=1;

if pd and holding>0 then
begin
sell(1,holding,market);
//平仓一次算一次盈亏
if numprofit(1)<0 then mark:=0;
if numprofit(1)>0 then mark:=mark+1;   
end
  
if kd and holding=0 then
begin
//连盈大于2次,2倍初始手数开仓
buy(1,if(mark>=2,2*ss,ss),market);   
end


连盈次数:mark;

作者: 山水不惑    时间: 2025-1-10 13:59
技术006 发表于 2025-1-10 13:54
大致的处理逻辑如下,使用全局变量记录盈利的次数即可。
variable:num=0;

谢谢,原来有这个现成函数,没发现,被我想复杂了。
作者: 无为上善若水    时间: 2025-1-12 08:31
如果盈利大于 20000 ,加仓怎么写
作者: 山水不惑    时间: 2025-1-12 11:25
无为上善若水 发表于 2025-1-12 08:31
如果盈利大于 20000 ,加仓怎么写

OPENPROFIT>20000




欢迎光临 金字塔决策交易系统 (https://www.weistock.com/BBS/) Powered by Discuz! X3.4