SetForeign Function- Erratic behaviour

#1
Hello,

I use setforeign function and got confused with the results.

The AFL I used is as follows.


SetForeign("NIFTY-I");
tC = C;
YC=TimeFrameGetPrice("C",inDaily,-1); // Get yesterdays close price using this mehtod also.
y1c = Ref(C,-1);

RestorePriceArrays();


Filter = StrFind(Name(),"NIFTY");

AddColumn(yC,"Foreign YC - TFget function",1.2,IIf(tC >yc, colorGreen, colorRed));

AddColumn(y1C,"Foreign Yesterday-Close",1.2,IIf(tC >yc, colorGreen, colorRed));

AddColumn(tC,"Foreign today-Close",1.2,IIf(yC > Ref(yC,-1), colorGreen, colorRed));

when I run this afl over a watchlist The Close values of foreign symbol differs for few symbols. Why this deviation when the foreign symbol is the same?

Looking forward for your valuable guidance.

Regards,
BP
 

trash

Well-Known Member
#2
I don't use Nifty as I am not Indian.

But to explain tc, yc and y1c

If you use periodicity other than daily in AA settings then tc and y1c do not output todays close or yesterday's close but current bar's close and previous bar's close. On the other hand yc always outputs previous day's close as long as periodicity is <= daily time frame in periodicity settings of AA settings. If you just wanna output today's and yesterday's close then all you need is tc and y1c and periodicity being set to Daily in AA settings. So you don't need Timeframegetprice for that.

What is NIFTY-I? Is that the main Indian index? Since this is just one symbol included in setforeign function it always outputs the results of just that symbol and no other.

If you want to output the close prices of your watchlist you need to do it differently.

Either you use Apply to > Filter and choose to include your watchlist and set to daily in AA settings 'General'>'Periodicity' and in addition using this code for just the last results of the data base

Code:
tC = C;
y1c = Ref(C,-1);

Filter = Status("lastbarinrange");
AddColumn(tC,"Foreign today-Close",1.2,IIf(tC > y1c, colorGreen, colorRed));
AddColumn(y1C,"Foreign Yesterday-Close",1.2,IIf(tC >y1c, colorGreen, colorRed));
or this one to get all results of the data base

Code:
tC = C;
y1c = Ref(C,-1);

Filter = 1;
AddColumn(tC,"Foreign today-Close",1.2,IIf(tC > y1c, colorGreen, colorRed));
AddColumn(y1C,"Foreign Yesterday-Close",1.2,IIf(tC >y1c, colorGreen, colorRed));

//======================================================
OR another method is using these ones
that add function inWatchlist(your watchlist number) to Filter setting of your code
For these following two codes set 'Apply to' to 'All quotes' (instead of setting it to 'Filter') and like above set to daily in AA settings 'General'

Code:
tC = C;
y1c = Ref(C,-1);

Filter = InWatchList(0) AND Status("lastbarinrange");
AddColumn(tC,"Foreign today-Close",1.2,IIf(tC > y1c, colorGreen, colorRed));
AddColumn(y1C,"Foreign Yesterday-Close",1.2,IIf(tC >y1c, colorGreen, colorRed));
or again this one for all results of the data base

Code:
tC = C;
y1c = Ref(C,-1);

Filter = InWatchList(0);
AddColumn(tC,"Foreign today-Close",1.2,IIf(tC > y1c, colorGreen, colorRed));
AddColumn(y1C,"Foreign Yesterday-Close",1.2,IIf(tC >y1c, colorGreen, colorRed));
InWatchlist(0) means that it outputs results of Watchlist '0' so you have to insert your own watchlist number.
 
#3
Sincere thanks for your time and suggestions.

I needed to select Daily TF , rather than lesser timeframes than Daily.. Then tc (today's close) and y1c (Yesterday's close) values get picked correctly. TimeframegetPrice function is not needed. It is used for cross checking.

The confusion is, with the same code if I select a lesser timeframe (say 120 mins) then for some symbols, for y1c value, either C or Ref(C,-1) gets displayed in the AA list even though the Foreign symbol is the same.

//_________________
What is NIFTY-I? Is that the main Indian index? Since this is just one symbol included in setforeign function it always outputs the results of just that symbol and no other.
//__________________

Yes, Indeed. I needed to get the change in the value of the index to compare with that of the symbol in the watchlist. Hence the use of setforeign function.

Once again, Thank You.
 
#4
Do you mean that tc and y1c are equal on some occasions? Sorry I also don't understand your problem because I don't see any. To reproduce your problem I added a condition

Code:
SetForeign("EURUSD");
tC = C;
YC=TimeFrameGetPrice("C",inDaily,-1); // Get yesterdays close price using this mehtod also.
y1c = Ref(C,-1);
Cond= y1c == tc;
RestorePriceArrays();


Filter = StrFind(Name(),"EUR");

AddColumn(yC,"Foreign YC - TFget function",1.5,IIf(tC >yc, colorGreen, colorRed));

AddColumn(y1C,"Foreign Yesterday-Close",1.5,IIf(tC >yc, colorGreen, colorRed));
AddColumn(tC,"Foreign today-Close",1.5,IIf(yC > Ref(yC,-1), colorGreen, colorRed));
AddColumn(Cond,"y1c == tc?",1,IIf(tC >yc, colorGreen, colorRed));
And cond is never 1 with lower timeframe. Maybe your data is corrupted?
 
#5
Do you mean that tc and y1c are equal on some occasions? Sorry I also don't understand your problem because I don't see any. To reproduce your problem I added a condition

And cond is never 1 with lower timeframe. Maybe your data is corrupted?
I may be wrong. but could not understand why these change in values.

I have added a screen shot for the AA results..(picture is trimmed to bring the size under 100kb) when I run the following code at 120 min TF.

The code is as follows:

SetForeign("NIFTY-I");
tC = C;
YC=TimeFrameGetPrice("C",inDaily,-1); // Get yesterdays close price using this mehtod.
y1c = Ref(C,-1);

RestorePriceArrays();


Filter = StrFind(Name(),"NIFTY") AND Status("lastbarinrange");;

//Filter = 1;

AddColumn(yC,"Foreign YC - TFget function",1.2,IIf(tC >yc, colorGreen, colorRed));

AddColumn(y1C,"Ref(C,-1)",1.2,IIf(tC >yc, colorGreen, colorRed));

AddColumn(tC,"C",1.2,IIf(yC > Ref(yC,-1), colorGreen, colorRed));

//Actual Close values in 120 min chart for the Foreign symbol.
//Last Bar Close = 5191
//Previous bar Close = 5188.75
 

Attachments

#6
It could be the case that not all symbols have the same end date. I get correct results using my data base. Can you upload your data base in a zip file (to rapidshare or some other file storage provider) or is it too large? Maybe giving the upload link by using PM. It's difficult to encrypt and reproduce what you are doing there. Have you send it to support of Amibroker because they get paid for.
 

Similar threads