Data Return
Previous  Top  Next

Returning multiple values is possible, but for advanced users only.

Once you have computed your indicators, there are two distinct ways to return the values: implicit and explicit.

Implicit data return

When your expression is evaluated, the value is taken to be the indicator value you wish to display. For example, if you enter


in the Choose Expression Dialog, you will get the net change for each stock. The value you wish to display is exactly the value of the expression.

As your usage gets more sophisticated, you may wish to return two values, for example, a fast and a slow moving average. An explicit data return is required for that.

Explicit data return

The example study OHLCStudy is available in all four Language Modes and it demonstrates explicit data return. This study has 6 return values, namely the date, the open, the high, the low, the close, and the volume of the current day for each stock.

In Visual Basic,

function OHLCStudy()
UA.Title = "OHLC"
call UA.SetReturn(1,UA.GetDate(0),"Date","%.0lfC")
call UA.SetReturn(2,UA.GetPrice(1,0),"Open","%.4lfL")
call UA.SetReturn(3,UA.GetPrice(2,0),"High","%.4lfL")
call UA.SetReturn(4,UA.GetPrice(3,0),"Low","%.4lfL")
call UA.SetReturn(5,UA.GetPrice(4,0),"Close","%.4lfL")
call UA.SetReturn(6,UA.GetVol(0),"Vol","%.0lfL")
OHLCStudy = 2
end function

In JavaScript,

function OHLCStudy() {
//example OHLCStudy() = Returns the current OHLC
UA.SharePriceScale = 1;

In Perl,

sub OHLCStudy {
@UAIndicatorLabels = ('Date', 'Open', 'High', 'Low', 'Close', 'Vol');
@UAIndicatorDisplayFormat = ('%.0lfC','%.4lfL','%.4lfL','%.4lfL','%.4lfL','%.0lfL');
$UAIndicatorTitle = 'OHLC';
return (@Date[0], @Open[0], @High[0], @Low[0], @Close[0], @Vol[0]);

In AnyLanguage,

function OHLCStudy
'example Data Access\OHLCStudy() = Returns the current OHLC
'MenuText Data Access\Open, High, Low, and Close
UA.SharePriceScale = 1;
UA.MostRecentDataEarlyInArray = 1;
call UA.SetReturn(1,UA.GetPrice(1,0),"Open","%.4lfL");
call UA.SetReturn(2,UA.GetPrice(2,0),"High","%.4lfL");
call UA.SetReturn(3,UA.GetPrice(3,0),"Low","%.4lfL");
call UA.SetReturn(4,UA.GetPrice(4,0),"Close","%.4lfL");
OHLCStudy = 2;
end function

In each case, the number of return values is set to six, the Title is set to "OHLC", and the six return values are set as the current date, open, high, low, close, and volume respectively. When using the SetReturn function, one should index which return, what value, what the column name should be, and the display format. The display formats are all "%.xlfY" where x is the number of decimal digits and Y is whether the column should be L-left justified, R-right justified, or C-center justified.