以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  策略信号混乱的问题  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=168773)

--  作者:天天涨停
--  发布时间:2019/3/14 16:06:48
--  策略信号混乱的问题

input:initialstop(20,10,60,10);
input:breakvenstop(20,10,60,10);
input:trailingstop(30,10,60,10);
input:money(2,1,10,1);
variable:stopline:=0;

begin
 
//predayhigh:=callstock(stklabel,vthigh,6,-1);//昨高
//predaylow:=callstock(stklabel,vtlow,6,-1);//昨低
//predayopen:=callstock(stklabel,vtopen,6,0);//昨收
//上轨:昨高;
//下轨:昨低;
//手数:=SS;

dist1:=barslast(day <> ref(day,1))+1;
dist2:=ref(dist1,dist1);
predayhigh:=ref(hhv(high,dist2),dist1);
predaylow:=ref(llv(low,dist2),dist1);
predayopen:= ref(open,dist1-1);

entrytime:=time>=0916000 and time<=144500;
exittime:time>=150000;

initialstopnum:=mindiff*initialstop;
breakvenstopnum:=mindiff*breakvenstop;
 trailingstopnum:=mindiff*trailingstop;
marginratio:=18/100;  
 
end
  
if holding=0 then begin
 if predayopen<predayhigh and entrytime and high>=predayhigh+mindiff then
 myentryprice:=max(open,predayhigh+mindiff);
 mycash:=cash(0);
 lots1:=intpart(mycash/(myentryprice*multiplier*marginratio));
 lots2:=intpart((mycash*money/100)/(initialstopnum*multiplier));
 lots:=min(lots1,lots2);
  buy(1,lots,limitr,myentryprice);
 stopline:=0;
 end 
 
 if holding=0 then begin  
  if predayopen>predaylow and entrytime and low<=predaylow - mindiff then
   myentryprice:=max(open,predayhigh-mindiff);
  mycash:=cash(0);
  lots1:=intpart(mycash/(myentryprice*multiplier*marginratio));
   lots2:=intpart((mycash*money/100)/(initialstopnum*multiplier));
   lots:=min(lots1,lots2);
    BUYSHORT(1,lots,limitr,myentryprice);
 stopline:=0;
end 

if holding>0 then begin
 costprice:=enterprice+mindiff;
 
 if exittime then
 sell(1,holding,limitr,open);
end    
 if stopline>0 and low<=stopline then
 sell(1,holding,limitr,min(open,stopline));
 
 if stopline=0 then begin
  stopline:=enterprice-initialstopnum;
    
    if stopline<costprice and high- breakvenstopnum>=costprice then
         stopline:=costprice;
   
    if stopline>=costprice and high-trailingstopnum>=stopline then
        stopline:=high-trailingstopnum;
  end
 
 if holding<0 then begin
 costprice:=enterprice-mindiff;
  
 if exittime then
 sellshort(1,holding,limitr,open);
 
 if stopline>0 and high>=stopline then
 sellshort(1,holding,limitr,max(open,stopline));
 
 if stopline=0 then
  stopline:=enterprice+initialstopnum;
   
    if stopline>costprice and low+breakvenstopnum<=costprice then
    stopline:=costprice;
   
    if stopline<costprice and low+trailingstopnum<=stopline then
        stopline:=low+trailingstopnum;
           
    end  


--  作者:天天涨停
--  发布时间:2019/3/14 16:10:29
--  

老师,我这个策略信号乱了,我不知道是哪的原因,帮我看一下,谢谢

input:initialstop(20,10,60,10);
input:breakvenstop(20,10,60,10);
input:trailingstop(30,10,60,10);
input:money(2,1,10,1);
variable:stopline:=0;

begin
 
//predayhigh:=callstock(stklabel,vthigh,6,-1);//昨高
//predaylow:=callstock(stklabel,vtlow,6,-1);//昨低
//predayopen:=callstock(stklabel,vtopen,6,0);//昨收
//上轨:昨高;
//下轨:昨低;
//手数:=SS;

dist1:=barslast(day <> ref(day,1))+1;
dist2:=ref(dist1,dist1);
predayhigh:=ref(hhv(high,dist2),dist1);
predaylow:=ref(llv(low,dist2),dist1);
predayopen:= ref(open,dist1-1);

entrytime:=time>=0916000 and time<=144500;
exittime:time>=150000;

initialstopnum:=mindiff*initialstop;
breakvenstopnum:=mindiff*breakvenstop;
 trailingstopnum:=mindiff*trailingstop;
marginratio:=18/100;  
 
end
  
if holding=0 then begin
 if predayopen<predayhigh and entrytime and high>=predayhigh+mindiff then
 myentryprice:=max(open,predayhigh+mindiff);
 mycash:=cash(0);
 lots1:=intpart(mycash/(myentryprice*multiplier*marginratio));
 lots2:=intpart((mycash*money/100)/(initialstopnum*multiplier));
 lots:=min(lots1,lots2);
  buy(1,lots,limitr,myentryprice);
 stopline:=0;
 end 
 
 if holding=0 then begin  
  if predayopen>predaylow and entrytime and low<=predaylow - mindiff then
   myentryprice:=max(open,predayhigh-mindiff);
  mycash:=cash(0);
  lots1:=intpart(mycash/(myentryprice*multiplier*marginratio));
   lots2:=intpart((mycash*money/100)/(initialstopnum*multiplier));
   lots:=min(lots1,lots2);
    BUYSHORT(1,lots,limitr,myentryprice);
 stopline:=0;
end 

if holding>0 then begin
 costprice:=enterprice+mindiff;
 
 if exittime then
 sell(1,holding,limitr,open);
end    
 if stopline>0 and low<=stopline then
 sell(1,holding,limitr,min(open,stopline));
 
 if stopline=0 then begin
  stopline:=enterprice-initialstopnum;
    
    if stopline<costprice and high- breakvenstopnum>=costprice then
         stopline:=costprice;
   
    if stopline>=costprice and high-trailingstopnum>=stopline then
        stopline:=high-trailingstopnum;
  end
 
 if holding<0 then begin
 costprice:=enterprice-mindiff;
  
 if exittime then
 sellshort(1,holding,limitr,open);
 
 if stopline>0 and high>=stopline then
 sellshort(1,holding,limitr,max(open,stopline));
 
 if stopline=0 then
  stopline:=enterprice+initialstopnum;
   
    if stopline>costprice and low+breakvenstopnum<=costprice then
    stopline:=costprice;
   
    if stopline<costprice and low+trailingstopnum<=stopline then
        stopline:=low+trailingstopnum;
           
    end  



图片点击可在新窗口打开查看此主题相关图片如下:52.png
图片点击可在新窗口打开查看

--  作者:FireScript
--  发布时间:2019/3/14 16:17:46
--  
 开仓价格超出下单K的范畴,所以都会显示成白色箭头。
建议调整价格或者在开平仓语句后面加一个IGNORECHECKPRICE:
buy(...),IGNORECHECKPRICE

--  作者:天天涨停
--  发布时间:2019/3/14 16:26:38
--  

老师,我加进去了,白色的箭头没有了,但没有任何信号。这个策略是根据视频教程讲的菲阿里四价策略记录的笔记,为什么不执行的,我弄不了。


--  作者:FireScript
--  发布时间:2019/3/14 16:56:19
--  
 根据报错是下单参数问题。我输出了下单手数变量,是下单参数计算出来的结果太大。实际资金根本不足以下那么多手数。