以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  麻烦老师能把以下SAR指标改成以收盘价突破转向吗  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=184967)

--  作者:300qh
--  发布时间:2021/3/31 12:40:32
--  麻烦老师能把以下SAR指标改成以收盘价突破转向吗

麻烦老师能把以下SAR指标改成以收盘价突破转向吗

//-------------------------------------------------------------------

INPUT:CYC(10,1,100,2);
RUNMODE:0; //使用逐周期运行模式

 

//保证variable声明的变量都尽量在公式的最前面,防止带有IF语句的分支执行影响变量的初始化
variable:Step = 2 / 100; //步长
variable:fMax = 20 / 100; //最大值

 

variable:sarx=0;
variable:Trend=0;
variable:EP=0;
variable:AF=0;

 

//计算高点低点的值放到IF前面,防止前面语句直接退出导致最前CYC个周期的数据无法统计到
highprice:=ref(hhv(high,cyc),1);
lowPrice:=ref(llv(low,cyc),1);

 

原始SAR:SAR(10,2,20);

 

if barpos <= Cyc then
 exit;//不到CYC的统计周期,直接退出等待下个周期再做判断

if barpos = cyc+1 then
begin
 af:=Step;
 ep:=-1;
 if (high[barpos]-high[barpos-1])+(low[barpos]-low[barpos-1]) > 0 then
 begin
  //看跌
  Trend:= -1;
  sarx:=highprice;
 end
 else
 begin
  //看涨
  Trend:= 1;
  sarx:=lowPrice;
 end
 GOTO ENDANDSHOW;//跳转到末尾直接显示
End

//判断出这些日子数据的上涨,或者下跌
if Trend > 0 then
begin
 //是否为跳转标志
 if ep > 0 then
 begin
  sarx:=lowPrice;
  EP:=-1;
  GOTO ENDANDSHOW;//跳转到末尾直接显示
 end
 
 //如果今日最高价大于前N的最高价,加速因子需要增加
 if high > highprice then
 begin
  af := af+step;
  if af > fmax then
    af := fmax;
 end
 
 fsar := sarx + af * (highprice - sarx);
 //是否跳转
 if fsar > low then
 begin
  trend:=-1;
  ep:=1;
  af:=step;
 end
 sarx:=fsar;
end
else
begin
 if ep > 0 then
 begin
  sarx:=highprice;
  ep:=-1;
  GOTO ENDANDSHOW; //跳转到末尾直接显示
 end
 
 //看跌
 if low < lowPrice then
 begin
  af := af + step;
  if af > fmax then
    af := fmax;
 end
 
 fsar := sarx + af * (lowprice-sarx);
 
 //是否跳转
 if fSar < High then
 begin
  Trend := 1;
  EP := 1;
  AF := Step;
 end
 sarx := fSar;
end

//显示变量
ENDANDSHOW@; //此为语句标号,GOGO语句可以用这个标号直接跳转到这里
ShowSar:sarx;


--  作者:FireScript
--  发布时间:2021/3/31 13:44:17
--  
这种没办法改的。sar算法就是用的高低价。本身函数就没有提供其他价格选项,也是因为它自己算法就是这样设计的。