Help in correcting this indicator - ZigZag and auto Fibs

Hi,
Can someone please help me figure this out. I am new to programming and I lack the skills and knowledge to figure this out. I have no idea how to do the following;

For an up trend: I want to attach the Fibonacci to the current low and the previous high. For a down trend: I need the Fibonacci to connect to the current high and the previous low.

This is my current Fibonacci setup - File: Fibo current

This is how I want it to look - File: Fibo desired

The code for the indicator.
/------------------------------------------------------------------/
/ I have downloaded this indicator from /
/ .35pip dot com/metatrader-indicators/zigzag-fibo-v2beta-mq4]ZigZag Fibo v2beta mq4 free download (mt4 indicator /
/ /
/ This indicator is designed to attach an /
/ automatic Fibonacci Retracement to a Zig Zag indicator /
/ on the current low and the previous high for an up trend, /
/ and attach one to a current high and a previous low for a /
/ down trend /
/ /
/------------------------------------------------------------------
/

// fukinagashi

//RaptorUK 2011.10.15 17:00
//The Fib is attaching to LastZigZag and PreviousZigZag, you want it to attach to PreviousZigZap and OneBeforePreviousZigZag . . .
//you will need to create OneBeforePreviousZigZag and give it the correct values in the code.

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 White
//---- indicator parameters
//ZigZag settings
extern int ExtDepth=7; // Original setting 12
extern int ExtDeviation=5;
extern int ExtBackstep=3;
//---- indicator buffers
double ExtMapBuffer[];
double ExtMapBuffer2[];

int OldLastZigZag, OldPreviousZigZag;

//±-----------------------------------------------------------------+
//| Custom indicator initialization function |
//±-----------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
//---- drawing settings
SetIndexStyle(0,DRAW_SECTION,3); //Zig Zag Line; 0 = Line true, 1 = line false
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(0,0.0);
ArraySetAsSeries(ExtMapBuffer,true);
ArraySetAsSeries(ExtMapBuffer2,true);
//---- indicator short name
IndicatorShortName(“Fibodrawer”);
//---- initialization done
return(0);
}

int deinit() {
ObjectDelete(“Fibonacci Lines”);
}
//±-----------------------------------------------------------------+
//| |
//±-----------------------------------------------------------------+
int start()
{
int shift, back,lasthighpos,lastlowpos;
double val,res;
double curlow,curhigh,lasthigh,lastlow;

for(shift=Bars-ExtDepth; shift>=0; shift–)
{
val=Low[Lowest(NULL,0,MODE_LOW,ExtDepth,shift)];
if(val==lastlow) val=0.0;
else
{
lastlow=val;
if((Low[shift]-val)>(ExtDeviationPoint)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ExtMapBuffer[shift+back];
if((res!=0)&&(res>val)) ExtMapBuffer[shift+back]=0.0;
}
}
}
ExtMapBuffer[shift]=val;
//— high
val=High[Highest(NULL,0,MODE_HIGH,ExtDepth,shift)];
if(val==lasthigh) val=0.0;
else
{
lasthigh=val;
if((val-High[shift])>(ExtDeviation
Point)) val=0.0;
else
{
for(back=1; back<=ExtBackstep; back++)
{
res=ExtMapBuffer2[shift+back];
if((res!=0)&&(res<val)) ExtMapBuffer2[shift+back]=0.0;
}
}
}
ExtMapBuffer2[shift]=val;
}

// final cutting
lasthigh=-1; lasthighpos=-1;
lastlow=-1; lastlowpos=-1;

for(shift=Bars-ExtDepth; shift>=0; shift–)
{
curlow=ExtMapBuffer[shift];
curhigh=ExtMapBuffer2[shift];
if((curlow==0)&&(curhigh==0)) continue;
//—
if(curhigh!=0)
{
if(lasthigh>0)
{
if(lasthigh<curhigh) ExtMapBuffer2[lasthighpos]=0;
else ExtMapBuffer2[shift]=0;
}
//—
if(lasthigh<curhigh || lasthigh<0)
{
lasthigh=curhigh;
lasthighpos=shift;
}
lastlow=-1;
}
//----
if(curlow!=0)
{
if(lastlow>0)
{
if(lastlow>curlow) ExtMapBuffer[lastlowpos]=0;
else ExtMapBuffer[shift]=0;
}
//—
if((curlow<lastlow)||(lastlow<0))
{
lastlow=curlow;
lastlowpos=shift;
}
lasthigh=-1;
}
}

for(shift=Bars-1; shift>=0; shift–)
{
if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0;
else
{
res=ExtMapBuffer2[shift];
if(res!=0.0) ExtMapBuffer[shift]=res;
}

 } 
 
int i=0;
int LastZigZag, PreviousZigZag;

