发一个自己刚写的一个画峰谷的的代码,还有点问题 就是有时候会相邻比较近的时候出现两个峰,但是其实高低是不同的,高手给看看 也希望大家能多发些代码出来交流! var Bar , HighSeries , i , SSHH, SSLL , j ,k ,PER, m, l: integer; function SwingHighSeries(Series: Integer; Period: Integer): integer; begin var i, j, k, p, SH: integer; var SHscore: integer; var lastSH: float; var sName: string; { *************** Definitions ***************** p = swing verification period i = bar number j = range over which to check for SH's SH = resulting series of swing highs SHscore = totalizer to validate an SH lastSH = stores the last SH in the determination loop *************** Definitions *****************} p:=Period; SH:=CreateSeries(); { ***** Start Swing Point "finder" loop ***** } for i:= p+1 to BarCount()-p-1 do begin SHscore:=0; for j:= i-p to i+p do begin k:=i-j; if Abs(k)=1 then begin if GetSeriesValue(i,Series) >= GetSeriesValue(i-1,Series) then if GetSeriesValue(i,Series) >= GetSeriesValue(i+1,Series) then SHscore:=SHscore+1; end; if Abs(k)>0 then begin if GetSeriesValue(i,Series) > GetSeriesValue(i-k,Series) then if GetSeriesValue(i,Series) > GetSeriesValue(i+k,Series) then SHscore:=SHscore+1; end; end; {*** If the "score" variable equals 2x the verification period the swing point is validated***} if SHscore>=2*p then begin lastSH:=GetSeriesValue(i,Series); SetSeriesValue(i,SH,lastSH); end; //print (floattostr(getseriesvalue(i+p,SH))); end; { ***** End Swing Point "finder" loop ***** } Result:=SH; end; function SwingLowSeries(Series: Integer; Period: Integer): integer; begin var i, j, k, p, SL: integer; var SLscore: integer; var lastSL: float; var sName: string; { *************** Definitions ***************** p = swing verification period i = bar number j = range over which to check for SL's SL = resulting series of swing lows SLscore = totalizer to validate an SL lastSL = stores the last SL in the determination loop *************** Definitions *****************} p:=Period; SL:=CreateSeries(); { ***** Start Swing Point "finder" loop ***** } for i:= p+1 to BarCount()-p-1 do begin SLscore:=0; for j:= i-p to i+p do begin k:=i-j; if Abs(k)=1 then begin if GetSeriesValue(i,Series) <= GetSeriesValue(i-1,Series) then if GetSeriesValue(i,Series) <= GetSeriesValue(i+1,Series) then SLscore:=SLscore+1; end; if Abs(k)>1 then begin if GetSeriesValue(i,Series) < GetSeriesValue(i-k,Series) then if GetSeriesValue(i,Series) < GetSeriesValue(i+k,Series) then SLscore:=SLscore+1; end; end; {*** If the "score" variable equals 2x the verification period the swing point is validated***} if SLscore>=2*p then Begin lastSL:=GetSeriesValue(i,Series); SetSeriesValue(i,SL,lastSL); End; end; { ***** End Swing Point "finder" loop ***** } Result:=SL; end; SSHH :=SwingHighSeries(#high,13); SSLL :=SwingLowSeries(#low , 13) ; PER := 100; for i:= PER to BarCount()-1 do begin if GetSeriesValue(i,SSHH) <> 0 then begin for j:= i-PER to i do begin if GetSeriesValue(j,SSLL) <> 0 then k:= j; end; if i < BarCount() - 1 - PER Then begin for l:= i + 1 to i + PER do begin if GetSeriesValue(l,SSLL) <> 0 then break; m :=l + 1; end; end // import ! this place has not";",because else if i >= Barcount() - 1 - PER Then begin for l := i+1 to Barcount()-2 do begin if GetSeriesValue(l,SSLL) <> 0 then break; m :=l + 1; // attention this +1 because precious break cause l no change no +1 end; end; print(IntToStr(m)); SetBarColor(k,#yellow); SetBarColor(m,#yellow); Drawline(k,GetSeriesValue(k,#low),i,GetSeriesValue(i,#high),0,#purple,#thin); Drawline(m,GetSeriesValue(m,#low),i,GetSeriesValue(i,#high),0,#purple,#thin); SetBarColor(i,#green); end; end;