我使用IF THEN 语句对 BK4赋值, 但是输出结果BK4 一直是##, 这是为什么? 要怎样修改?
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15>-30 AND PV4 THEN BK4:=1;IF DIFF60<-30 AND DIFF15>-70 AND PV4 THEN BK4:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15>5 AND PV4 THEN BK4:=1;
## 说明是无效值。通常是定义改变量的条件没有满足或者是数值无效。你这里应该是条件没有满足吧。
你不妨把几个条件定义成变量输出看下呢。
你不妨把几个条件定义成变量输出看下呢。 我已经测试定义过了, 在条件都变成1的情况下, BK4:=1; 还是没有被赋值。? 我有十几条 IF THEN 语句对 BK4赋值,这个在语法上没有问题吧?
语法上你定义多少个IF...THEN 都没问题。
帖一段能重现这个现象的代码吧。另外你是shift+q查看变量还是把变量输出到文本了。
IF DIFFMON>-8 THEN BEGIN
IF DIFFWEEK>-200 THEN BEGIN
IF DIFFDAY>-10 THEN BEGIN
IF (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*12 AND 60MINMACD3NV距离>60*4*12 AND 60MIN量价NV3距离>60*4*12 AND 60MIN量价NV距离>60*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-10 AND DIFF15>-15 AND DIFF5>-7 AND PV3 THEN BK3:=1;
END
IF (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-10 AND DIFF15>-15 AND DIFF5>-7 AND PV4 THEN BK4:=1;
IF DIFF60>-10 AND DIFF15>-20 AND PV3 THEN BK3:=1;
END
IF (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-30 AND PV4 THEN BK4:=1;
IF DIFF60<-30 AND DIFF15>-70 AND PV4 THEN BK4:=1;
END
END
IF DIFFDAY>-30 AND DIFFDAY<=-10 THEN BEGIN
IF (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-30 AND DIFF15>-40 AND PV4 THEN BK4:=1; //此处用-40, 而没有用-30 是做一个缓冲
IF DIFF60>-30 AND DIFF15<=-40 AND DIFF15>-100 AND PV3 THEN BK3:=1;
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15>-30 AND PV4 THEN BK4:=1;
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15<=-30 AND DIFF15>-70 AND PV3 THEN BK3:=1;
END
IF
(60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-30 AND DIFF15>-30 AND PV3 THEN BK3:=1;
IF DIFF60>-30 AND DIFF15<=-30 AND DIFF15>-100 AND PV2 THEN BK2:=1;
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15>-30 AND PV3 THEN BK3:=1;
IF DIFF60<-30 AND DIFF15>-70 AND DIFF15<=-30 AND DIFF15>-70 AND PV2 THEN BK2:=1;
END
END
IF DIFFDAY>-150 AND DIFFDAY<=-30 THEN BEGIN
IF DIFF60>-30 AND DIFF15>0 AND PV4 THEN BK4:=1;
IF DIFF60>-30 AND DIFF15>-30 AND DIFF15<=0 AND (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌)AND PV4 THEN BK4:=1;
IF DIFF60>-30 AND DIFF15<=-30 AND DIFF15>-70 AND PV3 THEN BK3:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15>5 AND PV4 THEN BK4:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15>-20 AND DIFF15>0 AND PV4 AND (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) THEN BK4:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15<=-20 AND DIFF15>-70 AND PV3 THEN BK3:=1;
IF DIFF60<=-70 AND DIFF60>-150 AND DIFF15>-20 AND PV3 THEN BK3:=1;
IF DIFF60<=-70 AND DIFF60>-150 AND DIFF15<=-20 AND DIFF15>-70 AND PV2 THEN BK2:=1;
IF DIFF60<=-150 AND (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) AND PV2 THEN BK2:=1;
IF DIFF60<=-150 AND PV0 THEN BK1:=0;
END
END
END
IF DIFFMON<=-8 AND DIFFMON>-120 THEN BEGIN
IF DIFFWEEK>-50 THEN BEGIN
IF DIFFDAY>-150 AND PV1 THEN BK1:=1;
IF DIFFDAY<=-150 AND PV0 THEN BK0:=1;
END
IF DIFFWEEK<=-50 AND DIFFWEEK>-200 THEN BEGIN
IF DIFFDAY>-150 AND PV1 THEN BK1:=1;
IF DIFFDAY<=-150 AND (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) AND PV0 THEN BK0:=1;
END
END
IF DIFFMON<=-120 THEN BEGIN
IF DIFFWEEK>-50 AND DIFFDAY>-20 AND (60MINMACDNV距离>60*12*4 AND 60MIN量价NV距离>60*12 OR 价格背离后下跌) AND PV1 THEN BK1:=1;
IF DIFFWEEK>-50 AND DIFFDAY>-120 AND (60MINMACDNV距离>60*12*4 AND 60MIN量价NV距离>60*12 OR 价格背离后下跌) AND PV0 THEN BK0:=1;
IF DIFFWEEK<=-50 AND DIFFWEEK>-200 AND DIFFDAY>-20 AND (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) AND PV0 THEN BK0:=1;
END
你这个嵌套了很多if 的啊。如果要触发
BK4:=1; 的赋值操作。 离这个语句最近的if满足是不够的,它外面好几层的if对应的条件都要满足才行啊。
你这些语句里面最近的一个赋值
此主题相关图片如下:temp.png
也要满足五组条件才能执行到。
我即使满足所有条件测试test1和test2 , 都不能输出1.
if 1 then test1:=1;
IF (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) AND DIFFMON>-8 AND DIFFWEEK>-200 AND DIFFDAY>-10 AND DIFF60>-30 AND PV4 THEN TEST2:1;
test3:(60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) AND DIFFMON>-8 AND DIFFWEEK>-200 AND DIFFDAY>-10 AND DIFF60>-30 AND PV4;
con1:DIFF60>-10 AND DIFF15>-15 AND DIFF5>-7 AND PV4;
con2:DIFF60>-30 AND PV4;
IF DIFFMON>-8 THEN BEGIN
IF DIFFWEEK>-200 THEN BEGIN
IF DIFFDAY>-10 THEN BEGIN
IF (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*12 AND 60MINMACD3NV距离>60*4*12 AND 60MIN量价NV3距离>60*4*12 AND 60MIN量价NV距离>60*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-10 AND DIFF15>-15 AND DIFF5>-7 AND PV3 THEN BK3:=1;
END
IF (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-10 AND DIFF15>-15 AND DIFF5>-7 AND PV4 THEN BK4:=1;
IF DIFF60>-10 AND DIFF15>-20 AND PV3 THEN BK3:=1;
END
IF (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-30 AND PV4 THEN BK4:=1;
IF DIFF60<-30 AND DIFF15>-70 AND PV4 THEN BK4:=1;
END
END
IF DIFFDAY>-30 AND DIFFDAY<=-10 THEN BEGIN
IF (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-30 AND DIFF15>-40 AND PV4 THEN BK4:=1; //此处用-40, 而没有用-30 是做一个缓冲
IF DIFF60>-30 AND DIFF15<=-40 AND DIFF15>-100 AND PV3 THEN BK3:=1;
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15>-30 AND PV4 THEN BK4:=1;
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15<=-30 AND DIFF15>-70 AND PV3 THEN BK3:=1;
END
IF
(60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) THEN BEGIN
IF DIFF60>-30 AND DIFF15>-30 AND PV3 THEN BK3:=1;
IF DIFF60>-30 AND DIFF15<=-30 AND DIFF15>-100 AND PV2 THEN BK2:=1;
IF DIFF60<-30 AND DIFF60>-70 AND DIFF15>-30 AND PV3 THEN BK3:=1;
IF DIFF60<-30 AND DIFF15>-70 AND DIFF15<=-30 AND DIFF15>-70 AND PV2 THEN BK2:=1;
END
END
IF DIFFDAY>-150 AND DIFFDAY<=-30 THEN BEGIN
IF DIFF60>-30 AND DIFF15>0 AND PV4 THEN BK4:=1;
IF DIFF60>-30 AND DIFF15>-30 AND DIFF15<=0 AND (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌)AND PV4 THEN BK4:=1;
IF DIFF60>-30 AND DIFF15<=-30 AND DIFF15>-70 AND PV3 THEN BK3:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15>5 AND PV4 THEN BK4:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15>-20 AND DIFF15>0 AND PV4 AND (60MINMACDNV距离>60*4*12 AND 60MIN量价NV距离>60*4*12 OR 价格背离后下跌) THEN BK4:=1;
IF DIFF60<=-30 AND DIFF60>-70 AND DIFF15<=-20 AND DIFF15>-70 AND PV3 THEN BK3:=1;
IF DIFF60<=-70 AND DIFF60>-150 AND DIFF15>-20 AND PV3 THEN BK3:=1;
IF DIFF60<=-70 AND DIFF60>-150 AND DIFF15<=-20 AND DIFF15>-70 AND PV2 THEN BK2:=1;
IF DIFF60<=-150 AND (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) AND PV2 THEN BK2:=1;
IF DIFF60<=-150 AND PV0 THEN BK1:=0;
END
END
END
IF DIFFMON<=-8 AND DIFFMON>-120 THEN BEGIN
IF DIFFWEEK>-50 THEN BEGIN
IF DIFFDAY>-150 AND PV1 THEN BK1:=1;
IF DIFFDAY<=-150 AND PV0 THEN BK0:=1;
END
IF DIFFWEEK<=-50 AND DIFFWEEK>-200 THEN BEGIN
IF DIFFDAY>-150 AND PV1 THEN BK1:=1;
IF DIFFDAY<=-150 AND (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) AND PV0 THEN BK0:=1;
END
END
IF DIFFMON<=-120 THEN BEGIN
IF DIFFWEEK>-50 AND DIFFDAY>-20 AND (60MINMACDNV距离>60*12*4 AND 60MIN量价NV距离>60*12 OR 价格背离后下跌) AND PV1 THEN BK1:=1;
IF DIFFWEEK>-50 AND DIFFDAY>-120 AND (60MINMACDNV距离>60*12*4 AND 60MIN量价NV距离>60*12 OR 价格背离后下跌) AND PV0 THEN BK0:=1;
IF DIFFWEEK<=-50 AND DIFFWEEK>-200 AND DIFFDAY>-20 AND (60MINMACDNV距离>60*12 AND 60MINMACD2NV距离>60*4*12 AND 60MIN量价NV距离>60*12 AND 60MIN量价NV3距离>60*4*12 OR 价格背离后下跌) AND PV0 THEN BK0:=1;
END