以文本方式查看主题 - 金字塔客服中心 - 专业程序化交易软件提供商 (http://222.73.7.161/bbs/index.asp) -- 公式模型编写问题提交 (http://222.73.7.161/bbs/list.asp?boardid=4) ---- 变量赋值不成功 (http://222.73.7.161/bbs/dispbbs.asp?boardid=4&id=169468) |
-- 作者:m1978xz -- 发布时间:2019/4/19 19:21:37 -- 变量赋值不成功 下边这个公式中的czsc_high , czsc_low变量,在IF的条件满足时,也赋值不成功。始终是0. 拜托版主 帮看看问题在哪里。 QianH:=ref(h,1); QianL:=ref(L,1); s_czsc_high:QianH;//前一K线处理完包含关系之后的高,初值暂定为前K高 s_czsc_low:QianL;//前一K线处理完包含关系之后的低,初值暂定为前K低 s_direction:1; //前一K线的方向,应该有0,1,-1三个选项。 s_status:0; //包含 czsc_high:0;//当前K线高点,初值暂定为前K高 czsc_low:0; //当前K线低点,初值暂定为前K低 //分型 direction:0; ////当前K线方向,初值暂定为1 status:0; //当前K线的状态,是否为顶或者底,或者两者都不是。 f1:(s_czsc_high>0 or s_czsc_low>0); //如果前一缠K高>零,或者前一缠K高>0 f2:((s_czsc_high>High and s_czsc_low<Low) or (High>s_czsc_high and Low<s_czsc_low)); //如果前一缠K高>本K高,同时前一缠K低<本k低,或者(本K高>前一缠K高,同时本K低<前一缠K低) f3:s_direction>0;//如果前一K线方向大于0 If f1 and f2 and f3 then begin direction:=1; status:=0; czsc_high:=Max(s_czsc_high,High); czsc_low:=Max(s_czsc_low,Low); end
|
-- 作者:FireScript -- 发布时间:2019/4/22 9:12:52 -- 我本地试了,代码正常啊,该有值的时候就有值。你什么模式运行的呢,逐K还是序列呢。 |
-- 作者:m1978xz -- 发布时间:2019/4/22 9:18:16 -- 序列计算模式,我不知道这种代码应该用哪个模式才对。感谢版主回复。 周末您那边不上班的时候,我反复把整个代码梳理了。。。 问题 还是:czsc_high和 czsc_low这两个变量一直是0.实在不知道问题出在哪里 ![]() 完整代码如下: QianH:=ref(h,1); QianL:=ref(L,1); direction:0; ////当前K线方向,初值暂定为1 status:0; //当前K线的状态,是否为顶或者底,或者两者都不是。 s_direction:ref(direction,1); //前一K线的方向,应该有0,1,-1三个选项。 s_status:ref(status,1),NOAXIS; czsc_high:0;//当前K线高点,初值暂定为前K高 czsc_low:0; //当前K线低点,初值暂定为前K低 s_czsc_high:ref(czsc_high,1);//前一K线处理完包含关系之后的高,初值暂定为前K高 s_czsc_low:ref(czsc_low,1);//前一K线处理完包含关系之后的低,初值暂定为前K低 //分型 f1:(s_czsc_high>0 or s_czsc_low>0); //如果前一缠K高>零,或者前一缠K高>0 f2:((s_czsc_high>High and s_czsc_low<Low) or (High>s_czsc_high and Low<s_czsc_low)); //如果前一缠K高>本K高,同时前一缠K低<本k低,或者(本K高>前一缠K高,同时本K低<前一缠K低) f3:s_direction>0;//如果前一K线方向大于0 f4:s_direction<0;//如果前一K线方向<0 f5:s_direction>0; f6:High<s_czsc_high; f7:s_direction<0; f8:Low>s_czsc_low; f9:((High>ref(h,1) and Low<ref(L,1)) or (ref(h,1)>High and ref(L,1)<Low)); f10:ref(H,1)>ref(H,2); f11:ref(L,2)>ref(L,1); f12:ref(H,2)<ref(H,1); f13:ref(H,1)>High; f14:ref(L,2)>ref(L,1); f15:ref(L,1)<Low;//当前K线状态(0.表示延续方向 1.表示K线转变方向) ///---------------第一组判断开始 If f1 and f2 and f3 then begin //如果前高大于零或者前低大于零 IF1 //存在缠中说禅K线的 direction=1; status=0; czsc_high=Max(s_czsc_high,High); czsc_low=Max(s_czsc_low,Low); end //对应IF3 //更新最高点和最低点 If f1=1 and f2=1 and f3=0 and f4=1 then begin direction=-1; status=0; czsc_high=Min(s_czsc_high,High); czsc_low=Min(s_czsc_low,Low); end//对应IF4 ///---------------第二组判断开始 If f1=1 and f2=0 and f5=1 and f6=1 then begin //如果前高大于零或者前低大于零 IF1 //不存在包含关系 direction=-1; status=1; czsc_high=High; czsc_low=Low; end If f1=1 and f2=0 and f5=1 and f6=0 then begin //如果前高大于零或者前低大于零 IF1 //不存在包含关系 direction=1; status=0; czsc_high=Max(s_czsc_high,High); czsc_low=Max(s_czsc_low,Low); end ///---------------第三组判断开始 If f1=1 and f2=0 and f5=0 and f7=1 and f8=1 then begin direction=1; status=1; czsc_high=High; czsc_low=Low; end If f1=1 and f2=0 and f5=0 and f7=1 and f8=0 then begin direction=-1; status=0; czsc_high=min(s_czsc_high,High); czsc_low=min(s_czsc_Low,Low); end ///---------------第四组判断开始 ,从这里 开始f1为0了 If f1=0 and f9=1 and f10=1 then begin direction=1; status=0; czsc_high=Max(QianH,High); czsc_low=Max(QianL,Low); end If f1=0 and f9=1 and f10=0 and f11=1 then begin //判断方向 direction=-1; status=0; czsc_high=Min(QianH,High); czsc_low=Min(QianL,Low); end ///---------------第五组判断开始 If f1=0 and f9=0 and f12=1 and f13=1 then begin direction=-1; status=1; czsc_high=High; czsc_low=Low; end If f1=0 and f9=0 and f12=1 and f13=0 then begin direction=1; status=0; czsc_high=Max(QianH,High); czsc_low=Max(QianL,Low); end ///---------------第六组判断开始 If f1=0 and f9=0 and f12=0 and f14=1 and f15=1 then begin direction=1; status=1; czsc_high=High; czsc_low=Low; end If f1=0 and f9=0 and f12=0 and f14=1 and f15=0 then begin direction=-1; status=0; czsc_high=Min(QianH,High); czsc_low=Min(QianL,Low); end STICKLINE(czsc_low>0 and czsc_high>0,czsc_low,czsc_high,0.8,1),colorYellow; //输出缠中说禅K线 |
-- 作者:m1978xz -- 发布时间:2019/4/22 9:21:51 -- direction和 status也一直是零。也就是说这些IF语句的判断根本没效果。 |
-- 作者:FireScript -- 发布时间:2019/4/22 9:44:02 -- 用逐K模式。逐K和序列在if上的处理有差异,通常我们使用if时候都用逐K模式。 |
-- 作者:m1978xz -- 发布时间:2019/4/22 9:47:23 -- 换成逐K线试过也不行。不管勾选不勾选那个只刷新最后一根K线。 而且我发现主图上方有这样的提示,不知道啥意思。
|
-- 作者:m1978xz -- 发布时间:2019/4/22 9:55:06 -- 貌似只有看股票行情才会出那2个≠,那个不是重点。我平时只做期货。 关键是那4个变量是这个指标的关键。所有的IF都是为了改变这4个变量。 我想是不是我的IF语句语法有问题,或者这些变量需要申明为:variable全局变量?
|
-- 作者:FireScript -- 发布时间:2019/4/22 10:11:23 -- 不需要。你修改模式之后重新应用到图上试下。你是不是没有重新应用到图上? 代码原封不动,我只改了变量输出,方便查看。
|
-- 作者:m1978xz -- 发布时间:2019/4/22 10:22:28 -- 应用于图了。而且请您试下我在3楼发的完整代码。 您的截图上的显示的那些变量并不全是我说有问题 的4个变量。 [此贴子已经被作者于2019/4/22 10:23:56编辑过]
|
-- 作者:FireScript -- 发布时间:2019/4/22 10:42:32 -- 看了下,是你后面代码里面重新给变量赋值了啊。 你这里有好几组变量赋值的判断。前面三个F的条件满足了,如果后面的也满足了。可能就会重新赋值了。 |