Please Help me to Mofify a Loop

The following loop was written by Mr. @empottasch He used this loop for ATR-based ZigZag. One of the best aspects of ATR-based ZigZag is that its peaks and troughs remain the same even when switching to a higher timeframe, as long as the bars containing those peaks or troughs are not merged into the higher timeframe's bars.

However, this loop does not allow peaks and troughs to occur on a single bar, causing it to either skip one side of such bars or skip the bar entirely. For my trading strategy, these bars are important. Due to this limitation, I cannot use the ATR ZigZag. Is there a way to allow peaks and troughs on a single bar? If so, I can handle such bars using Gfx lines. I have already tried many times but have not succeeded. Please help.

The loop is from a webpage of this forum: Asymetric Zig Zag - #5 by empottasch

// build variable percentage array
//variablePercentage = StDev( 100 * ( H - L ) / ( ( H + L ) / 2 ), period );
variablePercentage = ATR( period ) / MA( C, period ) * 100;
uppercentage = uppercentageFactor * Ref( variablePercentage, -1 );
downpercentage = downpercentageFactor * Ref( variablePercentage, -1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
pk = tr = Buy = Sell = BuyPrice = SellPrice = 0;
ZigZag = line1 = line2 = Null;
trailarrayup = Null;
trailarraydn = Null;
mode = "";
SetBarsRequired( ( lvb - fvb ) * 2 );

if( priceswitch )
{
    prch = H;
    prcl = L;
    mode = "High/Low price";
}
else
{
    prch = C;
    prcl = C;
    mode = "Close price";
}

// if ticksize is not set in code or information window 0.01 is used
if( TickSize == 0 )
{
    TickSize = 0.01;
}

function percfluc( prc, perc )
{
    retprice = round( ( prc * perc / 100 ) / TickSize ) * TickSize;
    return retprice;
}

function calculatePivots()
{
    // initial condition trend is up (but -1 works also)
    trend = 1;
    topprc = prch[0];
    topidx = 0;
    botprc = prcl[0];
    botidx = 0;
    trailarrayup[period] = topprc - percfluc( topprc, downpercentage[period] );
    trailarraydn[period] = botprc + percfluc( botprc, uppercentage[period] );

    for( i = period + 1; i < BarCount; i++ )
    {
        if( trend > 0 )
        {
            // trend turning down, avoid same bar as the peak
            if( prcl[i] <= trailarrayup[i - 1] AND prch[i] < topprc )
            {
                pk[topidx] = 1;
                botprc = prcl[i];
                botidx = i;
                trend = -1;
                Sell[i] = 1;
                trailarraydn[i] = botprc + percfluc( botprc, uppercentage[i] );
                trailarrayup[i] = trailarrayup[i - 1];

                if( priceswitch )
                    SellPrice[i] = Min( O[i], trailarrayup[i] );
                else
                    SellPrice[i] = C[i];
            }
            else

                // still in uptrend and new top reached
                if( prch[i] >= topprc )
                {
                    topprc = prch[i];
                    topidx = i;
                    trailarrayup[i] = Max( trailarrayup[i - 1], prch[i] - percfluc( topprc, downpercentage[i] ) );
                }
                // continuation inside uptrend
                else
                {
                    trailarrayup[i] = Max( trailarrayup[i - 1], prch[i] - percfluc( prch[i], downpercentage[i] ) );
                }
        }
        else
            if( trend < 0 )
            {
                // trend turning up, avoid same bar as the trough
                if( prch[i] >= trailarraydn[i - 1] AND prcl[i] > botprc )
                {
                    tr[botidx] = 1;
                    topprc = prch[i];
                    topidx = i;
                    trend = 1;
                    Buy[i] = 1;
                    trailarrayup[i] = topprc - percfluc( topprc, downpercentage[i] );
                    trailarraydn[i] = trailarraydn[i - 1];

                    if( priceswitch )
                        BuyPrice[i] = Max( O[i], trailarraydn[i] );
                    else
                        BuyPrice[i] = C[i];
                }
                else

                    // still in downtrend and new trough reached
                    if( prcl[i] <= botprc )
                    {
                        botprc = prcl[i];
                        botidx = i;
                        trailarraydn[i] = Min( trailarraydn[i - 1], prcl[i] + percfluc( botprc, uppercentage[i] ) );
                    }
                    // continuation inside downtrend
                    else
                    {
                        trailarraydn[i] = Min( trailarraydn[i - 1], prcl[i] + percfluc( prcl[i], uppercentage[i] ) );
                    }
            }
    }
}

generally you do not know what happens inside a bar. Can you give me 1 example in a chart where this would be necessary (just 1 example not 10 :grinning: )? If you need all this detail why not go trade tick charts?

Thanks Mr. @empottasch for paying attention and responding.

Sorry for late response...there was something wrong with my WiFi router.

Kindly check the snapshot. I have provided the example in the snapshot.
When we let the peak-&-trough @ a single bar, then regural zigzag's lines do not connect to such a bar and zigzag appears broken. So I understand that when a using a regular zigzag it is necessary to avoid such bars. To handle such a situation I use Gfx lines to connect or fill the discontinuity of the zigzag, and let the regular zigzag to generate the rest of lines. Below is the code I have coded for Gfx lines.

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
nLast_Pivot_Peak = nPeakBar_01 > nTroughBar_01;
nLast_Pivot_Trough = nTroughBar_01 > nPeakBar_01;

nRecent_Pivot_Peak = nPeakBar_02 > nTroughBar_02 AND nTroughBar_01 > nPeakBar_02;
nRecent_Pivot_Trough = nTroughBar_02 > nPeakBar_02 AND nPeakBar_01 > nTroughBar_02;

nPrevious_Pivot_Peak = nPeakBar_02 < nTroughBar_02 AND nTroughBar_02 < nPeakBar_01 AND nPeakBar_01 < nTroughBar_01;
nPrevious_Pivot_Trough = nTroughBar_02 < nPeakBar_02 AND nPeakBar_02 < nTroughBar_01 AND nTroughBar_01 < nPeakBar_01;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

nPeakTrough_SameBar_01 = nPeakBar_01 == nTroughBar_01;
nPeakTrough_SameBar_02 = nPeakBar_02 == nTroughBar_02;
nPeakTrough_SameBar_03 = nPeakBar_02 == nTroughBar_01 AND nPeakBar_03 > nTroughBar_02;
nPeakTrough_SameBar_04 = nTroughBar_02 == nPeakBar_01 AND nTroughBar_03 > nPeakBar_02;


function Draw_UpLine( nGfxCoordsMode, nLine_Zorder, nUpLine_Color, nLine_Width, nLine_Style, nTroughBar_01, nTroughBarLow_01, nPeakBar_01, nPeakBarHigh_01 )
{
    GfxSetCoordsMode( nGfxCoordsMode );
    GfxSetZOrder( nLine_Zorder );

    GfxSelectPen( nUpLine_Color, nLine_Width, nLine_Style );
    GfxMoveTo( nTroughBar_01, nTroughBarLow_01 );
    GfxLineTo( nPeakBar_01, nPeakBarHigh_01 );
}

function Draw_DownLine( nGfxCoordsMode, nDownLine_Color, nLine_Zorder, nLine_Width, nLine_Style, nPeakBar_01, nPeakBarHigh_01, nTroughBar_01, nTroughBarLow_01 )
{
    GfxSetCoordsMode( nGfxCoordsMode );
    GfxSetZOrder( nLine_Zorder );

    GfxSelectPen( nDownLine_Color, nLine_Width, nLine_Style );
    GfxMoveTo( nPeakBar_01, nPeakBarHigh_01 );
    GfxLineTo( nTroughBar_01, nTroughBarLow_01 );
}

function Draw_UpLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02, nTroughBarLow_02, nPeakBar_01, nPeakBarHigh_01 )
{
    GfxSetCoordsMode( nGfxCoordsMode );
    GfxSetZOrder( nLine_Zorder );

    GfxSelectPen( nLine_Color, nLine_Width, nLine_Style );
    GfxMoveTo( nTroughBar_02, nTroughBarLow_02 );
    GfxLineTo( nPeakBar_01, nPeakBarHigh_01 );
}

