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
09
Lesson 9 of 36 · About 30 min

DAS Script Collections, Numeric Keys and Bounded Loops

Build and aggregate a collection with Set/Get/Del without assuming JavaScript arrays.

An indexed object is not a JavaScript array

Prerequisite: NewUserObj and while. The guide demonstrates array-like structures using numeric keys on a user object. Keep a count yourself and choose whether indices begin at zero. Bracket syntax, push, map, filter and length are not established by this example. A numeric key must be accessed through Set/Get, not .0.

A complete bounded aggregate

$feSamples = NewUserObj();
$feSamples.Set(0, 8);
$feSamples.Set(1, 12);
$feSamples.Set(2, 10);
$feCount = 3;
$feIndex = 0;
$feSum = 0;
$feMaximum = $feSamples.Get(0);
while ($feIndex < $feCount) {
    $feValue = $feSamples.Get($feIndex);
    $feSum = $feSum + $feValue;
    if ($feValue > $feMaximum) {
        $feMaximum = $feValue;
    }
    $feIndex = $feIndex + 1;
}
$feMean = $feSum / $feCount;
MsgBox($feSum, $feMean, $feMaximum);

Loop invariants and empty input

After processing index k, sum contains exactly k+1 values and maximum covers the same prefix. The expected output is 30, 10 and 12. The loop starts at zero and stops before count. Every iteration advances the index. Before adapting this to dynamic data, add a count>0 check before Get(0) and division. A zero initial maximum is wrong for an all-negative collection; initializing from the first verified element avoids that error.

Deletion leaves a schema decision

Del(1) removes a key; it does not document shifting key 2 into key 1 or decrementing count. Either rebuild dense keys after deletion or maintain an explicit list of valid keys. Del("*") clears fields but does not reset your separate count global. The documented 200-loop ceiling is a runtime safeguard, not a useful target. Chunk larger offline calculations deliberately; never busy-loop on network or order state.

Exercise and worked answer

Change samples to -4,-9,-2 and predict the maximum. Answer: -2, with a total of -15 and mean -5. Then delete index 1. A correct next step is to rebuild keys 0 and 1 from the two retained values and set count=2, giving total -6 and mean -3. Simply leaving count=3 would read a missing key.