Multichart 語法 轉XQ

  •   364 
  • 最後發表   stone77  2025 一月 09
stone77 發文於   2024/12/30

 

if marketposition= 1 and openpositionprofit>winatr1*bigpointvalue then begin
    trailing_pt1=(hpeak-entryprice)*0.6+entryprice;
    if c<=trailing_pt1 then sell ("trailing1+") next bar market;
end;
if marketposition=-1 and openpositionprofit>winatr1*bigpointvalue then begin
    trailing_pt1=entryprice-(entryprice-lpeak)*0.6;
    if c>=trailing_pt1 then buytocover ("trailing1-") next bar market;
end;

if marketposition= 1 and openpositionprofit>winatr2*bigpointvalue then begin
    trailing_pt2=(hpeak-entryprice)*0.8+entryprice;
    if c<=trailing_pt2 then sell ("trailing2+") next bar market;
end;
if marketposition=-1 and openpositionprofit>winatr2*bigpointvalue then begin
    trailing_pt2=entryprice-(entryprice-lpeak)*0.8;
    if c>=trailing_pt2 then buytocover ("trailing2-") next bar market;
end;


if marketposition= 1 and c<entryprice-lostpt then sell ("stoplostt+") next bar market;
if marketposition=-1 and c>entryprice+lostpt then buytocover ("stoplostt-") next bar market;

請問:以下該如何改寫成XQ

1. openpositionprofit

2. bigpointvalue

3. sell ("trailing1+") next bar market.

4. buytocover ("trailing1-") next bar market.

5. sell ("trailing2+") next bar market.

6. buytocover ("trailing2-") next bar market;

7. sell ("trailing2+") next bar market;

8. buytocover ("stoplostt-") next bar market;

9. sell ("stoplostt+") next bar market;

 

排序方式: 標準 | 最新
XQ 新手 發文於   2024/12/30

請試試 是否 正確囉~沒RUN 過~~
// 宣告參數

input: winatr1(2.0, "Win ATR1"), winatr2(3.0, "Win ATR2"), lostpt(10, "Stop Loss Points");

input: bigpointvalue(100, "Big Point Value");

 

// 設定變數

var: hpeak(0), lpeak(0), trailing_pt1(0), trailing_pt2(0), openpositionprofit(0);

 

// 計算浮動盈虧

openpositionprofit = (Close - EntryPrice) * bigpointvalue;

 

// 更新高點與低點

if marketposition = 1 then 

    hpeak = MaxList(hpeak, High);

if marketposition = -1 then 

    lpeak = MinList(lpeak, Low);

 

// 移動停利點位設定

if marketposition = 1 and openpositionprofit > winatr1 * bigpointvalue then begin

    trailing_pt1 = (hpeak - EntryPrice) * 0.6 + EntryPrice;

    if Close <= trailing_pt1 then 

        setposition(0, market, label:="trailing1+");

end;

 

if marketposition = -1 and openpositionprofit > winatr1 * bigpointvalue then begin

    trailing_pt1 = EntryPrice - (EntryPrice - lpeak) * 0.6;

    if Close >= trailing_pt1 then 

        setposition(0, market, label:="trailing1-");

end;

 

if marketposition = 1 and openpositionprofit > winatr2 * bigpointvalue then begin

    trailing_pt2 = (hpeak - EntryPrice) * 0.8 + EntryPrice;

    if Close <= trailing_pt2 then 

        setposition(0, market, label:="trailing2+");

end;

 

if marketposition = -1 and openpositionprofit > winatr2 * bigpointvalue then begin

    trailing_pt2 = EntryPrice - (EntryPrice - lpeak) * 0.8;

    if Close >= trailing_pt2 then 

        setposition(0, market, label:="trailing2-");

end;

 

// 停損邏輯

if marketposition = 1 and Close < EntryPrice - lostpt then 

    setposition(0, market, label:="stoplostt+");

if marketposition = -1 and Close > EntryPrice + lostpt then 

    setposition(0, market, label:="stoplostt-");

 

  • 按讚來自於
  • stone77
stone77 發文於   2025/01/03

謝謝

 

XS小編 發文於   2025/01/09

Hello stone77,

 

小編補充,MultiCharts 的函數並非都有對應的 XS函數。

openpositionprofit => 可以用 filledavgprice 和 close 來計算。

bigpointvalue => 需要自行設定參數

sell => sell

buytocover => cover

 

您可以在XSHelp中確認是否有所需的函數。

發表回覆
Close