function Draw_DownLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nPeakBar_02, nPeakBarHigh_02, nTroughBar_01, nTroughBarLow_01 )
{
    GfxSetCoordsMode( nGfxCoordsMode );
    GfxSetZOrder( nLine_Zorder );

    GfxSelectPen( nLine_Color, nLine_Width, nLine_Style );
    GfxMoveTo( nPeakBar_02, nPeakBarHigh_02 );
    GfxLineTo( nTroughBar_01, nTroughBarLow_01 );
}

function Draw_Line_PT_SameBar_to_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02, nTroughBarLow_02, nPeakBar_01, nPeakBarHigh_01 )
{
    GfxSetCoordsMode( nGfxCoordsMode );
    GfxSetZOrder( nLine_Zorder );

    GfxSelectPen( nLine_Color, nLine_Width, nLine_Style );
    GfxMoveTo( nTroughBar_02, nTroughBarLow_02 );
    GfxLineTo( nPeakBar_01, nPeakBarHigh_01 );
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

if( nZigZag_DisplaySwitch == 1 )
{
    nGfxCoordsMode = 1;
    nLine_Zorder = nZZ_Line_Zorder;

    nLine_Color = nZZ_UpLine_Color;
    nUpLine_Color = nZZ_UpLine_Color;
    nDownLine_Color = nZZ_DownLine_Color;
    nLine_Width = nZZ_Line_Width;
    nLine_Style = nGFX_Line_Style;

    for( i = 0; i < BarCount - 1; i++ )
    {
        if( nPeakTrough_SameBar_01[i] )
        {
            Draw_UpLine( nGfxCoordsMode, nLine_Zorder, nUpLine_Color, nLine_Width, nLine_Style, nTroughBar_01[i], nTroughBarLow_01[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
        }

        if( nPeakTrough_SameBar_03[i] )
        {
            Draw_UpLine( nGfxCoordsMode, nLine_Zorder, nUpLine_Color, nLine_Width, nLine_Style, nTroughBar_01[i], nTroughBarLow_01[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
        }

        if( nPeakTrough_SameBar_04[i] )
        {
            Draw_DownLine( nGfxCoordsMode, nDownLine_Color, nLine_Zorder, nLine_Width, nLine_Style, nPeakBar_01[i], nPeakBarHigh_01[i], nTroughBar_01[i], nTroughBarLow_01[i] );
        }

        if( nPeakTrough_SameBar_01[i] AND nRecent_Pivot_Trough[i] )
        {
            Draw_UpLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02[i], nTroughBarLow_02[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
        }

        if( nPeakTrough_SameBar_01[i] AND nRecent_Pivot_Peak[i] )
        {
            Draw_DownLine_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nPeakBar_02[i], nPeakBarHigh_02[i], nTroughBar_01[i], nTroughBarLow_01[i] );
        }

        if( nPeakTrough_SameBar_01[i] AND nPeakTrough_SameBar_02[i] )
        {
            Draw_Line_PT_SameBar_to_PT_SameBar( nGfxCoordsMode, nLine_Zorder, nLine_Color, nLine_Width, nLine_Style, nTroughBar_02[i], nTroughBarLow_02[i], nPeakBar_01[i], nPeakBarHigh_01[i] );
        }
    }
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

nZigZag = Calculate_ZigZag( nPeak, nTrough );
Calculate_LastSegment( nPeak, nTrough, nZigZag );

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

if( nZigZag_DisplaySwitch == 1 )
{
    nZZ_Line_Color = IIf( nZigZag, nZZ_UpLine_Color, IIf( nZigZag, nZZ_DownLine_Color, Null ) );
    Plot( nZigZag, "", nZZ_Line_Color, nZZ_Line_Style, Null, Null, 0, nZZ_Line_Zorder, nZZ_Line_Width );
}

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I have coded an AFL to visually check on outbars on the chart. Perhaps you would also like to check on outbars. It shows six types of OutBars.

_SECTION_BEGIN( "Outside-Bar Display" );

OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When OutBar' ?", "No|Yes", 0 );
OutBar_Shape_Color = ParamColor( "OutBar Shape-Color", colorWhite );
xAbsolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xAbsolute-OutBar' ?", "No|Yes", 0 );
xAbsolute_OutBar_Shape_Color = ParamColor( "xAbsolute-OutBar Shape-Color", colorGold );
xPeak_at_Absolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xPeak-Bar is also xAbsolute-OutBar' ?", "No|Yes", 0 );
xPeak_at_Absolute_OutBar_Shape_Color = ParamColor( "'xPeakBar-Absolute-OutBar' Shape-Color", colorBrightGreen );
xTrough_at_Absolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xTrough-Bar is also xAbsolute-OutBar' ?", "No|Yes", 0 );
xTrough_at_Absolute_OutBar_Shape_Color = ParamColor( "'xTroughBar-Absolute-OutBar' Shape-Color", colorOrange );
xPeakTrough_at_SameBar_Absolute_OutBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xPeakTrough-@-SameBar is also xAbsolute-OutBar' ?", "No|Yes", 0 );
xPeakTrough_at_SameBar_Absolute_OutBar_Shape_Color = ParamColor( "'xPeakTrough-SameBar is Absolute-OutBar' Shape-Color", colorBlue );
xPeakTrough_at_SameBar_DisplaySwitch = ParamToggle( "Display Shapes 'When xPeakTrough-@-SameBar' ?", "No|Yes", 0 );
xPeakTrough_at_SameBar_OutBar_Shape_Color = ParamColor( "'xPeakTrough_SameBar' Shape-Color", colorAqua );

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

PriceArrayMode_Switch = ParamToggle( "Use Close or High and Low price", "Use Close|Use High and Low", 1 );

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

if( PriceArrayMode_Switch == 1 )
{
    PaH = High;
    PaL = Low;
}
else
    if( PriceArrayMode_Switch == 0 )
    {
        PaH = C;
        PaL = C;
    }
    
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

pk = nPeak;
tr = nTrough;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

OutBar = PaH > Ref( PaH, -1 ) AND PaL < Ref( PaL, -1 );
OutBar_High = ValueWhen( OutBar, PaH );
OutBar_Low = ValueWhen( OutBar, PaL );

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xAbsolute_OutBar = OutBar AND( ValueWhen( nPeak, PaH, 1 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 1 ) > ValueWhen( OutBar, PaL ) );


xPeak_at_Absolute_OutBar = OutBar AND( ValueWhen( nPeak, PaH, 1 ) == ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 1 ) != ValueWhen( OutBar, PaL ) ) AND
                           ( ValueWhen( nPeak, PaH, 2 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 1 ) > ValueWhen( OutBar, PaL ) );

xTrough_at_Absolute_OutBar = OutBar AND( ValueWhen( nPeak, PaH, 1 ) != ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 1 ) == ValueWhen( OutBar, PaL ) ) AND
                             ( ValueWhen( nPeak, PaH, 1 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 2 ) > ValueWhen( OutBar, PaL ) );

xPT_at_SameBar_Absolute_OutBar = OutBar AND( ValueWhen( nPeak, PaH, 1 ) == ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 1 ) == ValueWhen( OutBar, PaL ) ) AND
                              ( ValueWhen( nPeak, PaH, 2 ) < ValueWhen( OutBar, PaH ) AND ValueWhen( nTrough, PaL, 2 ) > ValueWhen( OutBar, PaL ) );

xPeakTrough_at_SameBar_OutBar = nPeak AND nTrough;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

if( OutBar_DisplaySwitch == 1 )
{
    PlotShapes( shapeSquare * OutBar, OutBar_Shape_Color, 0, High, 70 );
    PlotShapes( shapeSquare * OutBar, OutBar_Shape_Color, 0, Low, -70 );
}

if( xAbsolute_OutBar_DisplaySwitch == 1 )
{
    PlotShapes( shapeSquare * xAbsolute_OutBar, xAbsolute_OutBar_Shape_Color, 0, High, 60 );
    PlotShapes( shapeSquare * xAbsolute_OutBar, xAbsolute_OutBar_Shape_Color, 0, Low, -60 );
}

if( xPeakTrough_at_SameBar_Absolute_OutBar_DisplaySwitch == 1 )
{
    PlotShapes( shapeSquare * xPT_at_SameBar_Absolute_OutBar, xPeakTrough_SameBar_Absolute_OutBar_Shape_Color, 0, High, 50 );
    PlotShapes( shapeSquare * xPT_at_SameBar_Absolute_OutBar, xPeakTrough_SameBar_Absolute_OutBar_Shape_Color, 0, Low, -50 );
}

if( xPeak_at_Absolute_OutBar_DisplaySwitch == 1 )
{
    PlotShapes( shapeSquare * xPeakBar_at_Absolute_OutBar, xPeakBar_Absolute_OutBar_Shape_Color, 0, High, 40 );
    PlotShapes( shapeSquare * xPeakBar_at_Absolute_OutBar, xPeakBar_Absolute_OutBar_Shape_Color, 0, Low, -40 );
}

if( xTrough_at_Absolute_OutBar_DisplaySwitch == 1 )
{
    PlotShapes( shapeSquare * xTroughBar_at_Absolute_OutBar, xTroughBar_Absolute_OutBar_Shape_Color, 0, High, 30 );
    PlotShapes( shapeSquare * xTroughBar_at_Absolute_OutBar, xTroughBar_Absolute_OutBar_Shape_Color, 0, Low, -30 );
}

if( xPeakTrough_at_SameBar_DisplaySwitch == 1 )
{
    PlotShapes( shapeSquare * xPeakTrough_at_SameBar_OutBar, xPeakTrough_SameBar_OutBar_Shape_Color, 0, High, 20 );
    PlotShapes( shapeSquare * xPeakTrough_at_SameBar_OutBar, xPeakTrough_SameBar_OutBar_Shape_Color, 0, Low, -20 );
}

_SECTION_END();

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

"...If you need all this detail why not go trade tick charts?..."

Well, I always use an overlayed zigzag ( Prime or Secondary zigzag ) for trading and dectecting Harmonic patterns or cycles etc..
This overlayed zigzag is directly based on the pivots of Base-Zigzag. If something is not good with the Base-zigzag then obviously this will also effect the overlayed zigzag. For example, if a Gartly pattern is detected and in between the range of this pattern there is an outbar which should have peak-trough on the same bar but ignored or disabled by the code, then actually Gartly ratios will be based on wrong pivots and thereby I will be viewing and trading a Gartly pattern which is actually not a Gartly at all. Other than Harmonic patterns there are vary many scenarios where it would be much better if such bars are not avoided. Thanks.

Secondly, for tick-data very high speed internet connection is required. And I had to usually travel to remote tribal area in order to held free medical camps...and in such areas high speed internet connection is not available. Especially in hill areas.

my code is based on either the close price of a bar or the H/L of a bar. In your example chart I can not even imagine how such a curve would look like. In my opinion it is just a waste of time. In that case just trade tick charts then you have 1 price per bar. Then you will get every wiggle.

I attach my latest code on this ATR code. More interesting is it for you to figure out good point of entry and exit.

For instance the code that I add is highly profitable if you enter at the price shown in the chart. However, in real trading this is not possible because the signal is only known at the close (in default mode, using the close price). But if you manage to enter and exit (on average) at the price shown in the chart then it is very profitable. Sometimes you can get even a better entry/exit price but not always. So if you want to trade this then you need to find good entry and exit points within the ATR trend

per = Param( "ATR Period", 10, 1, 500, 1 );
mult = Param( "ATR Multiple", 3, 0.5, 20, 0.1 );
priceswitch = ParamToggle( "Select", "Close|High or Low", 0 );
labelsswitch = ParamToggle( "Show Labels", "Off|On", 1 );
showseparator = ParamToggle( "Show Separator", "No|Yes", 0 );
showmacd = ParamToggle( "Show MACD", "No|Yes", 0 );
plottrailswitch = ParamToggle( "Show Trail Line", "No|Yes", 1 );
ft = ParamList( "Font Type", "Tahoma Bold|Arial Black|Verdana Bold|Courier New Bold|Comic Sans MS Bold|Arial Bold|Candara Bold|Calibri Bold|Constantia Bold|Georgia Bold|Gadugi Bold|Segoe UI Bold", 1 );
sz = Param( "Font Size", 10, 8, 50, 1 );

bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );
pk = tr = Buy = Sell = BuyPrice = SellPrice = pkn = trn = 0;
trailarrayup = trailarraydn = Null;
colorlightblue1 = ColorRGB( 128, 213, 255 );
colorlightorange1 = ColorRGB( 255, 213, 128 );

if( priceswitch )
{
    prch = H;
    prcl = L;
}
else
{
    prch = C;
    prcl = C;
}

// if ticksize is not set in code or information window use 0.01
if( TickSize == 0 )
{
    TickSize = 0.01;
}

// calculate format for display purposes
fmt = "" + TickSize;
fmt = StrReplace( fmt, ".", "," );
fmt = StrExtract( fmt, 1 );
fmt = "1" + "." + StrLen( fmt );
fmt = StrToNum( fmt );

slip = 0;

// ATR
sup = round( ( prch - mult * ATR( per ) ) / TickSize ) * TickSize;
res = round( ( prcl + mult * ATR( per ) ) / TickSize ) * TickSize;

trend = 1; // start trend at 1 or -1 doesnt matter
topprc = 0;
topidx = 0;
botprc = 0;
botidx = 0;

for( i = per + 1; i < BarCount; i++ )
{
    if( trend > 0 )
    {
        // trend turning down, avoid same bar as the peak
        if( prcl[i] < trailarrayup[i - 1] )//AND prch[i] < topprc )
        {
            pk[topidx] = 1;
            botprc = prcl[i];
            botidx = i;
            trend = -1;
            Sell[i] = 1;
            SellPrice[i] = C[i] - slip;
            trailarraydn[i] = res[i];
            trailarrayup[i] = trailarrayup[i - 1];
        }
        else

            // still in uptrend but new top reached
            if( prch[i] >= topprc )
            {
                topprc = prch[i];
                topidx = i;
                trailarrayup[i] = Max( trailarrayup[i - 1], sup[i] );
                pkn[i] = 1;
            }
            // continuation inside uptrend
            else
            {
                trailarrayup[i] = Max( trailarrayup[i - 1], sup[i] );
            }
    }
    else
        if( trend < 0 )
        {
            // trend turning up, avoid same bar as the trough
            if( prch[i] > trailarraydn[i - 1] )// AND prcl[i] > botprc )
            {
                tr[botidx] = 1;
                topprc = prch[i];
                topidx = i;
                trend = 1;
                Buy[i] = 1;
                BuyPrice[i] = C[i] + slip;
                trailarrayup[i] = sup[i];
                trailarraydn[i] = trailarraydn[i - 1];
            }
            else

                // still in downtrend but new trough reached
                if( prcl[i] <= botprc )
                {
                    botprc = prcl[i];
                    botidx = i;
                    trailarraydn[i] = Min( trailarraydn[i - 1], res[i] );
                    trn[i] = 1;
                }
                // continuation inside downtrend
                else
                {
                    trailarraydn[i] = Min( trailarraydn[i - 1], res[i] );
                }
        }
}

line1 = Null;
lastidxpk = LastValue( ValueWhen( pk, bi ) );
lastidxtr = LastValue( ValueWhen( tr, bi ) );
lastvalpk = LastValue( ValueWhen( pk, prch ) );
lastvaltr = LastValue( ValueWhen( tr, prcl ) );
lastidxbuy = LastValue( ValueWhen( Buy, bi ) );
lastidxsell = LastValue( ValueWhen( Sell, bi ) );
valpk = LastValue( HighestSince( Ref( tr, -1 ), prch , 1 ) );
idxpk = LastValue( ValueWhen( prch == valpk, bi ) );
valtr = LastValue( LowestSince( Ref( pk, -1 ), prcl, 1 ) );
idxtr = LastValue( ValueWhen( prcl == valtr, bi ) );

if( lastidxsell > lastidxbuy AND lastidxsell > lastidxpk AND lastidxpk > lastidxtr )
{
    x0 = lastidxpk;
    y0 = lastvalpk;
    x1 = idxtr;
    y1 = valtr;
    line1 = linedn = LineArray( x0, y0, x1, y1 );
    tr[idxtr] = 1;
    valpk = LastValue( HighestSince( Ref( tr, -1 ), prch, 1 ) );
    idxpk = LastValue( ValueWhen( prch == valpk, bi ) );
}

if( lastidxsell < lastidxbuy AND lastidxbuy > lastidxtr AND lastidxpk < lastidxtr )
{
    x0 = lastidxtr;
    y0 = lastvaltr;
    x1 = idxpk;
    y1 = valpk;
    line1 = lineup = LineArray( x0, y0, x1, y1 );
    pk[idxpk] = 1;
    valtr = LastValue( LowestSince( Ref( pk, -1 ), prcl, 1 ) );
    idxtr = LastValue( ValueWhen( prcl == valtr, bi ) );
}

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, prcl, 1 );
zigupHigh = ValueWhen( pk, prch, 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, prcl, 0 );
zigdnHigh = ValueWhen( pk, prch, 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 );
ZigZag = IIf( !IsEmpty( line1 ), line1, ZigZag );

uptrend1 = Flip( Buy, Sell );
dntrend1 = Flip( Sell, Buy );
trn = LowestSince( pk, prcl ) == prcl && dntrend1;
pkn = HighestSince( tr, prch ) == prch && uptrend1;

SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );
//Plot( C, "C", IIf( Outside(), colorAqua, IIf( C > O, colorBlue, IIf( C < O, colorRed, colorLightGrey ) ) ), styleCandle, Null, Null, 0, 0, 1 );
Plot( C, "C", colorWhite, styleCandle, Null, Null, 0, 0, 1 );
//Plot( IIf( !IsEmpty( line1 ), line1, Null ), "", ColorRGB( 255, 255, 0 ), styleLine | styleNoRescale | styleNoLabel, Null, Null, 0, -1, 4 );
Plot( ZigZag, "", IIf( uptrend1, colorLightBlue1, colorLightOrange1 ), styleLine | styleNoRescale | styleNoLabel, Null, Null, 0, 0, 1 );

