做空策略卻執行平倉的買進,也沒有執行做空

  •   303 
  • 最後發表   束束  2025 二月 19
束束 發文於   2025/02/19

Dears
做空策略卻執行平倉的買進,也沒有執行做空,都是先買進

Inputs: BBPeriod(20), BBMultiplier(2);  { 布林帶參數 }

Vars: upperBand(0), lowerBand(0), middleBand(0);  { 布林帶計算值 }

Vars: myEntryPrice(0), positionState(0);  { 進場價格與持倉狀態 }

Vars: maxProfit(0), currentDrawdown(0);  { 移動停損用最大浮動獲利 }

 

{ 計算布林帶上下軌 }

upperBand = BollingerBand(Close, BBPeriod, BBMultiplier);

lowerBand = BollingerBand(Close, BBPeriod, -BBMultiplier);

 

{ 進場邏輯:前兩根 K 棒觸及布林帶上軌或下軌,確保沒有持倉時才放空 }

If positionState = 0 Then 

Begin

    If (Low[2] <= lowerBand[2]) And (Close[1] < lowerBand[1]) Then 

    Begin

        Sell(1);  { 放空 }

        myEntryPrice = Open;

        positionState = -1;  { 記錄空單持倉狀態 }

        maxProfit = 0;

    End;

 

    If (High[2] >= upperBand[2]) And (Close[1] < upperBand[1]) Then 

    Begin

        Sell(1);  { 放空 }

        myEntryPrice = Open;

        positionState = -1;  { 記錄空單持倉狀態 }

        maxProfit = 0;

    End;

End;

 

{ 空單移動停損邏輯 }

If positionState = -1 Then 

Begin

    maxProfit = MaxList(maxProfit, myEntryPrice - Close);  { 更新最大浮動獲利 }

    currentDrawdown = maxProfit - (myEntryPrice - Close);

    

    { 如果最大浮動獲利達到 15 點且回撤超過 15 點,則平倉 }

    If (maxProfit >= 15) And (currentDrawdown >= 15) Then 

    Begin

        Buy(1);  { 平倉空單 }

        positionState = 0;  { 清除持倉狀態 }

        maxProfit = 0;

    End;

 

End;

 

排序方式: 標準 | 最新
虎科大許教授 發文於   2025/02/19

Sell是有多頭部位的賣出。放空要用Short。

平倉空頭部位不可用Buy,要用Cover。

束束 發文於   2025/02/19
發表回覆
Close