欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → While do 语句的问题

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有3274人关注过本帖树形打印复制链接

主题:While do 语句的问题

帅哥哟,离线,有人找我吗?
m1978xz
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:193 积分:0 威望:0 精华:0 注册:2018/12/18 15:40:26
While do 语句的问题  发帖心情 Post By:2019/4/28 6:57:51    Post IP:123.168.88.72[只看该作者]

在下边这个代码中,主图上i的值一直是50.While do 应该是往前回溯的吧?从最近一根K线开始,本K线i=0,然后每往前走i+1
请版主帮看看我这个代码中.循环部分i为啥一直都是50.

或者有啥办法可以 不用while do函数,可以用别的函数实现这个功能。
我看http://www.weistock.com/bbs/dispbbs.asp?BoardID=4&ID=162309&replyID=481423&skin=1
这个页面里版主说可以不用这个函数。


QianH:=ref(h,1);
QianL:=ref(L,1);
VARIABLE:direction:=0;       ////当前K线方向,初值暂定为1
VARIABLE:status:=0;  //当前K线的状态,是否为顶或者底,或者两者都不是。
s_direction:ref(direction,1);  //前一K线的方向,应该有0,1,-1三个选项。
s_status:=ref(status,1);
VARIABLE:czsc_high:=0;//当前K线高点,初值暂定为前K高
VARIABLE: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,3,1),colorYellow;                                                                                                                      //输出缠中说禅K线
i:0;//i是序列值,在循环语句中,每个循环会+1. 
VARIABLE:pen:=0;//当前笔
s_direction_2:=ref(direction,2);
s_pen:ref(pen,1); ;//前一笔  
s_czsc_high_1:=ref(s_czsc_high,1);    
s_czsc_high_i:=ref(s_czsc_high,(i+2));  
s_czsc_low_i:=ref(s_czsc_low,(i+2)); 
s_czsc_low_2:=ref(s_czsc_low,2); 
        
fb1:=s_status=0;
fb1_1:=i<50;
fb2:=s_pen=11 or s_pen=-11;
fb3:=s_pen=10 or s_pen=-10;
fb4:=s_direction>0;
fb5:=i<3;
fb6:=s_direction=1 and s_pen=11;
fb7:=ref(s_czsc_low,1)<ref(s_czsc_low,(i+2));
fb8:=s_direction=-1 and s_pen=-11;
fb9:=s_czsc_high_1>s_czsc_high_i;
fb10:=s_direction>0;
fb11:=s_czsc_high_1<s_czsc_low_i;
fb12:=s_czsc_low_2>s_czsc_high_i;
               
    //第一组    
        If fb1 then begin    //如果前一K线不是顶或者底儿
            pen:=s_direction*10; //赋值pen为前K方向值乘以10.因为s_direction初值为0.所以第一根K线判定时,pen也为0,pen为当前K线所在的趋势。
            //但最迟第三根K线开始s_direction就为1或者-1,所以pen的值也成为10或者-10.
            i=0;
            end
            
        While  i<50 do begin 
        If fb1=0 and (s_pen=11 or s_pen=-11) then  BREAK;
        i:=i+1; 
          end  //回溯50个处理完包含关系到K线,直至符合条件中断(50可根据周期自定义)  
          //第二组 
        If fb1=0 and fb3 and fb4 then begin            //如果回溯50个仍没符合条件的则延续状态
                    pen:=s_direction*10+s_status;
                    DRAWTEXT(h>0,l-4,'d1'),colorwhite;
                    i=0;
                    ll:=s_czsc_low;//原文是l,但是l是保留字,所以改成了ll
              end  
      //第三 组
        If fb1=0 and fb3=0 and fb4=0 then begin    
                    pen:=s_direction*10-s_status;
                    DRAWTEXT(h>0,H+4,'g1'),colorwhite;
                    i=0;
                    u:=s_czsc_high;
              end  
       //第四组       
        If fb1=0 and fb3=0 and fb5 then begin         
                    pen:=s_direction_2*10;
               end
       //第五组   
        If fb1=0 and fb3=0 and fb5=0 and fb6 and fb7 then begin         
             pen:=s_direction*10+s_status;
              DRAWTEXT(h>0,l-4,'d2'),colorwhite;
             p:=s_czsc_low;
               end
       //第六组   
        If fb1=0 and fb3=0 and fb5=0 and fb6 and fb7=0 then begin         
             pen:=s_direction_2*10;
                end
       //第七组  
        If fb1=0 and fb3=0 and fb5=0 and fb6=0 and fb8 and fb9 then begin     
        pen:=s_direction*10-s_status;
            DRAWTEXT(h>0,H+4,'g2'),colorwhite;
            u:=s_czsc_high;
            p:=s_czsc_high;
                end
     //第八组 
         If fb1=0 and fb3=0 and fb5=0 and fb6=0 and fb8 and fb9=0 then begin 
             pen:=s_direction_2*10;
                end  
     //第九组 
         If fb1=0 and fb3=0 and fb5=0 and fb6=0 and fb8=0 and fb10 and fb11 then begin  
          pen:=s_direction*10+s_status;
            DRAWTEXT(h>0,l-4,'d3'),colorwhite;
            ll:=s_czsc_low;
            p:=s_czsc_low;
                end
     //第十组 
         If fb1=0 and fb3=0 and fb5=0 and fb6=0 and fb8=0 and fb10 and fb11=0 then begin  
          pen:=s_direction_2*10; 
              end
     //第十一组 
         If fb1=0 and fb3=0 and fb5=0 and fb6=0 and fb8=0 and fb10=0 and fb12 then begin  
          pen:=s_direction*10-s_status;
             DRAWTEXT(h>0,H+4,'g3'),colorwhite;
             u:=s_czsc_high;
             p:=s_czsc_high;
              end     
     //第十二组 
      If fb1=0 and fb3=0 and fb5=0 and fb6=0 and fb8=0 and fb10=0 and fb12=0 then begin 
             pen:=s_direction_2*10; 
              end



                
          