PlotShapes( IIf( tr, shapeSmallCircle, shapeNone ), colorGreen, 0, L, -10 );
PlotShapes( IIf( pk, shapeSmallCircle, shapeNone ), colorRed, 0, H, 10 );
PlotShapes( IIf( trn, shapeHollowSmallCircle, shapeNone ), ColorRGB( 0, 80, 0 ), 0, L, -25 );
PlotShapes( IIf( pkn, shapeHollowSmallCircle, shapeNone ), ColorRGB( 135, 0, 0 ), 0, H, 25 );

BuyPrice = Max( O, trailarraydn );
SellPrice = Min( O, trailarrayup );
ShortPrice = Min( O, trailarrayup );
CoverPrice = Max( O, trailarraydn );
//BuyPrice = SellPrice = ShortPrice = CoverPrice = C;

// crossing trail indicator
crossup = Cross( C, trailarraydn );
crossdn = Cross( trailarrayup, C );
iBuy = BarsSince( crossdn ) >= 1 AND BarsSince( crossdn ) < BarsSince( crossup ) AND H >= Ref( trailarraydn, -1 ) OR crossup;
iBuyPrice = Max( O, Ref( trailarraydn, -1 ) );
iShort = BarsSince( crossup ) >= 1 AND BarsSince( crossdn ) > BarsSince( crossup ) AND L <= Ref( trailarrayup, -1 ) OR crossdn;
iShortPrice = Min( O, Ref( trailarrayup, -1 ) );
iSell = iShort;
iSellPrice = iShortPrice;
iCover = iBuy;
iCoverPrice = iBuyPrice;
PlotShapes( IIf( iBuy, shapeSmallCircle, shapeNone ) , colorAqua, 0, trailarraydn, 0 );
PlotShapes( IIf( iSell, shapeSmallCircle, shapeNone ), colorGold, 0, trailarrayup, 0 );
PlotShapes( IIf( iCover, shapeSmallCircle, shapeNone ) , colorAqua, 0, trailarraydn, 0 );
PlotShapes( IIf( iShort, shapeSmallCircle, shapeNone ), colorGold, 0, trailarrayup, 0 );

