FennEdge Learn · Programming

DAS Trader Advanced Hotkey Script Course

Understand the code. Inspect the state. Verify the outcome. A detailed path through Advanced Script: language, data structures, order objects, event workflows and complete practice projects.

Plan about 1046 minutes including reading, worked examples, and each lesson exercise; actual time varies.

36Lessons≈1046Est. minutes—Sign in to save progress
03
Lesson 3 of 36 · About 24 min

DAS Script Conditions, Early Exits and Shared State

Validate before computing; initialize before reuse.

Make invalid input take a visible path

Advanced Script · calculation only. This exercise computes a price distance; it does not choose an entry or send an order.

$feUpper = 18.4;
$feLower = 18.1;
$feDistance = 0;
if ($feUpper > $feLower) {
    $feDistance = $feUpper - $feLower;
} else {
    MsgBox("Check the input order");
    return;
}
MsgBox($feDistance);

For the stated inputs, the mathematical distance is 0.30. Setting both values equal should take the early-exit branch. The explicit reset prevents a previous result from being mistaken for a new result when inputs are invalid.

Assignment and comparison

= assigns a value. The official condition example uses == to compare equality. Braces group a branch; return; ends the script. Do not import JavaScript syntax such as ===, promises or exception handling without a DAS source.

The June 2025 guide documents while with a maximum of 200 iterations. That is a documented limit for that guide, not a promise that a busy loop is a suitable scheduler. Use a finite pure calculation to learn loops; never use a loop to wait for a fill.

A loop with an explicit endpoint

Advanced Script · calculation only. Sum 1, 2 and 3; the expected result is 6. The counter advances on every iteration until the condition becomes false. Termination is part of the program, not delegated to the platform limit.

$feCounter = 1;
$feTotal = 0;
while ($feCounter < 4) {
    $feTotal = $feTotal + $feCounter;
    $feCounter = $feCounter + 1;
}
MsgBox($feTotal);

Lab: a four-case matrix

Run positive distance, equal inputs, reversed inputs and a second run after changing inputs. Write down the expected branch for each case first. For later workflows, define reset conditions for account changes, symbol changes and layout reloads. Global variable reuse across hotkeys must be deliberate.

Store validity separately from value

Resetting a result to zero is insufficient when zero can be a valid result. Set a separate $feReady=0, changing it to 1 only after all prerequisites pass. Consumers check readiness before using a result; Script modules develops this into an explicit input/output protocol.

return; ends the current execution without undoing earlier assignments or window changes. Put reads, validation and calculations before effects. This is still not a database transaction and cannot stop external state changing after validation.

A loop needs its own termination proof

The counter starts at 1, increases each iteration and exits at 4, so the body runs three times. Without the increment, the platform iteration limit may stop it, but that is fault containment, not an algorithm. Bound collection processing by a known record count below the documented limit; split larger work into batches instead of assuming unlimited iteration.

Four-case answers and retest order

Inputs Branch Usable result
18.4 / 18.1 Positive distance Mathematical value 0.30
18.1 / 18.1 Message and exit No new valid result
18.1 / 18.4 Message and exit No new valid result
Valid case immediately followed by invalid case Initialize again, then exit Cannot reuse the previous 0.30

The final case reveals stale global state that isolated tests miss. Account changes, symbol changes, desktop restores and script restarts all require a fresh check of input identity.