thanks Bebbe,
yes I have been using the fvb/lvb range a lot lately because I like the speed. In this case however, this gap fill finder seems to only give nice signals when using EOD data where there is no pre-market or afterhours data added. I made a version where instead of using a percentage I use ATR (see below). I like ATR because when switching time frames it adjusts to the bars and one does not have to figure out an alternative percentage value to use. But I noticed that in other time frames I do not see these nice signals.
So might as well just use:
for( i = BarCount - 1; i > 1; i-- )
since I also built in a "jump", so it jumps from pattern to pattern. Here is the ATR version.
// http://forum.amibroker.com/t/do-not-disqualify-levels-on-the-next-occurrence/5287
// E.M.Pottasch 3/2018
GapBullishATRPeriod = Param( "Bullish ATR Period", 100, 2, 200, 1 );
GapBullishATRMultiple = Param( "Bullish ATR Multiple", 2, 0.1, 10, 0.1 );
GapBullishMinBars = Param( "Bullish Minimum Bars Since Inception", 5, 0, 100, 1 );
GapBullishMaxBars = Param( "Bullish Maximim Bars Since Inception", 5000, 5, 10000, 1 );
fillPatternWithColor = ParamToggle( "Fill Zone with Color", "Off|On", 0 );
GfxSetZOrder( -5 );
GfxSetCoordsMode( 1 );
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
Buy = Sell = Short = Cover = 0;
BuyPrice = SellPrice = ShortPrice = CoverPrice = 0;
GapBullishSetup = Open - Ref( Close, -1 ) > Ref( ATR( GapBullishATRPeriod ), -1 ) * GapBullishATRMultiple;
GapBullishSetupJumpto = ValueWhen( GapBullishSetup, bi, 1 );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowDates );
Plot( C, "Close", colorViolet , styleCandle, Null, Null, 0, 0, 1 );
GfxSelectPen( ColorRGB( 0, 200, 200 ), 4, 0 );
GfxSelectSolidBrush( ColorRGB( 0, 21, 21 ) );
cnt = 0;
//for( i = lvb; i > fvb; i-- )
for( i = BarCount - 1; i > 1; i-- )
{
if( GapBullishSetup[i] )
{
// initial coordinates
x0top = i - 1;
x1top = Min( i + GapBullishMaxBars, BarCount - 1 );
y0top = O[i];
y1top = O[i];
x0bot = i - 1;
x1bot = Min( i + GapBullishMaxBars, BarCount - 1 );
y0bot = C[i - 1];
y1bot = C[i - 1];
gaptop = LineArray( x0top, y0top, x1top, y1top );
gapbot = LineArray( x0bot, y0bot, x1bot, y1bot );
// condition when filled
fillCondition = IIf( !IsEmpty( gapbot ), Cross( gapbot, L ) OR L < gapbot, 0 );
fillCondition = fillCondition && SumSince( i == bi, fillCondition ) == 1;
lx = LastValue( ValueWhen( fillCondition, bi ) );
lidx = lx;
if( lx == 0 ) // no cross found
{
lx = x1bot;
}
if( lx - i >= GapBullishMinBars ) // exclude where cross is too early
{
// adjusted coordinates for fill condition
x0top = i - 1;
x1top = lx;
y0top = O[i];
y1top = O[i];
x0bot = i - 1;
x1bot = lx;
y0bot = C[i - 1];
y1bot = C[i - 1];
GfxPolyline( x0bot, y0bot, x0bot + 0, y0top, x1top, y1top, x1bot, y1bot, x0bot, y0bot );
if( fillPatternWithColor )
{
GfxPolygon( x0bot, y0bot, x0bot + 0, y0top, x1top, y1top, x1bot, y1bot, x0bot, y0bot );
}
if( lidx != 0 ) // buy when gap is filled
{
Buy[lidx] = 1;
BuyPrice[lidx] = C[lidx];
}
}
}
cnt++;
i = GapBullishSetupJumpto[i - 1] + 1;
}
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, -15 );
PlotShapes( IIf( Buy, shapeSmallCircle, shapeNone ), colorWhite, 0, BuyPrice, 0 );
Filter = Buy;
AddColumn( Buy, "Buy Signal", 1.2, colorWhite, colorGreen );