if( plottrailswitch )
{
    Plot( trailarrayup, "trail up", colorLightBlue1, styleLine | styleStaircase | styleNoRescale, Null, Null, 0, 0, 1 );
    Plot( trailarraydn, "trail dn", colorLightOrange1, styleLine | styleStaircase | styleNoRescale, Null, Null, 0, 0, 1 );
    Plot( trailarrayup, "trail up", colorLightBlue1, styleLine | styleStaircase | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 1 );
    Plot( trailarraydn, "trail dn", colorLightOrange1, styleLine | styleStaircase | styleNoRescale | styleNoLabel, Null, Null, 0, 1, 1 );
    PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorLightBlue1, 0, L, -15 );
    PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorLightOrange1, 0, H, -15 );
    PlotShapes( IIf( Buy, shapeSmallSquare, shapeNone ), colorLightBlue1, 0, BuyPrice, 0 );
    PlotShapes( IIf( Sell, shapeSmallSquare, shapeNone ), colorLightOrange1, 0, SellPrice, 0 );
}

Cover = Buy;
Short = Sell;
longResult = round( IIf( Sell, SellPrice - ValueWhen( Buy, BuyPrice ), 0 ) / TickSize ) * TickSize;
shortResult = round( IIf( Cover, ValueWhen( Short, ShortPrice ) - CoverPrice, 0 ) / TickSize ) * TickSize;

