沒法跑編譯

  •   205 
  • 最後發表   Meli  2025 二月 20
Meli 發文於   2025/02/20

以下程式沒法編譯,我檢查過了,沒問題,可以幫我看一下嗎?謝謝!感恩

input: grid_gap(20, "每格點數");

input: grid_maxcount (3, "最多格數");

input: stoploss_point (100, "停損(點)");

input: MinTradeDifference (10,"最小交易間距");

input: TrendFilter(true, "是否使用趨勢過濾");

 

var: intrabarpersist grid_started(false);

var: intrabarpersist grid_base(0);

var: intrabarpersist grid_current_base(0);

var: intrabarpersist grid_current_ord(0);

var: intrabarpersist grid_buycount(0);

var: intrabarpersist grid_sellcount(0);

var: intrabarpersist LastTradePrice(0);

var: intrabarpersist TrendDirection("")

{判斷趨勢方向}

if TrendFilter then 

begin

if Close > Average(Close, 20) then TrendDirection = "Up";

if Close < Average(Close, 20) then TrendDirection = "DOWn";

end;

{ 啟動網格交易 }

if not grid_started and GEtInfo("Trademode") = 1 then 

begin

grid_started =true;

grid_base = Close;

grid_current_base = close;

grid_current_ord = 0;

grid_buycount = 0;

grid_sellcount = 0;

Print("=>啟動網格中心點:", numtostr(grid_current_base, 0));

end;

{網格交易邏輯}

if grid_base <> 0 then 

begin

if close >= grid_base + stoploss_point or close <= grid_base-stoploss_point then 

begin

Setposition (0, label:= "網格:停損出場");

grid_base = 0;

end 

else 

begin

if abs(close-LastTradePrice) > MinTradeDifference then 

begin

if close >= grid_current_base + grid_gap then 

begin

value1>= grid_current_ord + IntPortion ((close-grid_current_base) / grid_gap);

if value1>= grid_maxcount then value1 = grid_maxcount;

value1 = value1-grid_current_ord;

if value1>0 then 

begin

grid_current_base = grid_current_base +value1 * grid_gap;

grid_current_ord = grid_current_ord + value1;

grid_sellcount = grid_sellcount + value1;

if not TrendFilter or TrendDirection = "Down" then 

begin

SetPostion (Position-value1, label:="網格:上漲賣出");

LastTradePrice = close;

end;

end;

end;

if close<= grid_current_base-grid_gap then 

begin

value1 = grid_current_ord - IntPortion ((grid_current_base- close) / grid_gap);

if value1 <= -1 * grid_maxcount then value1 = -1* grid_maxcount;

value1= grid_current_ord - value1;

if value1 > 0 then

begin

grid_current_base = grid_current_base-value1* grid_gap;

grid_current_ord = grid_current_ord-value1;

grid_buycount = grid_buycount + value1;

if not TrendFilter or TrendDirection = "Up" then

begin

SetPosition (Position + value1, label:= "網格:下跌買進");

LastTradePrice = close;

end;

end;

end;

end;

end;

end;

虎科大許教授 發文於   2025/02/20

你需要養成良好的撰寫習慣。若沒把握可編譯成功,就應該撰寫一小段就編譯。很多很低級的錯誤都沒被檢查出來。

input: grid_gap(20, "每格點數");
input: grid_maxcount (3, "最多格數");
input: stoploss_point (100, "停損(點)");
input: MinTradeDifference (10,"最小交易間距");
input: TrendFilter(true, "是否使用趨勢過濾");
var: intrabarpersist grid_started(false);
var: intrabarpersist grid_base(0);
var: intrabarpersist grid_current_base(0);
var: intrabarpersist grid_current_ord(0);
var: intrabarpersist grid_buycount(0);
var: intrabarpersist grid_sellcount(0);
var: intrabarpersist LastTradePrice(0);
var: intrabarpersist TrendDirection("");
{判斷趨勢方向}
if TrendFilter then 
    begin
        if Close > Average(Close, 20) then TrendDirection = "Up";
        if Close < Average(Close, 20) then TrendDirection = "DOWn";
    end;
{ 啟動網格交易 }
if not grid_started and GEtInfo("Trademode") = 1 then 
    begin
        grid_started =true;
        grid_base = Close;
        grid_current_base = close;
        grid_current_ord = 0;
        grid_buycount = 0;
        grid_sellcount = 0;
        Print("=>啟動網格中心點:", numtostr(grid_current_base, 0));
    end;
{網格交易邏輯}
if grid_base <> 0 then 
    begin
        if close >= grid_base + stoploss_point or close <= grid_base-stoploss_point then 
            begin
                Setposition (0, label:="網格:停損出場");
                grid_base = 0;
            end 
        else 
            begin
                if absvalue(close-LastTradePrice) > MinTradeDifference then 
                    begin
                        if close >= grid_current_base + grid_gap then 
                            begin
                                value1 = grid_current_ord + IntPortion ((close-grid_current_base) / grid_gap);
                                if value1>= grid_maxcount then value1 = grid_maxcount;
                                value1 = value1-grid_current_ord;
                                if value1>0 then 
                                    begin
                                        grid_current_base = grid_current_base +value1 * grid_gap;
                                        grid_current_ord = grid_current_ord + value1;
                                        grid_sellcount = grid_sellcount + value1;
                                        if not TrendFilter or TrendDirection = "Down" then 
                                            begin
                                                SetPosition(Position-value1, label:="網格:上漲賣出");
                                                LastTradePrice = close;
                                            end;
                                    end;
                            end;
                        if close<= grid_current_base-grid_gap then 
                            begin
                                value1 = grid_current_ord - IntPortion ((grid_current_base- close) / grid_gap);
                                if value1 <= -1 * grid_maxcount then value1 = -1* grid_maxcount;
                                value1= grid_current_ord - value1;
                                if value1 > 0 then
                                    begin
                                        grid_current_base = grid_current_base-value1* grid_gap;
                                        grid_current_ord = grid_current_ord-value1;
                                        grid_buycount = grid_buycount + value1;
                                        if not TrendFilter or TrendDirection = "Up" then
                                            begin
                                                SetPosition (Position + value1, label:= "網格:下跌買進");
                                                LastTradePrice = close;
                                            end;
                                    end;
                            end;
                    end;
            end;
    end;

發表回覆
Close