編譯時出現錯誤描述:編譯器看到了一個無法辨認的字 "ifPosition<><=-1thenbegin下略>

  •   263 
  • 最後發表   豪邁野豬  2024 十月 23
豪邁野豬 發文於   2024/10/22

我在原本寫好編譯好的固定停損停利的腳本中,嘗試加入移動停利的程式碼,但寫完開始編譯後出現錯誤,但我怎麼看都沒有不對的地方,想請小幫手幫我看看,以下是出現錯誤的部分,他把這一整串當成同一個字了...

if Position <= -1 and Filled <= -1 then begin

{ 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 }

 

var: intrabarpersist max_profit_percent(0); { 啟動停利後最大獲利點 }

 

if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then begin

{ 停損 }

SetPosition(0);

max_profit_percent = 0;

 

end else begin

 

{ 判斷是否要啟動停利 }

if max_profit_percent = 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then begin

max_profit_percent = Close;

end;

 

if max_profit_percent <> 0 then begin

if Close >= max_profit_percent*(1+0.01*profit_percent) then begin

{ 停利 }

SetPosition(0);

max_profit_point = 0;

end else if Close < max_profit_point then begin

{ 移動最大獲利點 }

max_profit_point = Close;

end;

if currentTime >= 132000 then SetPosition(0, market);

 

end;

附上腳本檔

也麻煩小幫手幫我檢視一下我移動停利這樣寫是正確的嗎?謝謝

 

附加文件

排序方式: 標準 | 最新
虎科大許教授 發文於   2024/10/22

此問題並非系統把那一串指令當作一個字,而是你的程式少了兩個end。另外,以後參數及變數的程式碼也應貼上來,不然會被誤以為沒有宣告造成問題。還有,避免少了end的問題,最好begin打完就打end,再回去打中間的程式碼。修改後的程式碼如下:

input:loss_percent(2,"停損趴數");
input:profit_percent(5,"停利趴數");
var: intrabarpersist max_profit_percent(0); { 啟動停利後最大獲利點 }
var: intrabarpersist max_profit_point(0);
if Position <= -1 and Filled <= -1 then 
    begin
        { 依照成本價格設定停損/停利: 請注意當作空時, 判斷是否獲利的方向要改變 }
        if loss_percent > 0 and Close >= FilledAvgPrice*(1+0.01*loss_percent) then 
            begin
                { 停損 }
                SetPosition(0);
                max_profit_percent = 0;
            end 
        else 
            begin
                { 判斷是否要啟動停利 }
                if max_profit_percent = 0 and Close <= FilledAvgPrice*(1-0.01*profit_percent) then 
                    begin
                        max_profit_percent = Close;
                    end;
                if max_profit_percent <> 0 then 
                    begin
                        if Close >= max_profit_percent*(1+0.01*profit_percent) then 
                            begin
                                { 停利 }
                                SetPosition(0);
                                max_profit_point = 0;
                            end 
                        else 
                            if Close < max_profit_point then 
                                begin
                                    { 移動最大獲利點 }
                                    max_profit_point = Close;
                                end;
                    end;
                if currentTime >= 132000 then SetPosition(0, market);
            end;
    end;

  • 按讚來自於
  • salineyu
豪邁野豬 發文於   2024/10/23

謝謝教授的解答!

發表回覆
Close