clr = colorDefault;
shiftLabels = 10;//Param( "Shift Labels", 12, -20, 100, 1 );
upColor = colorLightBlue1;
dnColor = colorLightOrange1;

if( labelsswitch )
{
    str1 = "";
    str2 = "";

    for( i = fvb; i <= lvb; i++ )
    {
        if( pk[i] )
        {
            if( dt[i] )
                str1 = "DT";

            if( hh[i] )
                str1 = "HH";

            if( lh[i] )
                str1 = "LH";

            PlotTextSetFont( str1, ft, sz, i, H[i], colorRed, clr, sz * 3 );
        }

        if( tr[i] )
        {
            str1 = "";

            if( db[i] )
                str1 = "DB";

            if( ll[i] )
                str1 = "LL";

            if( hl[i] )
                str1 = "HL";

            PlotTextSetFont( str1, ft, sz, i, L[i], colorBlue, clr, -sz * 4 );
        }

        if( Buy[i] && Cover[i] )
        {
            str = "Buy: " + BuyPrice[i];// + " (" + shortResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -35 - shiftLabels );
            str = "Cover: " + CoverPrice[i] + " (" + shortResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -50 - shiftLabels );
        }

        if( !Buy[i] && Cover[i] )
        {
            str = "Cover: " + CoverPrice[i] + " (" + shortResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -35 - shiftLabels );
        }

        if( Buy[i] && !Cover[i] )
        {
            str = "Buy: " + BuyPrice[i];
            PlotTextSetFont( str, ft, sz, i, L[i], upColor, clr, -35 - shiftLabels );
        }

        if( Short[i] && Sell[i] )
        {
            str = "Short: " + ShortPrice[i];// + " (" + longResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 25 + shiftLabels );
            str = "Sell: " + SellPrice[i] + " (" + longResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 40 + shiftLabels );
        }

        if( !Short[i] && Sell[i] )
        {
            str = "Sell: " + SellPrice[i] + " (" + longResult[i] + ")";
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 25 + shiftLabels );
        }

        if( Short[i] && !Sell[i] )
        {
            str = "Short: " + ShortPrice[i];
            PlotTextSetFont( str, ft, sz, i, H[i], dnColor, clr, 25 + shiftLabels );
        }
    }
}

