Code: Function: TL_Zigzag inputs: Price( numericseries ), RetraceMethod( numericsimple ), { 1 = percent, 2 = number } retrace( numericsimple ), LineColor( numericsimple ), LineWidth( numericsimple ), PlotLine( truefalse ) ; variables: NewSwingPrice( 0 ), SwingPrice( Price ), { 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 } TLDir( 0 ), { TLDir = -1 implies prev TL dn, +1 implies prev TL up } RetraceFctrUp( 1 + retrace * .01 ), RetraceFctrDn( 1 - retrace * .01 ), SaveSwing( false ), AddTL( false ), UpdateTL( false ), TLRef( 0 ), ZigZagTrend( 0 ) ; { Candidate swings are just confirmed, 3-bar (Str=1), SwingHi's and SwingLo's } NewSwingPrice = SwingHigh( 1, Price, 1, 2 ) ; if NewSwingPrice <> -1 then begin if ( RetraceMethod = 1 and TLDir <= 0 and NewSwingPrice >= SwingPrice * RetraceFctrUp ) or ( RetraceMethod = 2 and TLDir <= 0 and NewSwingPrice >= SwingPrice + Retrace ) 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, Price, 1, 2 ) ; if NewSwingPrice <> -1 then begin if (RetraceMethod = 1 and TLDir >= 0 and NewSwingPrice <= SwingPrice * RetraceFctrDn) or (RetraceMethod = 2 and TLDir >= 0 and NewSwingPrice <= SwingPrice - retrace ) 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 AddTL then { add new TL and reset AddTL } begin if Plotline then begin TLRef = TL_New( SwingDate, SwingTime, SwingPrice, SwingDate[1], SwingTime[1], SwingPrice[1] ) ; TL_SetExtLeft( TLRef, false ) ; TL_SetExtRight( TLRef, false ) ; TL_SetSize( TLRef, LineWidth ) ; TL_SetColor( TLRef, LineColor ) ; end ; AddTL = false ; end else if UpdateTL then { update prev TL and reset UpdateTL } begin if PlotLine then TL_SetEnd( TLRef, SwingDate, SwingTime, SwingPrice ) ; UpdateTL = false ; end ; TL_ZigZag = SwingPrice ; Indicator: Zigzag Trend inputs: Price( Close ), RetraceMethod( 1 ), { 1 = percent, 2 = number } retrace( .75 ), LineColor( Yellow ), LineWidth( 1 ), PlotLine( true ) ; variables: SwingPrice( Price ), { used as a convenient 2-element array } ZigZagTrend( 0 ) ; { Candidate swings are just-confirmed, 3-bar (Str=1), SwingHi's and SwingLo's } SwingPrice = TL_ZigZag( Price, RetraceMethod, retrace, LineColor, LineWidth, PlotLine ) ; if SwingPrice > SwingPrice[1] then begin print( SwingPrice, " ", SwingPrice[1] ) ; ZigZagTrend = 1 ; end else if SwingPrice < SwingPrice[1] then begin ZigZagTrend = -1 ; end ; Plot1( ZigZagTrend, "Zig" ) ; print( date, " ", time, " ", SwingPrice, " ", SwingPrice[1], " ", zigZagtrend ) ; Strategy: Zigzag Trend Strat inputs: Price( Close ), RetraceMethod( 1 ), { 1 = percent, 2 = number } retrace( .75 ), LineColor( Yellow ), LineWidth( 1 ), PlotLine( true ) ; variables: SwingPrice( Price ), { used as a convenient 2-element array } ZigZagTrend( 0 ) ; { Candidate swings are just-confirmed, 3-bar (Str=1), SwingHi's and SwingLo's } SwingPrice = TL_ZigZag( Price, RetraceMethod, retrace, LineColor, LineWidth, PlotLine ) ; if SwingPrice > SwingPrice[1] then begin ZigZagTrend = 1; end else if SwingPrice < SwingPrice[1] then begin ZigZagTrend = -1; end; if ZigZagTrend =1 and ZigZagTrend[1]= -1 then buy next bar at market else if ZigZagTrend =-1 and ZigZagTrend[1]= 1 then sellshort next bar at market ; Function: CMO inputs: Length( numericsimple ); variables: CMO_1(0), CMO_2(0), CMO_Final(0); if C > C[1] then begin CMO_1 = C - C[1] ; CMO_2 = 0 ; end else begin CMO_1 = 0 ; CMO_2 = C[1] - C ; end; Value1 = Summation( CMO_1, Length ); Value2 = Summation( CMO_2, Length ) ; CMO = ( Value1 - Value2 )/( Value1 + Value2 ) * 50 + 50 ; Indicator: CMO inputs: Length( 14 ) ; if CurrentBar > Length then Plot1( CMO( Length ), "CMO" ) ; Plot2( 0, "Zero" ) ; print( plot1 ) ;