SetForeign
- replace current price arrays with those of foreign security

Referencing other symbol data
(AmiBroker 4.50)


SYNTAX SetForeign( ticker, fixup = True, tradeprices = False )
RETURNS NUMBER
FUNCTION The SetForeign function replaces current price/volume arrays with those of foreign security, returns True (1) if ticker exists, False (0) otherwise.

If ticker does not exist (and function returns false) price arrays are not changed at all.

fixup parameter controls if data holes are filled with previous bar data or not.

  • 0 - the holes are not fixed
  • 1 - default value - missing data bar OHLC fields are all filled using previous bar Close and volume is set to zero.
  • 2 - (old pre-4.90 behaviour) - causes filling the holes in the data with previous O, H, L, C, V values

tradeprices parameter controls if trade price arrays should be replaced too. If it is set to TRUE, then not only OHLC, V, OI, Avg arrays are set to foreign symbol values, but also BuyPrice, SellPrice, ShortPrice, CoverPrice, PointValue, TickSize, RoundLotSize, MarginDeposit variables are set to correspond to foreign security. This allows Equity() to work well with SetForeign.

Single SetForeign( "ticker" ) call is equivalent to the following sequence:

C = Foreign( "ticker", "C" );
O = Foreign( "ticker", "O" );
H = Foreign( "ticker", "H" );
L = Foreign( "ticker", "L" );
V = Foreign( "ticker", "V" );
OI = Foreign( "ticker", "I" );
Avg = ( C + H + L )/3;

but 6x faster (SetForeign takes about the same time as single foreign). To restore original prices call RestorePriceArrays()

EXAMPLE // Example 1: Plot the indicator using foreign security data
SetForeign("MSFT");
Plot( Ultimate(), "Ultimate from MSFT", colorRed );
RestorePriceArrays();

// Example 2: Use SetForeign with Equity function
SetForeign("MSFT", True, True );
Buy = Cross( MACD(), Signal());
Sell = Cross( Signal(), MACD());
e =
Equity(); // backtest on MSFT
RestorePriceArrays( True ); // <- should match parameter used in SetForeign

SEE ALSO FOREIGN() function , RestorePriceArrays() function

References:

The SetForeign function is used in the following formulas in AFL on-line library:

More information:

See updated/extended version on-line.