// back test for futures
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "FuturesMode", True );
SetOption( "PriceBoundChecking", False );
SetOption( "AllowSameBarExit", True );
SetOption( "CommissionMode", 3 );
SetOption( "CommissionAmount", 4 );
SetPositionSize( 1, spsShares );

/*
iBuy = Buy;
iSell = Sell;
iShort = Short;
iCover = Cover;

Short = iBuy;
Cover = iSell;
Buy = iShort;
Sell = iCover;
BuyPrice = SellPrice = ShortPrice = CoverPrice = C;
*/
1 Like

Thanks Mr. @empottasch for your kind effort and guidance. I can clearly see that this latest code is an improvement on earlier code. But it seems that it's not possible to modify the code for letting it to generate the peak-trough on same bar.

Mr. @empottasch

"...I attach my latest code on this ATR code. More interesting is it for you to figure out good point of entry and exit..."
I will certainly work on that to find some indirect approach to handle this problem. And if I succede in trding that solution I will update you.

Below is one of your loop code. This loop allows tpeak-trough on samebar. And I am very happy with that. But I want to have a zigzag whose pivots remain same even after switching to higher timeframe. and for that purpose ATR is best. If somehow ATR could be used with the below loop then I will automatically have all that I want to achieve. Thanks.

xPeak = xTrough = 0;
xPeak_High = 0;
xTrough_Low = 1e5;
Ups = Downs = 0;
IdxHigh = IdxLow = 0;
High_PriceArray = Low_PriceArray = 0;
Breakout_High = Breakout_Low = 0;
UpSwing_Start = DownSwing_Start = 0;

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx




