Doubt about "ISNULL" function

Hello,

Apparently I am not using "ISNULL" function properly, but I am unable to understand why.

Please check the attached images, from a simple example. I created an indicator which is supposed to warn about emptly quotes of "CLI.EU", when checking "SPY".

B = IsNull(Foreign("CLI.EU", "C"));
Plot(B, "B", colorRed, styleLine, Null, Null, 0, 0, 2);

Since "CLI.EU" has empty quotes for 31/05 and 29/06, the indicator should be "B = 1" for those months, but obviously I am doing something wrong because "B = 0"

I will thank your help to understand what I am doing wrong.

Best regards.

Screen%2001Screen%2002

@jptrader When you access foreign security data using Foreign(Ticker, Datafield, fixup) pay special attention to the fixup parameter which is responsible for dealing with data holes. You need to use Foreign() with fixup parameter set to 0 (zero or false) to get the results that you expect. (By default it is set to 1 - true):

B = IsNull(Foreign("11B", "C", 0));
Plot(B, "B", colorRed, styleLine, Null, Null, 0, 0, 2);

Fixup

A quote from: https://www.amibroker.com/guide/afl/setforeign.html

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


4 Likes

Milosz,

Thank you for your answer.

There must be something else, after changing to Fixup 0, the formula keeps on failing.

Screen%201

Screen%202

The result should be 0 until 30/04/18 and 1 from 31/05/18. Instead of that, the formula keeps 0 all the time when applied to "CLI.EU", and it keeps 1 all the when applied to "SPY", in the case of the example.

Do you have an aditional idea of what I keep doing wrong?

Regards.

You are using MONTHLY chart. Switch to DAILY !

Tomasz,

Thank you for your answer.

I would need to use the formula in a monthly basis provided that the system works in that time frame.

"CLI.EU" has only one daily close for the whole month.

Screen%2001

It represents the Composite Leading Indicator for Euro Zone by OCDE. I use those indicators as filters for certain monthly systems, like in the following example:

LongCLI = Ref(Foreign("CLI.EU", "Close"), -1) >= Ref(Foreign("CLI.EU", "Close"), -2);
ShortCLI = Ref(Foreign("CLI.EU", "Close"), -1) < Ref(Foreign("CLI.EU", "Close"), -2);

Buy = LongCondition1 AND LongCondition2 AND LongCLI;
Short = ShortCondition1 AND ShortCondition2 AND ShortCLI;

I will represent the filter by the following formula:

LongCLI = Ref(Foreign("CLI.EU", "Close"), -1) >= Ref(Foreign("CLI.EU", "Close"), -2);
ShortCLI = Ref(Foreign("CLI.EU", "Close"), -1) < Ref(Foreign("CLI.EU", "Close"), -2);

B = IIf(LongCLI, 1, IIf(ShortCLI, -1, 0));
Plot(B, "B", colorRed, styleLine, Null, Null, 0, 0, 2);
Plot(0, "0", colorBlue, styleLine, Null, Null, 0, 0, 1);

This is the result:

imageI

image

As you can check, "CLI.EU" ticker is falling down by the last close available (30/04), and consequently the filter shows B = -1. However, if I applyied that formula to "$SXXP-STX" (whose last close availible is 20/07), the filter turns up and shows B = 1 for those month without data for . "CLI.EU". I intend that the filter shows B = 0 in that case.

If I switch to daily chart and I use the formula from the original example, it works as shown in the following image:

B = IsNull(Foreign("CLI.EU", "C", 0));
Plot(B, "B", colorRed, styleLine, Null, Null, 0, 0, 2);

image

B = 0 for the first day of every month, if it is a working day, since "CLI.EU" has data just for the first day of every month. It works fine in a daily chart, but I would need to use it in a monthly basis.

Thank you in advance for your help.

Regards.