DAS Script Events, Exec and Script Reuse
Distinguish script text from execution with GetHotkeyScript, Exec and ExecHotkey.
More than a key press
The June 2025 guide describes a Timer Event that runs every second, a Chart Update Script, alert-triggered scripts and a Desktop Load Script. They have different contexts. None should be treated as an automatically reliable broker fill callback.
| Entry point | Lesson use | Condition to verify |
|---|---|---|
| Manual hotkey | Inspect one named object | Current target and account |
| Chart update | Refresh a displayed calculation | Correct chart and study |
| Timer Event | Observe a value periodically | Enabled state and stop behavior |
| Desktop load | Initialize practice variables | Named windows restored |
| Alert script | React to a configured condition | Repeated triggers and context |
Reuse is a dependency, not isolation
ExecHotkey(...) runs a named hotkey from the hotkey file. Inspect that hotkey's body and global variables before calling it. A harmless-looking caller can invoke a script with trading or external-process effects.
A useful design is prepare → inspect → explicitly enable → request → reconcile → reset. These are workflow states you design; they are not names of built-in DAS functions. Bind the prepared state to its account, symbol and inputs. Invalidate it when any of them changes.
A reusable helper with an explicit dependency
In the hotkey editor, name a helper FE_PracticeMessage and give it only the following body. Advanced Script · message only.
MsgBox("Practice helper");
Then create the caller. Advanced Script · invokes the inspected helper. This depends on the name resolving to the exact body above. Changing the helper changes the caller's effects.
ExecHotkey("FE_PracticeMessage");
Lab: observe and stop
Use a timer only to refresh a practice variable from a named quote. Compare it with the one-shot read from lesson 4. Record when it updates, how it stops, and what happens on disconnect and reconnect. Disable the timer when finished. Test reuse first with a helper containing only MsgBox("Practice helper");.
Exec, GetHotkeyScript and ExecHotkey
| Interface | Input | Effect |
|---|---|---|
GetHotkeyScript("name") |
Hotkey name | Retrieves its script text |
Exec(script) |
Script text or a variable holding it | Interprets and executes the text |
ExecHotkey("name") |
Hotkey name | Executes the named script in the hotkey file |
The spelling is GetHotkeyScript, not GetHokeyScript. Retrieving text does not execute it; a hotkey name is not a script body. A helper can have a name without a physical key binding and be called by other scripts.
Inspect, then execute the same text
Keep FE_PracticeMessage exactly as defined above. Advanced Script · Retrieves and displays helper source only.
$feHelperText = GetHotkeyScript("FE_PracticeMessage");
MsgBox($feHelperText);
Expect to see the source MsgBox("Practice helper");. Missing names, duplicate names and unloaded files have not been client-tested here. Confirm the dependency in the editor and do not pass an unknown result directly to Exec.
After closing the preview, ensure no other script has overwritten $feHelperText. Advanced Script · Executes the inspected message body. This depends on the preceding retrieval succeeding.
Exec($feHelperText);
Now expect Practice helper, rather than its source code. Editing the helper does not automatically rewrite text already retrieved into a variable. Retrieve again and inspect again. Keep the source you reviewed connected to the body you actually execute.
Once the current helper body is verified, the operations can be combined. Advanced Script · Retrieves and immediately executes the inspected message helper.
Exec(GetHotkeyScript("FE_PracticeMessage"));
Like ExecHotkey("FE_PracticeMessage");, this is an execution entry point, not an inspection step. Know the current helper body's effects before calling it.
Quoting a script inside a string
Advanced Script · Executes a fixed message script. Escape double quotes inside the outer string with backslashes. Preserve ASCII quotes and backslashes when copying.
Exec("MsgBox(\"Practice helper\");");
The actual text passed to Exec is MsgBox("Practice helper");. Without escaping, an inner quote can terminate the outer string and change what the parser reads.
The guide also documents Exec(script1, script2, ...) and ExecHotkey(name1, name2, ...). Sequencing snippets is not a transaction: a later error does not undo an earlier external action. Reuse is also not a custom function call with isolated local variables.
Lab: distinguish a name, source and output
Run source display, execution of saved text, and execution by name in that order. Predict each output on paper before testing. Edit the helper message and compare the old stored text with newly retrieved text. Inspect the call graph for self-calls or an A-to-B-to-A cycle.
Do not pass uninspected input, pasted code or external content to Exec. Orders, Locate actions and external effects inside that text become executable behavior. The next lesson applies this distinction to Alert callbacks.
A named script is not a function declaration
ExecHotkey executes a saved body by name; it is not a function you declared with private locals. Inspect its dependencies before the call and its explicit outputs afterward. GetHotkeyScript retrieves text; Exec executes that text. Interpolating untrusted input into source promotes data into code.
A reusable body specifies required inputs, which stale outputs it resets, success outputs, and how consumers identify failure. Never depend on last run's $feResult. See a complete calculation helper in Script modules and calling contracts.
Callbacks need a lifecycle
Save the previous callback before installing a minimal message-only body. Observe whether one trigger causes one execution, then remove it and confirm execution stops. Once a Timer is involved, avoid a click-to-dismiss dialog on every tick; the official guide discusses blocking interaction in Timer scripts.
Worked answer
Displaying retrieved hotkey source does not execute its effects; Exec crosses that boundary. A missing-name return value remains unconfirmed, so an empty-value check cannot be advertised as a universal guarantee. Case differences do not isolate a shared variable: use consistent ownership and input/output conventions.