for( i = 0; i < BarCount; i++ )
{
    // UpSwing start
    if( UpSwing[i] AND Ups == 0 )
    {
        IdxHigh = i;
        High_PriceArray = PaH[i];
        Ups = 1;
        Downs = 0;
        UpSwing_Start[i] = 1;

        xTrough[IdxLow] = 1;
        xTrough_Low[IdxLow] = PaL[IdxLow];
    }

    else

        // UpSwing continuation
        if( Ups == 1 AND PaH[i] >= High_PriceArray )
        {
            IdxHigh = i;
            High_PriceArray = PaH[i];
        }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    // DownSwing start
    if( DownSwing[i] AND Downs == 0 )
    {
        IdxLow = i;
        Low_PriceArray = PaL[i];
        Ups = 0;
        Downs = 1;
        DownSwing_Start[i] = 1;

        xPeak[IdxHigh] = 1;
        xPeak_High[IdxHigh] = PaH[IdxHigh];
    }
    else

        // DownSwing continuation
        if( Downs == 1 AND PaL[i] <= Low_PriceArray )
        {
            IdxLow = i;
            Low_PriceArray = PaL[i];
        }

    // breakout lower without swinglow
    if( Ups == 1 AND PaL[i] < Low_PriceArray AND !UpSwing[i] )
    {
        Breakout_Low[i] = 1;
        DownSwing[i] = 1;
        DownSwing_Start[i] = 1;

        IdxLow = i;
        Low_PriceArray = PaL[i];
        Ups = 0;
        Downs = 1;

        xPeak[IdxHigh] = 1;
        xPeak_High[IdxHigh] = High_PriceArray;
    }

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

    // breakout higher without swinghigh
    if( Downs == 1 AND PaH[i] > High_PriceArray AND !DownSwing[i] )
    {
        Breakout_High[i] = 1;
        UpSwing[i] = 1;
        UpSwing_Start[i] = 1;

        IdxHigh = i;
        High_PriceArray = PaH[i];
        Ups = 1;
        Downs = 0;

        xTrough[IdxLow] = 1;
        xTrough_Low[IdxLow] = Low_PriceArray;
    }
}