[此贴子已经被作者于2019/4/28 6:59:32编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
wenarm
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:26632 积分:0 威望:0 精华:7 注册:2015/4/9 14:59:07
  发帖心情 Post By:2019/4/28 9:23:55    Post IP:180.169.30.6[只看该作者]

如果说k线的在时间轴上是横向的循环的话。你自己的策略在每根k上的循环就是纵向的。

最终得到的结果肯定是纵向循环中的最后一个值。

所以你的循环在k线上根本没有意义。



编程无捷径,技巧靠积累。
 回到顶部
帅哥哟,离线,有人找我吗?
m1978xz
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:193 积分:0 威望:0 精华:0 注册:2018/12/18 15:40:26
  发帖心情 Post By:2019/4/28 9:33:35    Post IP:123.168.88.72[只看该作者]

版主~那我如果不用while这个函数。用if怎么来 描述啊?

我想实现的是,i=0,如果前一根根线上的pen这个变量如果不是10或者-10,就i+1,
直到回溯到前边的第N个 K 线上的pen这个值是10或者-10为之。

i就用于记录从目前的K线到那根满足条件的K线距离是几。

 回到顶部
帅哥哟,离线,有人找我吗?
yukizzc
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:21598 积分:0 威望:0 精华:1 注册:2010/7/31 16:35:30
  发帖心情 Post By:2019/4/28 10:33:02    Post IP:180.169.30.6[只看该作者]

你要在现在的k复合条件的情况下,去改变历史上k的变量的值??
这种带有未来操作的,在程序化中不好用的

 回到顶部
帅哥哟,离线,有人找我吗?
m1978xz
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:193 积分:0 威望:0 精华:0 注册:2018/12/18 15:40:26
  发帖心情 Post By:2019/4/28 10:44:09    Post IP:123.168.88.72[只看该作者]

嗯。我用于缠论分笔 。要确定每笔至少有7根K线也就是每个分型3根,一个顶分型和一个底分型中间夹一根。

图片点击可在新窗口打开查看此主题相关图片如下:qq截图20190428104234.png
图片点击可在新窗口打开查看
比如我现在用的策略就是这样的。在 图中1的地方做空或者平多,在图中2的地方做多或者平空。图中最后的部分就已经在那里平空了。

不过这个图中的策略使用的函数是买来的,加密的。我现在想自己试着写出来替代它。要不没法优化升级。


 回到顶部
帅哥哟,离线,有人找我吗?
FireScript
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:14496 积分:0 威望:0 精华:0 注册:2017/7/4 13:40:18
  发帖心情 Post By:2019/4/28 11:02:57    Post IP:180.169.30.6[只看该作者]

 你仔细看下你的循环。你每个K上都会循环一次的,所以如果循环后面没有对i再次赋值处理,那每个K上的I最终值都是50.
While do 应该是往前回溯的” 这个不是回溯,就是单个K数据上的一个内部循环计算。


命数如织,当如磐石。
 回到顶部
帅哥哟,离线,有人找我吗?
m1978xz
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:193 积分:0 威望:0 精华:0 注册:2018/12/18 15:40:26
  发帖心情 Post By:2019/4/28 11:21:25    Post IP:123.168.88.72[只看该作者]

那往前回溯应该用什么函数啊?

比如我之前看过一个类似的代码貌似是之前的版主阿火写的。首先他先求从目前这根K线往前20根K线的最高值。
然后看往前第几根K线的H等于这个最高值。然后求出目前K至那根K线的距离。貌似有个专门的函数就是干这个用的。\

那我现在的需求和那个类似,我这个相当于求之前第几根K线上的pen这个变量的值是10或者-10.
如果是就停止,不是就继续往前步进。每步进一根K线就i+1.
如果前边第5根K线上的pen这个变量的值是10或者-10.就跳出循环了。i上的值就是5
如果往前走50根都没pen这个变量的值是10或者-10.i上的值就是50。

 回到顶部
帅哥哟,离线,有人找我吗?
FireScript
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:14496 积分:0 威望:0 精华:0 注册:2017/7/4 13:40:18
  发帖心情 Post By:2019/4/28 14:55:22    Post IP:180.169.30.6[只看该作者]

 是啊,的确有个函数就是这样的:
HHVBARS
LLVBARS

你这个需求可以这样子:
i:=if(BARSLAST(pen=10)<=50,BARSLAST(pen=10),50);

核心是BARSLAST(pen=10) ,if语句那个只是处理上次满足条件大于50的情况,这个是你上面需求里的逻辑。


命数如织,当如磐石。
 回到顶部
帅哥哟,离线,有人找我吗?
m1978xz
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游侠 帖子:193 积分:0 威望:0 精华:0 注册:2018/12/18 15:40:26
  发帖心情 Post By:2019/4/28 15:13:02    Post IP:123.168.88.72[只看该作者]

感谢版主指导。我好好理解下。


 回到顶部