【 ZigZag Fibonacci Plus】
[code]inputs:
RetraceType( 1 ) , { Choose: 1 Pnts, 2 Pct }
RetracePnts( 5 ) ,
RetracePct( 5 ) ,
ShowZigZagLines( True ) ,
ShowSwingPointLines( True ) ,
ZigZagLineColor( Magenta ) ,
ZigZagLineWidth( 1 ),
SwingHighColor( Black ) ,
SwingLowColor (Red ) ,
SwingLineStyle( Tool_Dotted ),
VertOffset( 0.25 ),
DecimalPlaces( 2 ),
{HamFon Fib inputs}
ShowOpenLine (False), ExtRight(True),
TextColor(LightGray),
HiLoColor (Magenta), OuterFibColor (DarkGreen),
MidColor(Magenta), InnerFibColor(Red), FibPlusColor(DarkGray), OpenColor (Darkbrown);
variables:
NewSwingPrice( 0 ) ,
LastSwingPrice(0 ) ,
SwingPrice( High ) , { used as a convenient 2-element array }
SwingDate( Date ) , { used as a convenient 2-element array }
SwingTime( Time ) , { used as a convenient 2-element array }
RetraceFctrUp( 1 + RetracePct * .01 ),
RetraceFctrDn( 1 - RetracePct * .01 ),
TLDir( 0 ), { TLDir = -1 implies prev TL dn, +1 implies prev TL up }
SaveSwing( false ) ,
AddTL( false ) ,
UpdateTL( false ) ,
TLRef( 0 ) ,
TLSwing( 0 ),
PeakTextRef( 0 ) ,
PeakStr("") ,
{HamFon variables inputs}
TLCreated (false), Redraw (false), Loop (0), Diff(0),
ArrayMax (11);
vars: showDebug(FALSE);
arrays: TrendLine[11] (0), DayValue[11] (0), FibText[11](0), FibLabel[11](" ");
//Create initial fib lines
if CurrentBar = 1 then begin
for loop=0 to ArrayMax begin {added Color for visual differentiation}
if loop <= ArrayMax then begin
TrendLine[loop] = TL_New (Date[1], Time[1], Low, Date, Time, Low);
If (loop = 4) then
TL_SetColor (TrendLine[loop], MidColor)
else if (loop = 0) or (Loop = 1) then
TL_SetColor (TrendLine[loop], HiLoColor)
else if (loop = 3 ) or (loop = 5 ) then
TL_SetColor (TrendLine[loop], InnerFibColor)
else if (Loop = 2) or (loop = 6) then
TL_SetColor (Trendline[loop], OuterFibColor)
{else if (Loop > 7) then
TL_setcolor(Trendline[loop], red)}
else TL_SetColor (TrendLine[loop], FibPlusColor);
TL_SetExtLeft (TrendLine[loop], false);
TL_SetExtRight (TrendLine[loop], True);
if loop = 4 then
TL_SetStyle(TrendLine[loop],Tool_dotted);
FibText[loop] = Text_New(Date, Time, Low, " " ) ;
Text_SetColor(FibText[loop], TextColor) ;
end; // if loop
end; // for loop
FibLabel[0] = "1" ; {Max Swing }
FibLabel[1] = "0" ; { Min Swing }
FibLabel[2] = ".236" ;
FibLabel[3] = ".382" ;
FibLabel[4] = ".5" ;
FibLabel[5] = ".618" ;
FibLabel[6] = ".764" ;
FibLabel[7] = ".886" ;
FibLabel[8] = "1.23" ;
FibLabel[9] = "1.5" ;
FibLabel[10] = "1.62" ;
FibLabel[11] = "2.00" ;
end; //if currentbar
{ Candidate swings are just-confirmed, 3-bar (Str=1), SwingHi's and SwingLo's }
NewSwingPrice = SwingHigh( 1, High, 1, 2 ) ;
if NewSwingPrice <> -1 then
begin
if ( RetraceType = 1 and TLDir <= 0 and NewSwingPrice >= SwingPrice + RetracePnts ) or
( RetraceType = 2 and TLDir <= 0 and NewSwingPrice >= SwingPrice * RetraceFctrUp ) then
{ prepare to add new up TL }
begin
SaveSwing = true ;
AddTL = true ;
TLDir = 1 ;
end
else if TLDir = 1 and NewSwingPrice >= SwingPrice then
{ prepare to update prev up TL }
begin
SaveSwing = true ;
UpdateTL = true ;
end ;
end
else
begin
NewSwingPrice = SwingLow( 1, Low, 1, 2 ) ;
if NewSwingPrice <> -1 then
begin
if ( RetraceType = 1 and TLDir >= 0 and NewSwingPrice <= SwingPrice - RetracePnts ) or
( RetraceType = 2 and TLDir >= 0 and NewSwingPrice <= SwingPrice * RetraceFctrDn ) then
{ prepare to add new dn TL }
begin
SaveSwing = true ;
AddTL = true ;
TLDir = -1 ;
end
else if TLDir = -1 and NewSwingPrice <= SwingPrice then
{ prepare to update prev dn TL }
begin
SaveSwing = true;
UpdateTL = true ;
end ;
end ;
end ;
if SaveSwing then
{ save new swing and reset SaveSwing }
begin
SwingPrice = NewSwingPrice ;
SwingDate = Date[1] ;
SwingTime = Time[1] ;
// SaveSwing = false ;
end ;
if (showDebug) then
print(" AddTL === ", AddTL, " UpdateTL == ", UpdateTL, "SaveSwing == ", SaveSwing, " TL Dir = ", TLDir);
if AddTL then
{ add new TL and reset AddTL }
begin
PeakTextRef = Text_New(Date, Time, Close, " ") ;
Text_SetColor(PeakTextRef, TextColor ) ;
if ShowZigZagLines then
begin
TLRef = TL_New( SwingDate, SwingTime, SwingPrice, SwingDate[1], SwingTime[1],
SwingPrice[1] ) ;
Text_SetStyle(PeakTextRef, 2, 2 );
TL_SetExtLeft( TLRef, false ) ;
TL_SetExtRight( TLRef, false ) ;
TL_SetSize( TLRef, ZigZagLineWidth ) ;
TL_SetColor( TLRef, ZigZagLineColor ) ;
LastSwingPrice = SwingPrice[1];
end ;
if ShowSwingPointLines then
begin
TLSwing = TL_New( Date[1], Time[1], SwingPrice, Date, Time, SwingPrice ) ;
if TLDir = -1 then
TL_SetColor( TLSwing, SwingLowColor )
else
TL_SetColor( TLSwing, SwingHighColor ) ;
TL_SetStyle( TLSwing, SwingLineStyle ) ;
TL_SetExtLeft( TLSwing, False ) ;
TL_SetExtRight( TLSwing, False ) ;
end ;
if TLDir = -1 then
PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(LastSwingPrice - SwingPrice, DecimalPlaces )
else
PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(SwingPrice - LastSwingPrice, DecimalPlaces ) ;
Text_SetString(PeakTextRef, PeakStr );
if TLDir = -1 then
Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice - VertOffset )
else
Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice + VertOffset );
AddTL = false ;
end
else if UpdateTL then
{ update prev TL and reset UpdateTL }
begin
if ShowZigZagLines then
TL_SetEnd( TLRef, SwingDate, SwingTime, SwingPrice ) ;
if ShowSwingPointLines then
begin
TL_SetEnd( TLSwing, SwingDate, SwingTime, SwingPrice ) ;
TL_SetBegin( TLSwing, SwingDate, SwingTime, SwingPrice ) ;
end ;
if TLDir = -1 then
PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(LastSwingPrice - SwingPrice, DecimalPlaces )
else PeakStr = "" + NumToStr(SwingPrice,DecimalPlaces) + " / " + NumToStr(SwingPrice - LastSwingPrice, DecimalPlaces ) ;
Text_SetString( PeakTextRef, PeakStr );
if TLDir = -1 then
Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice - VertOffset)
else
Text_SetLocation(PeakTextRef, SwingDate, SwingTime, SwingPrice + VertOffset);
UpdateTL = false ;
end ;
{************* HamFons' FIB POINTS Code:
goal is to call the LAST SWING HI AND LAST SWING LO from ABOVE CODE
and draw Fib points between them *****************}
if (showDebug) then
print("SaveSwing == ", SaveSwing, " TL Dir = ", TLDir);
//Update Fib lines
if SaveSwing then begin
if TLDir = -1 then
begin
DayValue[0] = Swingprice;
DayValue[1] = LastSwingprice;
end
else
begin
DayValue[1] = Swingprice;
DayValue[0] = LastSwingprice;
end ;
Diff = DayValue[0] - DayValue[1];
if (showDebug) then
print("Day0 = ", DayValue[0], " DayMax= ", DayValue[1], " Diff =", Diff, " TLDir = ", TLDir);
DayValue[2] = DayValue[1] + Diff * .236;
DayValue[3] = DayValue[1] + Diff * .382;
DayValue[4] = DayValue[1] + Diff * .5;
DayValue[5] = DayValue[1] + Diff * .618;
DayValue[6] = DayValue[1] + Diff * .764;
DayValue[7] = DayValue[1] + Diff * .886;
DayValue[8] = DayValue[1] + Diff * 1.23;
DayValue[9] = DayValue[1] + Diff * 1.5;
DayValue[10] = DayValue[1] + Diff * 1.62;
DayValue[11] = DayValue[1] + Diff * 2.00;
for loop=0 to ArrayMax begin
{ SetEnd before SetBegin }
if TrendLine[loop] > 0 then begin
TL_SetEnd (TrendLine[loop], Date, Time, DayValue[loop]);
TL_SetBegin (TrendLine[loop], Date, Time, DayValue[loop]);
end; // if TrendLine
end; // for loop
SaveSwing = False ;
end ; // if SaveSwing
for loop=0 to ArrayMax begin
if (showDebug) then
print("Dayvalue[",Loop,"]= ", DayValue[Loop]);
if FibText[loop] > 0 then begin
Text_SetLocation(FibText[loop],Date,Time +1, Dayvalue[loop]);
if TLDir = -1 then
Text_SetString(FibText[loop],NumToStr(DayValue[loop],DecimalPlaces) + " / " + FibLabel[loop] )
else
Text_SetString(FibText[loop],NumToStr(DayValue[loop],DecimalPlaces) + " / " + FibLabel[loop] ) ;
end ;
end;
[/code]
页:
[1]