Unexpected result with 'Foreign'

I have the following simple code which compiles without problems.

V1 = C;
V2 = C;
V3 = C;
V4 = C;
V5 = C;
V6 = C;
V7 = C;
VEUR = (V1+V2+V3+V4+V5+V6+V7)/7;
Plot( VEUR, "VEUR", colorWhite, stylethick |styleNoTitle );

It is supposed to run as subchart under whatever other chart.
I'm connected to Interactive Brokers, so the data should be available.
But instead of the expected result it simply draws a linechart
of the mainchart to which the code was associated...
  1. You should not do like you do in first post.

    Instead you should do like this

    total= 0;
    for (i = 0; (ticker = StrExtract(ticker_list, i)) != ""; i++) 
    	total+= Nz(Foreign(ticker, "C"));	
    sym_num = StrCount(ticker_list, ",")+1;
    VEUR = total/sym_num;
    Plot(VEUR, "VEUR", colorWhite, stylethick |styleNoTitle );

    In addition you might use static variables for storage of result (after some trigger event)
    as posted today here: Intra day volume for nifty 50 index

  2. Your symbols are not inline with Interactive Brokers symbology
    Please read here

    So e.g. EURUSD symbol on IdealPro would be EUR.USD-IDEALPRO-CASH
    So since your symbols are not proper IB symbols you won't get expected results.

1 Like

Thank you very much for your answer.
I changed all the symbols and all seemed to work out fine,
but the result doesn't correspond to the result I got with my original
script in easylanguage. It should be 18.xx actually, because the
average rises as the EURJPY is at 124.xx actually...
while I obtain now 0.169xx


Ok, I found the problem, as it seemed to exclude the JPY as it was not
integrated in my amibroker database, but I thought that this would not be necessary
with 'foreign' as my aim was to establish the same chart also with the
other 7 currencies to compare their relative strength, but without
integrating all the details in my amibroker database.
So doesn't it work like I expected with 'foreign' ?


You need to add symbols to DB first.

Foreign calls existing symbols data of DB. It is does not create/add symbols.
Please read documentation.
Nowhere is it said that Foreign() function creates symbols.