DAS Script Chart Bars, Studies and Observation Windows
Inspect bar fields and build calculations without assuming closed-bar semantics.
Define the chart contract before the formula
Prerequisite: collections and named windows. A bar depends on symbol, interval, session inclusion, loaded history and position in the chart. GetBar(-5) is documented as the fifth-last displayed bar; displayed is not a guarantee that it is closed. The guide demonstrates the HI field. Do not silently substitute High, Close or Timestamp from a different API.
Inspect a bar and a study together
$feChart = GetWindowObj("feChart");
$feBar = $feChart.GetBar(-5);
$feBar.ShowObject();
$feBarHigh = $feBar.HI;
$feStudy = $feChart.GetStudyVal("feVwap");
MsgBox($feBarHigh, $feStudy);
Preconditions and interpretation
Advanced Script · read and display. Configure feChart and feVwap and load at least five displayed bars. GetStudyVal reads the latest value of the named study, not necessarily the value at the bar returned by GetBar(-5). Subtracting these values combines two different time positions. That may be your intended calculation, but it must be labeled accordingly. A study with multiple outputs needs its own configuration check; this guide does not establish a universal output-index parameter.
Build a bounded observation window
First verify -1, -2 and -3 against the visible chart in your build, including whether the newest displayed bar is still forming. Then the following extension collects three HI values. It is conditional on that index verification; it does not define "last three completed candles". Do not use the loop before verifying sufficient history and missing-bar behavior.
Index-verified extension
$feBarHighs = NewUserObj();
$feOffset = 1;
while ($feOffset < 4) {
$feCurrentBar = $feChart.GetBar(0 - $feOffset);
$feBarHighs.Set($feOffset, $feCurrentBar.HI);
$feOffset = $feOffset + 1;
}
$feBarHighs.ShowObject();
Exercise and worked answer
With verified highs 21.20,21.35,21.10, calculate the maximum using the collection loop from the prior lesson. Answer: initialize from key 1, compare keys 2 and 3, giving 21.35. Repeat after changing only the chart interval and record why the window now describes different observations. Keep retrieval time and bar position in the record; a new bar arriving during the loop can shift relative indices. This is not an atomic historical snapshot API.