All scripts with first candle of the day without Gapup

Hi Gurus,

I am writing an exploration program in which I need to identify all those stocks whose first candle hasn't opened in gap-up (from previous day close).

I have written the below code but it's not working. What am I doing wrong? Can anybody help?

dn = Day();
bi = BarIndex();
newDay = dn != Ref( dn, -1 );
Gap_Up = GapUP();
Filter = (newDay != Gap_Up);

Hi
Please read the manual
https://www.amibroker.com/guide/afl/gapup.html

Τhe GapUp() function returns "one" or "zero"
you may use this exploration for EOD data to find NOT GapUp day

Gap_Up = GapUP();  

Filter = Gap_Up ;    // or  Filter = Gap_Up < 1;

AddColumn( Close, "Close" ); 
AddColumn( Gap_Up, "Gap_Up",1);

// Not a GapUP() Gives a "0" 
AddColumn( Gap_Up < 1 , "Not Gap_Up",1);
1 Like

Hello Pano,

Thanks for suggesting a solution.

But in exploration, the function Gapup() will scan the last created candle at a given time and not the first candle created on that day. My requirement is the later one.

To summarize, I need to write a code which explicitly scans the first candle created of all stocks which hasn't opened in gap up.

Evidently from its description as Previously posted by PanoS:

A gap up occurs if yesterday's high is less than today's low.

Since, the Periodicity of your Analysis is less than Daily, this might help:

NewDay = Day() != Ref( Day(), -1 );
/*
//Or
bi = BarIndex();
NewDay = bi == TimeFrameExpand( TimeFrameCompress( bi, inDaily, compressOpen ), inDaily, expandFirst );
*/
YstrdDayH = TimeFrameGetPrice( "H", inDaily, -1, expandFirst );
LowOfTodaysFirstBar = ValueWhen( NewDay, L );
//If the code compares Today's Low to Previous Day's High using in-built GapUp(),
//it is no longer validating the Days First Bar as the Day progresses, is it?
GapUpCond = YstrdDayH < LowOfTodaysFirstBar;

You can set your own conditions for a Gap Up or Down!

2 Likes

Hi Cougar,

May be I was not able make my phrase clear and had a confusion on "gap up". Here I rephrase it again.

I need to write a code which explicitly scans today's first candle which hasn't opened higher than it's yesterday's close.

That was much clear! Hope this helps:

NewDay = Day() != Ref( Day(), -1 );
/*
//Or
bi = BarIndex();
NewDay = bi == TimeFrameExpand( TimeFrameCompress( bi, inDaily, compressOpen ), inDaily, expandFirst );
*/
YstrdDayC = TimeFrameGetPrice( "C", inDaily, -1, expandFirst );
OpenOfTodaysFirstBar = ValueWhen( NewDay, O );

Condition = OpenOfTodaysFirstBar <= YstrdDayC;

Filter = Condition;
1 Like

Hi Cougar,

Many thanks for the solution. Saved a ton of time. Really appreciate.

Thanks,
Sandeep

1 Like