Create and review XS scripts with current XQ semantics, explicit script-type boundaries, and honest validation limits.
Classify the request
Determine these facts before writing code:
- Select the artifact type: indicator, sensor/alert, filter/stock selection, autotrade, or function.
- Identify the market, symbol class, bar frequency, and whether the task uses historical, real-time, backtest, or live-trading data.
- Separate the user's entry/exit idea from execution details such as target position, order price, quantity, and risk controls.
- Ask only for missing facts that materially change the script. State safe, reversible assumptions for the rest.
Read references/xs-language-guide.md when choosing a script header, declaration form, data API, or trading primitive.
Ground claims in the right source
Use this order of authority:
- Use XSHelp for current language and function semantics.
- Use XScript_Preset for official system-script idioms across script types.
- Use XS_Blocks for selection, alert, and ranking-block patterns.
- Use XQStrategy for stock-selection condition examples.
- Use vscode-xs only for lexical clues and editor support, never as semantic authority.
Read references/source-map.md before researching syntax or reusing an upstream example. Verify unstable details live. Cite the exact help page or repository path when a non-obvious API or compatibility claim affects the result.
Do not assume that similarity to EasyLanguage or PowerLanguage implies compatibility. Do not invent a function, field, frequency, or script-type capability when the official sources do not establish it.
Write or modify a script
- Put the correct
{@type:...}header on the first line. - Keep inputs, variables, arrays, and calculation stages easy to audit.
- Prefer built-in XS functions when their semantics match the requirement.
- Guard insufficient history, zero denominators, unsupported fields, frequency mismatches, and real-time-only data where relevant.
- Keep trigger logic separate from plotting, output fields, or order execution.
- Add concise Traditional Chinese comments when the user does not specify a language.
- Preserve the existing style and behavior when editing user code unless the requested correction requires a change.
For autotrade code, distinguish Position (target position) from Filled
(executed position). Make target size, order price, entry, exit, and
stop/risk behavior explicit. Never silently turn an alert or research rule into
a live order path.
Review or debug a script
Inspect the smallest reproducible section first. Report findings in this order:
- compile or syntax blockers;
- wrong script-type or unsupported-API use;
- look-ahead, frequency, history-window, and real-time/backtest errors;
- order and position-state risks;
- numerical edge cases;
- maintainability improvements.
Preserve the user's intended trading logic unless they ask for strategy redesign. Explain behavioral changes in plain language and show a minimal patch or corrected script.
Read references/review-checklist.md for the full review and confidence checklist.
Validate and report
Run all validation that the available environment supports:
- inspect the script header, declarations, delimiters, references, and type restrictions;
- compare non-obvious functions and fields with current XSHelp;
- compare the pattern with a relevant official system script;
- compile in the XQ XScript editor and run the appropriate historical, simulation, or paper-trading test when that environment is available.
There is no bundled standalone XS compiler. If the XQ editor was not used, say
static review only; XQ compile/runtime validation not performed. Never call a
script validated merely because it looks like EasyLanguage or matches an old
example.
Return:
- the chosen script type and assumptions;
- the complete or patched XS code;
- a short explanation of the logic;
- validation performed and remaining XQ-side checks;
- a risk note for autotrade or strategy requests.
Respect source and financial boundaries
Treat upstream repositories and XSHelp as references. Link and paraphrase by default. Do not mirror or bulk-copy code whose license does not permit redistribution. Keep excerpts minimal and attribute their exact source.
Treat generated strategy code as a software artifact, not an investment recommendation. Do not claim profitability, safety, or production readiness without evidence from the user's own XQ environment and data.