Buy and Sell Signal was generated but backtest results was empty.

I use the code from empottasch to display HH and LL in charts and made some modification to eliminate the future leak from the code as following


Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );

// Fractal Pivots, E.M.Pottasch 2/2018
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

rightstrength = Param( "Right Strength", 5, 1, 50, 1 );
leftstrength = Param( "Left Strength", 5, 1, 50, 1 );
fact = Param( "Chart Time Frame Factor", 1, 1, 10, 1 );

rightStrength = rightStrength * fact;
leftStrength = leftStrength * fact;

pk = 0;
tr = 0;
pkl = 0;
trl = 0;
for( i = lvb; i > fvb; i-- )
{
	j = i  - leftStrength + 1;
	j = IIf(j<0, 0, j);
	LeftHighest = 0;
	LeftLowest =L[j];
	while(j <= i) {
		if (LeftHighest < H[j]) {
			LeftHighest = H[j];
		}
		if (LeftLowest > L[j]) {
			LeftLowest = L[j];
		}
		j = j + 1;
	}
	
	DistantUntilLastBar = (BarCount - 1) - i;
	
	SafeRightStrength = IIf(DistantUntilLastBar >= rightStrength, rightStrength, DistantUntilLastBar);
	k = i + SafeRightStrength;
	RightHighest = 0;
	RightLowest = L[k];
	while(k > i) {
		if (RightHighest < H[k]) {
			RightHighest = H[k];
		}
		if (RightLowest > L[k]) {
			RightLowest = L[k];
		}
		k = k - 1;
	}
	pk[i] = H[i] == LeftHighest AND RightHighest < H[i];
	tr[i] = L[i] == LeftLowest AND RightLowest > L[i];
	pkl[i] = H[i] == LeftHighest;
	trl[i] = L[i] == LeftLowest;
}

for( i = 0; i < 3; i++ )
{
    VarSet( "px" + i, ValueWhen( pk, bi, i ) );
    VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
    VarSet( "ph" + i, ValueWhen( pk, H, i ) );
    VarSet( "tl" + i, ValueWhen( tr, L, i ) );
}

ll = tr AND tl1 < tl2;
hl = tr AND tl1 > tl2;
hh = pk AND ph1 > ph2;
lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

Buy = BarsSince(hh) == 1;
Sell = BarsSince(Buy) >= 10;
Sell = ExRem(Sell, Buy);

PlotShapes(Buy * shapeUpArrow, colorGreen, 0, L, -25);
PlotShapes(Sell * shapeDownArrow, colorRed, 0, H, -25);

doubleTopThreshold = 0.75 * Ref( ATR( 20 ), -1 );
doubleTop = pk && abs( ph1 - ph2 ) < doubleTopThreshold;

doubleBottomThreshold = 0.75 * Ref( ATR( 20 ), -1 );
doubleBottom = tr && abs( tl1 - tl2 ) < doubleBottomThreshold;

for( i = lvb; i > fvb; i-- )
{
    sz = 8;

    // troughs
    if( ll[i] )
    {
        str = "LL";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    if( hl[i] )
    {
        str = "HL";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    if( db[i] )
    {
        str = "DB";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 0, 250, 0 ), colorDefault, -30 );
    }

    //peaks
    if( hh[i] )
    {
        str = "HH";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( lh[i] )
    {
        str = "LH";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( dt[i] )
    {
        str = "DT";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( doubleTop[i] )
    {
        str = "Double Top";
        PlotTextSetFont( str, "Arial Black", sz, i, H[i], ColorRGB( 250, 125, 0 ), colorDefault, 40 );
    }
    
     if( doubleBottom[i] )
    {
        str = "Double Bottom";
        PlotTextSetFont( str, "Arial Black", sz, i, L[i], ColorRGB( 250, 125, 0 ), colorDefault, -40 );
    }
    
}

writeif( highest( doubleTop ) == 1, "\nAmiBroker has detected some possible Double Top patterns for " + name() + "\n\nLook for TAG on the price chart.", "\n\nThere are no double top patterns for " + name() );
writeif( highest( doubleBottom ) == 1, "\n\nAmiBroker has detected some possible Double Bottom patterns for " + name() + "\n\nLook for TAG on the price chart.", "\nThere are no double top patterns for " + name() );

When I backtest above code, it show zero trade list result. I change the Buy signal code from

Buy = BarsSince(hh) == 1;

to

Buy = C > Ref(HHV(H, 60), -1);

My backtest result list show trade list as normal.

The point is when I use 'old' buy signal to plot green up arrow shape, it show the shape in chart as expected. That's mean Buy array has correct values.

Question is: why the code that can generating correct Buy signal got zero result backtest result?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.