chart looks weird. That is not my code. Since it suggests it is in High/Low mode. But it is not. It is in Close mode but you draw the zigzag at the high and low. In High/Low mode it would have found these outside bars. Why not post a chart with my code instead of your own code. Show me that same chart in High/Low mode using my code.

Yes best to concentrate on a strategy instead of every wiggle. So many guys making so much money but they can not describe what they do. It must be just gut feel

I humbly assert that it's your code. I just removed the shapes from chart for better clarity.

Making a video also.

Kindly check the video at below link

Video 2024 07 14 152626 (youtu.be)

Thanks

Mr. @empottasch

I guess that perhaps you accidently copy pasted some other code.

Thanks.

with these setting you probably need to use code below.

this line:
if( prcl[i] < trailarrayup[i - 1] )//AND prch[i] < topprc )

and this line:
if( prch[i] > trailarraydn[i - 1] )// AND prcl[i] > botprc )

can be changed to:
if( prcl[i] < trailarrayup[i - 1] AND prch[i] < topprc )

and this :
if( prch[i] > trailarraydn[i - 1] AND prcl[i] > botprc )

I just remember that some undesirable things might happen. Best to check in playback mode. Safest is the original code using the Close price.

Mr. @empottasch

I apologize for bothering you so much. And I sincerely by heart thankful for your efforts. At least you have benefited me by sharing your latest ATR code.

And I will certainly find out some approach to issue that was mentioned by you, because, as far as trading is concerned, whatever is put on my plate I somehow happen to make it quite useful.

Its just that my AFL knowledge is not good, since I am still at the very starting point of my journey to learn AFL.

With or without any indicator I am very good in trading. I am investing my effort in all these tiny-winy wiggle things just to save time and energy for the future that lies ahead, nothing else.

If you happen to integrate ATR in the last loop code [
Please Help me to Mofify a Loop - #8 by LotusHeart ] then please let me know.
If you don't have time for that then no need.

Again I am very grateful to you because the codes you have contributed in the form in various topics had already made my trading a lot easier. Thanks.

I am going to remove the video-proof from Youtube, because this video is sharing your code outside this forum community, and this is against the forum rules.

Mr. @empottasch

Solved the ATR -Zigzag. :smile:
But in order to create the ZigZag I wanted to achieve ( the kind of ZigZag I was disscussing about) , I had to approach it in an entirely different way. After a few thorough checks I didn't find any error yet. To post the solution code, I will take a period of one or two days , becuase I want to check it more extensively before posting it here.

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