thanks Jorgen. Your method of trading is also valuable information because in the end as a trader you need to make money. So I am going to look into your method.
Looking at the code using tick data I made a small change (added to the change you already made), but probably you already done that.
At the bottom I also add ZigZag code using fractal pivots.
The slightly adjusted ZigZag code using absolute price change
PriceTicks = Param( "Price Change In Ticks", 4, 1, 40, 1 );
labelsswitch = ParamToggle( "Show Labels", "Off|On", 1 );
priceswitch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );
upColor = ColorRGB( 0, 255, 0 );
dnColor = ColorRGB( 255, 0, 0 );
pk = tr = 0;
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
fluc = TickSize * PriceTicks;
if( priceswitch )
{
prch = H;
prcl = L;
}
else
{
prch = C;
prcl = C;
}
// initial condition trend is up
trend = 1;
topprc = prch[0];
topidx = 0;
breakl = topprc - fluc;
for( i = 1; i < BarCount; i++ )
{
if( trend > 0 )
{
if( prcl[i] <= breakl AND prch[i] < topprc )
{
pk[topidx] = 1;
botprc = prcl[i];
botidx = i;
breakh = botprc + fluc;
trend = -1;
}
else
if( prch[i] >= topprc )
{
topprc = prch[i];
topidx = i;
breakl = prch[i] - fluc;
}
}
else
if( trend < 0 )
{
if( prch[i] >= breakh AND prcl[i] > botprc )
{
tr[botidx] = 1;
topprc = prch[i];
topidx = i;
breakl = topprc - fluc;
trend = 1;
}
else
if( prcl[i] <= botprc )
{
botprc = prcl[i];
botidx = i;
breakh = prcl[i] + fluc;
}
}
}
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;
// create ZIGZAG array line
zigup = Flip( tr, pk );
zigupLow = ValueWhen( tr, L, 1 );
zigupHigh = ValueWhen( pk, H, 0 );
zigupLowIndex = ValueWhen( tr, bi, 1 );
zigupHighIndex = ValueWhen( pk, bi, 0 );
slopeup = IIf( zigup, ( zigupHigh - zigupLow ) / ( zigupHighIndex - zigupLowIndex ) , Null );
zigupLine = IIf( zigup, zigupLow + slopeup * BarsSince( tr ), Null );
zigdn = Flip( pk, tr );
zigdnLow = ValueWhen( tr, L, 0 );
zigdnHigh = ValueWhen( pk, H, 1 );
zigdnLowIndex = ValueWhen( tr, bi, 0 );
zigdnHighIndex = ValueWhen( pk, bi, 1 );
slopedn = IIf( zigdn, ( zigdnLow - zigdnHigh ) / ( zigdnLowIndex - zigdnHighIndex ) , Null );
zigdnLine = IIf( zigdn, zigdnHigh + slopedn * BarsSince( pk ), Null );
ZigZag = IIf( zigup, zigupLine, IIf( zigdn, zigdnLine, Null ) );
ZigZag = IIf( bi > Max( LastValue( ValueWhen( tr, bi ) ), LastValue( ValueWhen( pk, bi ) ) ), Null, ZigZag );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 0 );
Plot( ZigZag, "", colorwhite, styleLine, Null, Null, 0, 0, 2 );
PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 255, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );
ft = "Arial Black";
clr = colorDefault;
sz = 7;
GfxSetZOrder( 0 );
GfxSetCoordsMode( 1 );
if( labelsswitch )
{
for( i = fvb; i <= lvb; i++ )
{
if( ll[i] )
{
str = "LL\n" + L[i];
PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
}
if( hl[i] )
{
str = "HL\n" + L[i];
PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
}
if( db[i] )
{
str = "DB\n" + L[i];
PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
}
if( hh[i] )
{
str = "HH\n" + H[i];
PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 35 );
}
if( lh[i] )
{
str = "LH\n" + H[i];
PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 35 );
}
if( dt[i] )
{
str = "DT\n" + H[i];
PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 35 );
}
}
}
ZigZag code using Fractal Pivots
rightstrength = Param( "Right Strength", 5, 2, 50, 1 );
leftstrength = Param( "Left Strength", 10, 2, 50, 1 );
labelsswitch = ParamToggle( "Show Labels", "Off|On", 1 );
upColor = ColorRGB( 0, 255, 0 );
dnColor = ColorRGB( 255, 0, 0 );
pk = tr = 0;
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
pk = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
pk = pk AND LastValue( bi ) - ValueWhen( pk, bi ) > rightstrength;
tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
tr = tr AND LastValue( bi ) - ValueWhen( tr, bi ) > rightstrength;
// alternate pivots
pkHigh = 0;
pkHighIndex = 0;
trLow = 1e10;
trLowIndex = 0;
for( i = 0; i < BarCount; i++ )
{
if( pk[i] AND tr[i] )
{
pk[i] = tr[i] = 0;
}
if( pk[i] AND H[i] >= pkHigh )
{
pk[pkHighIndex] = 0;
trLow = 1e10;
trLowIndex = 0;
pkHigh = H[i];
pkHighIndex = i;
}
else
if( pk[i] AND H[i] < pkHigh )
{
pk[i] = 0;
trLow = 1e10;
trLowIndex = 0;
}
if( tr[i] AND L[i] <= trLow )
{
tr[trLowIndex] = 0;
pkHigh = 0;
pkHighIndex = 0;
trLow = L[i];
trLowIndex = i;
}
else
if( tr[i] AND L[i] > trLow )
{
tr[i] = 0;
pkHigh = 0;
pkHighIndex = 0;
}
}
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;
// create ZIGZAG array line
zigup = Flip( tr, pk );
zigupLow = ValueWhen( tr, L, 1 );
zigupHigh = ValueWhen( pk, H, 0 );
zigupLowIndex = ValueWhen( tr, bi, 1 );
zigupHighIndex = ValueWhen( pk, bi, 0 );
slopeup = IIf( zigup, ( zigupHigh - zigupLow ) / ( zigupHighIndex - zigupLowIndex ) , Null );
zigupLine = IIf( zigup, zigupLow + slopeup * BarsSince( tr ), Null );
zigdn = Flip( pk, tr );
zigdnLow = ValueWhen( tr, L, 0 );
zigdnHigh = ValueWhen( pk, H, 1 );
zigdnLowIndex = ValueWhen( tr, bi, 0 );
zigdnHighIndex = ValueWhen( pk, bi, 1 );
slopedn = IIf( zigdn, ( zigdnLow - zigdnHigh ) / ( zigdnLowIndex - zigdnHighIndex ) , Null );
zigdnLine = IIf( zigdn, zigdnHigh + slopedn * BarsSince( pk ), Null );
ZigZag = IIf( zigup, zigupLine, IIf( zigdn, zigdnLine, Null ) );
ZigZag = IIf( bi > Max( LastValue( ValueWhen( tr, bi ) ), LastValue( ValueWhen( pk, bi ) ) ), Null, ZigZag );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 0 );
Plot( ZigZag, "", colorwhite, styleLine, Null, Null, 0, 0, 2 );
PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 255, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );
ft = "Arial Black";
clr = colorDefault;
sz = 7;
GfxSetZOrder( 0 );
GfxSetCoordsMode( 1 );
if( labelsswitch )
{
for( i = fvb; i <= lvb; i++ )
{
if( ll[i] )
{
str = "LL\n" + L[i];
PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
}
if( hl[i] )
{
str = "HL\n" + L[i];
PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
}
if( db[i] )
{
str = "DB\n" + L[i];
PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -30 );
}
if( hh[i] )
{
str = "HH\n" + H[i];
PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 35 );
}
if( lh[i] )
{
str = "LH\n" + H[i];
PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 35 );
}
if( dt[i] )
{
str = "DT\n" + H[i];
PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 35 );
}
}
}