### Get Field Data Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E5%9D%87%E8%B2%B7%E5%8F%A3%E6%95%B8&b=ta Examples of how to retrieve field data using the GetField function with different field names. These examples demonstrate retrieving average buy units and shares. ```xshelp Value1 = GetField("委買均"); Value1 = GetField("AvgLongShare"); Value1 = GetField("AvgLongUnits"); Value1 = GetField("均買張數"); Value1 = GetField("均買口數"); ``` ```xshelp Value1 = GetField("委買均"); Value1 = GetField("AvgLongShare"); Value1 = GetField("AvgLongUnits"); Value1 = GetField("均買張數"); Value1 = GetField("均買口數"); ``` -------------------------------- ### Get Field Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E6%9C%9F%E6%AC%8A%E9%96%8B%E7%9B%A4%E5%A7%94%E8%B2%B7&b=ta Demonstrates how to retrieve field values using different identifiers. Use 'DayOpenBid' for general open bid, and '期權開盤委買' specifically for options open bid. ```script 1Value1 = GetField("開盤委買"); 2Value1 = GetField("DayOpenBid"); 3Value1 = GetField("期權開盤委買"); ``` ```script Value1 = GetField("開盤委買"); Value1 = GetField("DayOpenBid"); Value1 = GetField("期權開盤委買"); ``` -------------------------------- ### Array_Copy Example Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=Array_Copy&group=ARRAYFUNC Demonstrates copying elements between arrays. The first example copies all elements from arrA to arrB. The second example copies a subset of elements from arrA to arrC, starting at a different position in arrC. ```XQ Array: arrA[5](0); Array: arrB[5](0); Array: arrC[5](0); arrA[1] = 1; arrA[2] = 2; arrA[3] = 3; arrA[4] = 4; arrA[5] = 5; Array_Copy(arrA, 1, arrB, 1, 5); Array_Copy(arrA, 1, arrC, 2, 3); ``` -------------------------------- ### GetSymbolFieldStartOffset Examples Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=GetSymbolFieldStartOffset&group=GENERALFUNC Demonstrates how to use GetSymbolFieldStartOffset to get the number of bars for a field. The first example retrieves the count for the current script's execution frequency, while the second specifies a monthly frequency ('M'). ```XScript Value1 = GetSymbolFieldStartOffset("1101.TW", "月營收"); Value2 = GetSymbolFieldStartOffset("1101.TW", "月營收", "M"); ``` -------------------------------- ### GetBarOffset Example Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=GetBarOffset&group=GENERALFUNC This example demonstrates how to use GetBarOffset to find the relative position of a specific bar and then access its high price. ```XScript value1 = GetBarOffset(20150831); //取得20150831這根K棒的相對位置 value2 = High[value1]; //取得20150831當天的最高價 plot1(value2); //繪出20150831最高價的水平線 ``` -------------------------------- ### StrTrim function examples Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=StrTrim&group=STRINGFUNC A consolidated example demonstrating various uses of the StrTrim function with different options. ```XScript str1 = StrTrim(" hello world "); //回傳的字串會是"hello world"。 str1 = StrTrim(" hello world ", 0); //回傳的字串會是 "hello world"。 str1 = StrTrim(" hello world ", 1); //回傳的字會是 "hello world ". str1 = StrTrim(" hello world ", 2); //回傳的字串會是" hello world". ``` -------------------------------- ### Basic Plotting Example Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=NoPlot&group=GENERALFUNC This example demonstrates the basic usage of the Plot function to display the difference between the current and previous closing price. ```XScript 1Value1 = Close - Close[1]; 2Plot1(Value1); ``` -------------------------------- ### DownTo Loop Example: Summing Close Prices (Reverse) Source: https://xshelp.xq.com.tw/XSHelp/api?a=For&b=controlflow This example achieves the same result as the previous For loop example but uses the DownTo syntax. It iterates from 4 down to 0, summing the last 5 closing prices. ```XScript SumValue = 0; For i = 4 downto 0 Begin SumValue = SumValue + Close[i]; End; AvgValue = SumValue / 5; ``` -------------------------------- ### Array_Sum Function Example Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=Array_Sum&group=ARRAYFUNC Demonstrates how to declare an array, populate it with values, and use Array_Sum to calculate the sum of elements within different ranges. The function sums elements from a start position to an end position. ```XScript Array: arr[5](0); // 宣告arrA是一個有5個元素的陣列,初始值都是0 arr[1] = 1; arr[2] = 2; arr[3] = 3; arr[4] = 4; arr[5] = 5; Value1 = Array_Sum(arr, 1, 5); // Value1 = 15 (1 + 2 + 3 + 4 + 5) Value2 = Array_Sum(arr, 1, 3); // Value2 = 6 (1 + 2 + 3) ``` -------------------------------- ### Get Field Examples for 因子分數_成交值流動性 Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=%E5%9B%A0%E5%AD%90%E5%88%86%E6%95%B8_%E6%88%90%E4%BA%A4%E5%80%BC%E6%B5%81%E5%8B%95%E6%80%A7&group=FFINANCE Demonstrates how to retrieve the '因子分數_成交值流動性' field using the GetField function with various equivalent names. This is applicable for stock selection scripts with monthly frequency for Taiwanese stocks. ```XScript 1Value1 = GetField("因子分數_成交值流動性"); 2Value1 = GetField("FactorScore_DVOL"); 3Value1 = GetField("因子分數_流動性因子(以成交值為基準)"); 4Value1 = GetField("FactorScore_Trading volume Factor"); ``` ```XScript Value1 = GetField("因子分數_成交值流動性"); Value1 = GetField("FactorScore_DVOL"); Value1 = GetField("因子分數_流動性因子(以成交值為基準)"); Value1 = GetField("FactorScore_Trading volume Factor"); ``` -------------------------------- ### GetField Function Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E9%96%8B%E7%9B%A4%E5%A7%94%E8%B3%A3&b=ta Examples of how to use the GetField function to retrieve different types of '開盤委賣' data. ```APIDOC ## GetField Function Examples ### Description This section provides examples of using the `GetField` function to retrieve specific data points related to '開盤委賣' (Opening Sell Orders). ### Method Function Call ### Endpoint N/A (Function Call) ### Parameters N/A ### Request Example ``` Value1 = GetField("開盤委賣"); Value1 = GetField("DayOpenAsk"); Value1 = GetField("期權開盤委賣"); ``` ### Response #### Success Response Returns the requested data value. #### Response Example ``` Value1 = GetField("開盤委賣"); Value1 = GetField("DayOpenAsk"); Value1 = GetField("期權開盤委賣"); ``` ``` -------------------------------- ### GetField Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E5%A7%94%E8%B3%A3%E5%BC%B5%E6%95%B8&b=ta Demonstrates how to retrieve field values using GetField. Supports various field names including localized and English versions. ```XScript Value1 = GetField("累計委賣"); Value1 = GetField("AskUnits"); Value1 = GetField("委賣張數"); Value1 = GetField("委賣口數"); ``` ```XScript Value1 = GetField("累計委賣"); Value1 = GetField("AskUnits"); Value1 = GetField("委賣張數"); Value1 = GetField("委賣口數"); ``` -------------------------------- ### Get Current Bar Number - General Functions Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=CurrentBar&group=GENERALFUNC Returns the sequential bar number during script execution, starting from 1. This can be used to determine the current execution timing, for example, to set initial values on the first bar. ```General Functions 1if CurrentBar = 1 then 2 value1 = Close 3else 4 value1 = value1[1] + value2 * (Close - value1[1]); ``` ```General Functions if CurrentBar = 1 then value1 = Close else value1 = value1[1] + value2 * (Close - value1[1]); ``` -------------------------------- ### Using ArrayXDaySeries to Store Daily Closing Prices Source: https://xshelp.xq.com.tw/XSHelp/api?a=ArrayXDaySeries&b=sys This example demonstrates how to initialize an array and then use ArrayXDaySeries to populate it with daily closing prices. Ensure SBB_length and _DayValue are defined in your script. ```XScript Array: CloseArray[](0); ArrayXDaySeries(GetField("收盤價","D"),SBB_length,_DayValue); ``` -------------------------------- ### Get Stock Buyback Start Date Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E5%BA%AB%E8%97%8F%E8%82%A1%E9%96%8B%E5%A7%8B%E6%97%A5%E6%9C%9F&b=filter Retrieves the stock buyback start date using GetField. The function returns 0 if no data is available. ```XScript Value1 = GetField("庫藏股開始日期"); Value1 = GetField("Stockstartdate"); ``` ```XScript Value1 = GetField("庫藏股開始日期"); Value1 = GetField("Stockstartdate"); ``` -------------------------------- ### Get Current Bar Number for a Frequency Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=xf_GetCurrentBar&group=FREQUENCYFUNC This example demonstrates how to use xf_GetCurrentBar to get the current bar number. It's used here to conditionally initialize a variable based on whether it's the first bar. ```XScript value1 = xf_GetCurrentBar(FreqType); if Length + 1 = 0 then Factor = 1 else Factor = 2 / (Length + 1); if value1 = 1 then xf_XAverage = Series else xf_XAverage = lastXAverage + Factor * (Series - lastXAverage); ``` ```XScript value1 = xf_GetCurrentBar(FreqType); if Length + 1 = 0 then Factor = 1 else Factor = 2 / (Length + 1); if value1 = 1 then xf_XAverage = Series else xf_XAverage = lastXAverage + Factor * (Series - lastXAverage); ``` -------------------------------- ### Retrieve Debt to Equity Ratio (Combined) Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=%E8%B2%A0%E5%82%B5%E5%B0%8D%E6%B7%A8%E5%80%BC%E6%AF%94%E7%8E%87&group=FFINANCE This example shows multiple ways to call GetField for the Debt to Equity Ratio in a single line, demonstrating flexibility in accessing the field. ```xq Value1 = GetField("負債對淨值比率"); Value1 = GetField("DebtEquityRatio"); Value1 = GetField("總負債/總淨值"); ``` -------------------------------- ### Combined Examples for Retrieving Sell Price Source: https://xshelp.xq.com.tw/XSHelp?HelpName=%E8%B3%A3%E5%87%BA&group=QOFTEN Demonstrates multiple ways to retrieve the sell price within a single script. This includes using GetQuote with both Chinese and English parameters, as well as the q_Ask variable. ```xq Value1 = GetQuote("賣出"); Value1 = GetQuote("Ask"); Value1 = q_Ask; ``` -------------------------------- ### Get Stock Buyback Start Date Source: https://xshelp.xq.com.tw/XSHelp?HelpName=%E5%BA%AB%E8%97%8F%E8%82%A1%E9%96%8B%E5%A7%8B%E6%97%A5%E6%9C%9F&group=FEVENT Retrieves the start date of the latest stock buyback period. Use GetFieldDate to check if data exists by verifying it's not equal to 0. The field format is YYYYMMDD. ```script Value1 = GetField("庫藏股開始日期"); Value1 = GetField("Stockstartdate"); ``` ```script Value1 = GetField("庫藏股開始日期"); Value1 = GetField("Stockstartdate"); ``` -------------------------------- ### Get Array Element Count Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=Array_GetMaxIndex&group=ARRAYFUNC Returns the number of elements in an array variable. Example shows assigning the result to a variable. ```Array Array: arrA[5](0); // 宣告arrA是一個有5個元素的陣列,初始值都是0 Value1 = Array_GetMaxIndex(arrA); // Value1 = 5 ``` -------------------------------- ### Buy Function Usage Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=Buy&b=bif Demonstrates various ways to use the Buy function to add to long positions. Includes specifying quantity, price, and labels. ```XScript Buy(1); Buy(1, Close); Buy(1, MARKET); Buy(1, label:="買進1張"); ``` -------------------------------- ### Calculate Fractional Part of a Number Source: https://xshelp.xq.com.tw/XSHelp/api?a=fracportion&b=bif Use FracPortion to get the decimal part of a number. This example also shows IntPortion for comparison. ```xs 1Value1 = IntPortion(10.5); // Value1 = 10 2Value2 = FracPortion(10.5); // Value2 = 0.5 ``` -------------------------------- ### Get 30-Minute Interval Value and Detect Change Source: https://xshelp.xq.com.tw/XSHelp/api?a=xfMin_GetDTValue&b=sys This snippet demonstrates how to use xfMin_GetDTValue to get the value for a 30-minute interval and then checks if this value has changed from the previous interval. If a change is detected, it plots a '1' on the chart, indicating the start of a new 30-minute period. ```XScript value1 = xfMin_getdtvalue("30",date); if value1 <> value1[1] then plot1(1) else plot1(0); ``` -------------------------------- ### PlaySound Function Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=PlaySound&b=bif Demonstrates how to use the PlaySound function to play audio files. The first example plays a file from the default sound directory, while the second specifies an absolute path. ```script 1PlaySound("GML.wav"); ``` ```script 2PlaySound("C:\\SysJust\\XQ2005\\User\\Sound\\GML.wav"); ``` -------------------------------- ### Extract Substring using MidStr Source: https://xshelp.xq.com.tw/XSHelp/api?a=midstr&b=bif Use MidStr to get a substring from a string, specifying the starting position and length. The first character is at position 1. ```xs 1Var: str1(""), str2(""); 2 3 4str1 = MidStr("abcdefg", 1, 3); // str1 = "abc" 5str2 = MidStr("abcdefg", 2, 3); // str1 = "bcd" ``` ```xs Var: str1(""), str2(""); str1 = MidStr("abcdefg", 1, 3); // str1 = "abc" str2 = MidStr("abcdefg", 2, 3); // str1 = "bcd" ``` -------------------------------- ### Sell Function Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=Sell&b=bif Demonstrates various ways to call the Sell function to reduce long positions. Includes specifying quantity,委託價格 (order price), and labels. ```XScript 1Sell(1); 2Sell(1, Close); 3Sell(1, MARKET); 4Sell(1, label:="出場1張"); ``` -------------------------------- ### Get Transaction Direction with FilledRecordBS Source: https://xshelp.xq.com.tw/XSHelp/api?a=FilledRecordBS&b=bif Use FilledRecordBS to get the transaction direction of a specific filled record. Pass the index of the record (starting from 1) as an argument. The function returns 1 for a buy and -1 for a sell. Ensure the index does not exceed the total number of filled records. ```XScript Value1 = FilledRecordBS(idx) ``` -------------------------------- ### Get Current Bar Number Source: https://xshelp.xq.com.tw/XSHelp/api?a=xfMin_GetCurrentBar&b=sys Retrieves the K-bar number for the specified frequency. This example shows how to use it to determine if it's the first bar and initialize a calculation. ```XScript value1 = xfMin_GetCurrentBar(FreqType); if Length + 1 = 0 then Factor = 1 else Factor = 2 / (Length + 1); if value1 = 1 then xfMin_XAverage = Series else xfMin_XAverage = lastXAverage + Factor * (Series - lastXAverage); ``` -------------------------------- ### Separate Print Files with StartTime Source: https://xshelp.xq.com.tw/XSHelp?HelpName=File&group=GENERALFUNC Utilize the [StartTime] parameter within the File function to create separate Print output files for each execution, which can be beneficial for file maintenance. This example demonstrates logging date and close price with dynamic filename generation. ```XScript 1Print(file("[StrategyName]_[Symbol]_[StartTime].log"), "Date=", NumToStr(Date, 0), "Close=", NumToStr(Close, 2)); ``` -------------------------------- ### Example: Calculate Average of Last 5 Closing Prices Source: https://xshelp.xq.com.tw/XSHelp/api?a=While&b=controlflow Demonstrates a practical application of the While loop to sum the last 5 closing prices and calculate their average. The loop terminates when the counter 'i' reaches 5. ```XScript SumValue = 0; While i < 5 Begin SumValue = SumValue + Close[i]; i = i + 1; End; AvgValue = SumValue / 5; ``` -------------------------------- ### Get StopConvertingSD Field Source: https://xshelp.xq.com.tw/XSHelp?HelpName=%E5%81%9C%E6%AD%A2%E8%BD%89%E6%8F%9B%E8%B5%B7%E5%A7%8B%E6%97%A5&group=FEVENT Retrieves the date of the last stop-conversion start using GetField. It can be accessed by its Chinese name or English alias. Check GetFieldDate for data availability. ```script Value1 = GetField("停止轉換起始日"); ``` ```script Value1 = GetField("StopConvertingSD"); ``` ```script Value1 = GetField("停止轉換起始日"); Value1 = GetField("StopConvertingSD"); ``` -------------------------------- ### Get Stock Buyback Volume Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E5%BA%AB%E8%97%8F%E8%82%A1%E5%AF%A6%E9%9A%9B%E8%B2%B7%E5%9B%9E%E5%BC%B5%E6%95%B8&b=filter Retrieves the actual volume of shares repurchased under a stock buyback program. Returns -2 if buyback has not started, or -1 if actual buyback volume is not yet announced. Use with related fields like buyback start date, end date, and expected repurchase volume. ```script Value1 = GetField("庫藏股實際買回張數"); Value1 = GetField("Stockbuyvalue"); ``` ```script Value1 = GetField("庫藏股實際買回張數"); Value1 = GetField("Stockbuyvalue"); ``` -------------------------------- ### Switch Statement Example with DayOfMonth Source: https://xshelp.xq.com.tw/XSHelp/api?a=Switch&b=controlflow Demonstrates how to use a Switch statement to perform actions based on the day of the month. It includes multiple Case conditions and a Default case for other scenarios. ```Pseudocode Value1 =DayOfMonth(date); Switch (value1) Begin Case 1: // value1=1時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日") ,"value1=1時執行這段程式碼"); Case 2: // value1=2時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日"), "value1=2時執行這段程式碼"); Case 3: // value1=3時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日"), "value1=3時執行這段程式碼"); Case 4: // value1=4時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日"), "value1=4時執行這段程式碼"); Case 5: // value1=5時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日"), "value1=5時執行這段程式碼"); Case 6 to 20: // value1= 6 ~ 20 時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日"), "value1=6~20時執行這段程式碼"); Default: // 其他情形都執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), "。是",numtoStr(DayOfMonth(date),0),"日"), "其他情形都執行這段程式碼"); End; ``` -------------------------------- ### Calculate Integer Part of a Number with IntPortion Source: https://xshelp.xq.com.tw/XSHelp/api?a=intportion&b=bif Use IntPortion to get the integer part of a number. For example, IntPortion(10.5) returns 10. Refer to FracPortion for the fractional part. ```xs Value1 = IntPortion(10.5); // Value1 = 10 Value2 = FracPortion(10.5); // Value2 = 0.5 ``` -------------------------------- ### Simulate Once Behavior with IF and Flag Variable Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=once&group=CONTROLFLOW This example demonstrates how to achieve the 'execute once' behavior using an IF statement and a boolean flag variable. The 'Once' keyword is generally more efficient for this purpose. ```XScript 1Var: FirstTime(False); 2If High = Highest(High, 5) And Not FirstTime Then 3Begin 4 HighDate = Date; 5 HighPrice = High; 6 FirstTime = True; 7End; ``` ```XScript Var: FirstTime(False); If High = Highest(High, 5) And Not FirstTime Then Begin HighDate = Date; HighPrice = High; FirstTime = True; End; ``` -------------------------------- ### Separate Print Files with StartTime Source: https://xshelp.xq.com.tw/XSHelp/api?a=File&b=bif Utilize the [StartTime] parameter in the File function to create separate Print files for each execution, aiding in file maintenance. Each symbol's Print output will generate an independent file. ```XQScript Print(file("[StrategyName]_[Symbol]_[StartTime].log"), "Date=", NumToStr(Date, 0), "Close=", NumToStr(Close, 2)); ``` -------------------------------- ### Get Stock Buyback Estimated Shares Source: https://xshelp.xq.com.tw/XSHelp/api?a=%E5%BA%AB%E8%97%8F%E8%82%A1%E9%A0%90%E8%A8%88%E8%B2%B7%E5%9B%9E%E5%BC%B5%E6%95%B8&b=filter Retrieves the estimated number of shares for a stock buyback. This field can be used with buyback start and end dates to determine its validity period. ```XScript Value1 = GetField("庫藏股預計買回張數"); Value1 = GetField("Stockestivalue"); ``` ```XScript Value1 = GetField("庫藏股預計買回張數"); Value1 = GetField("Stockestivalue"); ``` -------------------------------- ### Get Field Start Offset Source: https://xshelp.xq.com.tw/XSHelp/api?a=Getfield&b=bif Determines the number of bars between the current latest bar and the first data point of a specified field. Returns -1 if the field does not exist or its start offset exceeds the current bar position. Only supported in 'Stock Selection' script types. If frequency is not provided, it uses the current execution frequency. ```XScript 欄位筆數 = GetFieldStartOffset("欄位名稱") ``` ```XScript 欄位筆數 = GetFieldStartOffset("欄位名稱", "頻率") ``` -------------------------------- ### Basic GetField Usage Examples Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=GetField&group=FIELDFUNC Demonstrates retrieving field values with different parameter combinations. Use GetField to access current or historical data for your trading strategies. ```xs Value1 = GetField("收盤價"); // value1 為取得目前腳本執行頻率的收盤價。 ``` ```xs Value2 = GetField("收盤價", "1"); // value2 為取得原始1分鐘頻率的收盤價。 ``` ```xs Value3 = GetField("收盤價", "1", Adjusted:=true); // value3 為取得還原1分鐘頻率的收盤價。 ``` ```xs Value4 = GetField("本益比", "D", Default := 0); // 當運算的K棒沒有對應的本益比時,則回傳0。 ``` -------------------------------- ### Get Trade Record Time Source: https://xshelp.xq.com.tw/XSHelp/api?a=FilledRecordTimeMS&b=bif Retrieves the trade time for a specific trade record using its index. The index starts from 1 and must not exceed the total number of filled records. ```XScript Value1 = FilledRecordTimeMS(idx) ``` -------------------------------- ### Calculate and Plot Quarterly Change with QoQ Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=QoQ&group=PRICERELFUNC This example demonstrates how to use the QoQ function to calculate the quarter-over-quarter change of the closing price and then plot the resulting series. Ensure the data is at a quarterly frequency. ```XScript plot1(QoQ(close)); //繪製收盤價的季變化率連線 ``` -------------------------------- ### Switch Statement Example Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=switch&group=CONTROLFLOW Demonstrates how to use the Switch statement with multiple Case conditions and a Default case to handle different values of a variable. This example checks the day of the month. ```XScript Value1 =DayOfMonth(date); Switch (value1) Begin Case 1: // value1=1時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日") ,"value1=1時執行這段程式碼"); Case 2: // value1=2時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日"), "value1=2時執行這段程式碼"); Case 3: // value1=3時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日"), "value1=3時執行這段程式碼"); Case 4: // value1=4時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日"), "value1=4時執行這段程式碼"); Case 5: // value1=5時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日"), "value1=5時執行這段程式碼"); Case 6 to 20: // value1= 6 ~ 20 時執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日"), "value1=6~20時執行這段程式碼"); Default: // 其他情形都執行這段程式碼 print(Text("今天的日期是",numtoStr(date,0), ".是",numtoStr(DayOfMonth(date),0),"日"), "其他情形都執行這段程式碼"); End; ``` -------------------------------- ### NthDayOfMonth Source: https://xshelp.xq.com.tw/XSHelp/lists?a=DATERELFUNC Gets the date of the Nth occurrence of a specific weekday within a month, starting from a reference date. Retrieves the date of the Nth weekday (e.g., Sunday, Monday) after a given reference date. ```APIDOC ## NthDayOfMonth ### Description Gets the date of the Nth occurrence of a specific weekday within a month, starting from a reference date. ### Syntax `Return_Value = NthDayOfMonth(Reference_Date, Occurrence, Weekday)` ### Parameters #### Parameters - **Reference_Date** (number) - Required - The date in YYYYMMDD format. - **Occurrence** (number) - Required - The occurrence number. Positive for future dates, negative for past dates. - **Weekday** (number) - Required - The day of the week: 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, 4 for Thursday, 5 for Friday, 6 for Saturday. ``` -------------------------------- ### Cover Function Examples Source: https://xshelp.xq.com.tw/XSHelp/api?a=Cover&b=bif Demonstrates various ways to use the Cover function to reduce short positions. You can specify the quantity, a limit price, or a label for the order. ```xq Cover(1); ``` ```xq Cover(1, Close); ``` ```xq Cover(1, MARKET); ``` ```xq Cover(1, label:="回補1張"); ``` -------------------------------- ### Buy Function Execution Logic Source: https://xshelp.xq.com.tw/XSHelp/api?a=Buy&b=bif Illustrates the conditional logic of the Buy function, showing how it handles existing short positions before adding to long positions. ```XScript if Position < 0 then SetPosition(N) { 從Position(負數)變成N(正數) } else SetPosition(Position + N); { 從Position(零或是正數)變成Position+N } ``` -------------------------------- ### Get Buy-in Volume Field Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=%E8%B2%B7%E9%80%B2%E4%B8%AD%E5%96%AE%E9%87%8F&group=FVOLUME Use GetField to retrieve the buy-in volume. This can be accessed using the Chinese name '買進中單量' or the English alias 'BidVolume_M'. The examples show how to assign the retrieved value to a variable. ```xqscript Value1 = GetField("買進中單量"); ``` ```xqscript Value1 = GetField("BidVolume_M"); ``` ```xqscript Value1 = GetField("買進中單量"); Value1 = GetField("BidVolume_M"); ``` -------------------------------- ### Repeat/Until with Multiple Statements Source: https://xshelp.xq.com.tw/XSHelp/api?a=Repeat&b=controlflow Demonstrates how to execute multiple commands within a Repeat/Until loop using Begin and End keywords. This is necessary when more than one instruction needs to be performed in each iteration. ```XScript Repeat Begin 執行的指令1; 執行的指令2; End; Until 判斷式; ``` -------------------------------- ### Get '處置開始日期' Field Value Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=%E8%99%95%E7%BD%AE%E9%96%8B%E5%A7%8B%E6%97%A5%E6%9C%9F&group=FEVENT Use GetField to retrieve the start date of the disposition period. The field can be accessed using its Chinese name or its English alias 'DispositionSD'. Check GetFieldDate for data availability. ```script Value1 = GetField("處置開始日期"); Value1 = GetField("DispositionSD"); ``` ```script Value1 = GetField("處置開始日期"); Value1 = GetField("DispositionSD"); ``` -------------------------------- ### Example: Calculating Average Closing Price Source: https://xshelp.xq.com.tw/XSHelp/api?a=Repeat&b=controlflow An example illustrating the use of Repeat/Until to calculate the sum of the last five closing prices. The loop continues until the counter 'i' reaches 4, effectively summing five values (from index 0 to 4). ```XScript SumValue = 0; Repeat Begin SumValue = SumValue + Close[i]; i = i + 1; End; Until i = 4; AvgValue = SumValue / 5; ``` -------------------------------- ### Get '主力累計買賣超金額' using GetField Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=%E4%B8%BB%E5%8A%9B%E7%B4%AF%E8%A8%88%E8%B2%B7%E8%B3%A3%E8%B6%85%E9%87%91%E9%A1%8D&group=TCHIP Use GetField to retrieve the cumulative amount of major players' buying and selling transactions. Data is accumulated starting from 2023. This field is available for daily frequency and applicable to the index. ```script Value1 = GetField("主力累計買賣超金額"); Value1 = GetField("MBSCumAmount"); ``` ```script Value1 = GetField("主力累計買賣超金額"); Value1 = GetField("MBSCumAmount"); ``` -------------------------------- ### Conditional Return and Trigger Logic Source: https://xshelp.xq.com.tw/XSHelp/api?a=Return&b=controlflow This example demonstrates how to use Return to conditionally skip execution and then set a trigger based on market conditions. The script halts if the time condition is met, otherwise it checks for a new high close. ```XScript 4If Close > Close[1] and Close = High Then Ret = 1; ``` -------------------------------- ### Using MinList and MaxList in a Trading Strategy Source: https://xshelp.xq.com.tw/XSHelp/index?HelpName=MinList&group=NUMBERFUNC This script calculates the 5-day, 10-day, and 20-day moving averages and uses MinList to find the minimum of these averages. It then checks if the opening price is below this minimum and the closing price is above the maximum of these averages to trigger a signal. Requires prior calculation of moving averages. ```XQScript Value1 = Average(Close, 5); Value2 = Average(Close, 10); Value3 = Average(Close, 20); If Open < MinList(Value1, Value2, Value3) And Close > MaxList(Value1, Value2, Value3) Then Ret = 1; ``` ```XQScript Value1 = Average(Close, 5); Value2 = Average(Close, 10); Value3 = Average(Close, 20); If Open < MinList(Value1, Value2, Value3) And Close > MaxList(Value1, Value2, Value3) Then Ret = 1; ```