|
本帖最後由 abc889900 於 17-8-24 21:31 編輯
以下是原始碼:
VAR1:=(HHV(HIGH,9)-CLOSE)/(HHV(HIGH,9)-LLV(LOW,9))*100-70;
VAR2:=SMA(VAR1,9,1)+100;
VAR3:=(CLOSE-LLV(LOW,9))/(HHV(HIGH,9)-LLV(LOW,9))*100;
VAR4:=SMA(VAR3,3,1);
VAR5:=SMA(VAR4,3,1)+100;
VAR6:=VAR5-VAR2;
VAR7:=IF(VAR6>21,VAR6-21,0);
STICKLINE(REF(VAR7,1)<VAR7,VAR7,REF(VAR7,1),3,0),COLORRED;
STICKLINE(REF(VAR7,1)>VAR7,VAR7,REF(VAR7,1),3,0),COLORGREEN;
紅買綠賣,COLORRED;
VARM1:=SMA((CLOSE-LLV(LOW,5))/(HHV(HIGH,5)-LLV(LOW,5))*100,3,1);
VARM2:=3*VARM1-2*VARM1;
DRAWICON(CROSS(VARM2,25),VAR7-10,1);
VAR1M:=(HHV(H,9)-C)/(HHV(H,9)-LLV(L,9));
VAR2M:=(C-LLV(L,9))/(HHV(H,9)-LLV(L,9));
VAR3M:=SMA(SMA(VAR2M,3,1),3,1);
VAR4M:=(VAR3M-SMA(VAR1M,9,1))-0.5;
VAR5M:=IF(VAR4M>0.00,VAR4M,0.00);
VAR6M:=REF(VAR5M,1);
注意風險:120,COLORGREEN;
DRAWICON(CROSS(VAR6M,VAR5M),注意風險+20,2);
我把它修改為 Powerlanguage 語言,以下是我修改後的程式碼:-
但我套用在MultiCharts 中,出現了
{例外}
浮點運算除以0。
- <div><font style="background-color: rgb(255, 255, 255);">inputs:
- OverSold(-120),
- OverBought(120);</font></div><div><font style="background-color: rgb(255, 255, 255);">variables:
- var0( 0 ),
- var1( 0 ),
- var2( 0 ),
- var3( 0 ),
- var4( 0 ),
- var5( 0 ),
- var6( 0 ),
- var7( 0 ),
- var8( 0 ),
- var9( 0 ),
- var10( 0 ),
- var11( 0 ),
- var12( 0 ),
- var13( 0 ),
- var14( 0 ),
- var15( 0 );</font></div><div><font style="background-color: rgb(255, 255, 255);">
- var1=(HIGHD(9)-CLOSE)/((HIGHD(9)-LOWD(9))*100-70);
- var2=SMA(var1,9)+100;
- var3=(CLOSE-LOWD(9))/((HIGHD(9)-LOWD(9))*100);
- var4=SMA(var3,3);
- var5=SMA(var4,3)+100;
- var6=var5-var2;
- If var6>21 then var7 = (var6-21) else var7=0;
- var8=var7-var7[1];
- Plot1(var8);
- If var8> 0 then SetPlotColor(1,red)
- else
- SetPlotColor(1,green);</font></div><div><font style="background-color: rgb(255, 255, 255);">var9=SMA((CLOSE-LOWD(5))/(HIGHD(5)-LOWD(5))*100,3);
- var10=3*var9-2*var9;</font></div><div><font style="background-color: rgb(255, 255, 255);">var11=(HIGHD(9)-C)/(HIGHD(9)-LOWD(9));
- var12=(C-LOWD(9))/(HIGHD(9)-LOWD(9));
- var13=SMA(SMA(var12,3),3);
- var14=(var13-SMA(var13,9))-0.5;
- if var14>0.00 then var14=var13 else var14=0.00;
- var15=var14[1];</font></div><div><font style="background-color: rgb(255, 255, 255);">Condition1=var10 crosses over 25;
- if Condition1 then
- Print("Buy")
- else
- begin
- Condition1=var10[1] crosses over var10[0];
- if Condition1 then
- Print("Sell");
- End;</font></div><div>
- </div>
複製代碼
及SMA 函數如下:
Inputs: Price(NumericSeries), Length(NumericSimple);
Variables : Sum(0), Counter(0);
If CurrentBar = 1 Then Begin
Sum= 0;
For Counter = 0 To Length - 1 Begin
Sum= Sum+ Price[Counter];
End ;
SMA = Sum / Length;
End;
If CurrentBar > 1 Then Begin
Sum = Sum[1] - SMA[1] + Price;
SMA = Sum / Length;
end ;
可以幫忙看看是出現甚麼問題嗎?
另外,有沒有人可以把原始的程式碼轉換為Powerlanguage,待我看看有甚麼分別及有沒有可以優化的地方。
謝謝
|
|