int h=0;
while ( ExtMapBuffer[h]==0 && ExtMapBuffer2[h]==0) {
h++;
}

LastZigZag=h;

h++;
while(ExtMapBuffer[h]==0 && ExtMapBuffer2[h]==0) {
h++;
}

PreviousZigZag=h;

if (OldLastZigZag!=LastZigZag || OldPreviousZigZag!=PreviousZigZag) {
OldLastZigZag=LastZigZag;
OldPreviousZigZag=PreviousZigZag;

if (OldLastZigZag!=LastZigZag || OldPreviousZigZag!=PreviousZigZag) {
OldLastZigZag=LastZigZag;
OldPreviousZigZag=PreviousZigZag;

  WindowRedraw();
  ObjectCreate("Fibonacci Lines", OBJ_FIBO, 0, Time[PreviousZigZag], ExtMapBuffer[LastZigZag], 
  Time[LastZigZag], ExtMapBuffer[PreviousZigZag]);
  color levelColor = Aqua;
  }
  
  else{
  WindowRedraw();
  ObjectCreate("Fibonacci Lines", OBJ_FIBO, 0, Time[PreviousZigZag], ExtMapBuffer[LastZigZag], 
  Time[LastZigZag], ExtMapBuffer[PreviousZigZag]);
  levelColor = Aqua;
  }

ObjectDelete("Fibonacci Lines");
ObjectCreate("Fibonacci Lines", OBJ_FIBO, 0, Time[PreviousZigZag], ExtMapBuffer[LastZigZag], 
Time[LastZigZag], ExtMapBuffer[PreviousZigZag]);
// OBJ_FIBO, 0 - Fibonacci retracement. Uses 2 coordinates. 
// OBJ_FIBO, 1, Set Fibo to false*/
                               
  double fiboPrice1=ObjectGet("Fibonacci Lines",OBJPROP_PRICE1);
  double fiboPrice2=ObjectGet("Fibonacci Lines",OBJPROP_PRICE2);
  
  /*
  double fiboPriceDiff = fiboPrice2-fiboPrice1;
  string fiboValue0 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.0,Digits);
  string fiboValue23 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.236,Digits);
  string fiboValue38 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.382,Digits);
  string fiboValue50 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.50,Digits);
  string fiboValue61 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.618,Digits);
  string fiboValue100 = DoubleToStr(fiboPrice2-fiboPriceDiff*1.0,Digits);
*/
 ObjectSet("Fibonacci Lines",OBJPROP_FIBOLEVELS,9);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+0,0.0);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+1,0.236);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+2,0.382);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+3,0.50);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+4,0.618);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+5,1);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+6,1.618);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+7,2.618);
 ObjectSet("Fibonacci Lines",OBJPROP_FIRSTLEVEL+8,4.236);
 
 ObjectSet("Fibonacci Lines",OBJPROP_LEVELCOLOR,levelColor);
 ObjectSet("Fibonacci Lines",OBJPROP_LEVELWIDTH,1);
 ObjectSet("Fibonacci Lines",OBJPROP_LEVELSTYLE,STYLE_SOLID);
 ObjectSetFiboDescription( "Fibonacci Lines", 0,"%$  --&gt; 0.0%"); 
 ObjectSetFiboDescription( "Fibonacci Lines", 1,"%$ --&gt; 23.6%"); 
 ObjectSetFiboDescription( "Fibonacci Lines", 2,"%$ --&gt; 38.2%"); 
 ObjectSetFiboDescription( "Fibonacci Lines", 3,"%$ --&gt; 50.0%");
 ObjectSetFiboDescription( "Fibonacci Lines", 4,"%$ --&gt; 61.8%");
 ObjectSetFiboDescription( "Fibonacci Lines", 5,"%$ --&gt; 100.0%");
 ObjectSetFiboDescription( "Fibonacci Lines", 6,"%$ --&gt; 161.5%");
 ObjectSetFiboDescription( "Fibonacci Lines", 7,"%$ --&gt; 261.8%");
 ObjectSetFiboDescription( "Fibonacci Lines", 8,"%$ --&gt; 423.6%");

}
}

Please help me to move this Fib to the correct position.
Any advise will be greatly appreciated.
Thanks

No better teacher than trial and error.
I figured it out and now the indicator is working like a charm.

Show me the pips!!!

Doubtful you will ever read this, but did you get this ZigZag fixed and updated? I’d love to see it with the Fibs working right.

I can offer something in trade: this is my ZigZag I got from another forum that draws a horizontal line at the past swings (fixed ZZ points) and works pretty cool (I can’t seem to upload it, but here’s the link - it’s in post #105)

https://www.forexfactory.com/showthread.php?t=227018&page=6