inputs: iAlert(false), iStartDate(1070101), iPlotFibs(true), iPlotSR(true), iPlotTrade(false), iPrice( Close ), iDecimals(2), iPeriods(5), iFibPlot("R"), iFib1(.24), iFib2(.38), iFib3(.50), iFib4(.62), iFib5(.76), iFib1Color(darkcyan ), iFib2Color(darkbrown), iFib3Color(darkgray), iFib4Color(darkbrown ), iFib5Color(darkcyan ), HighColor( red), LowColor( blue), idummy(""); variables: fg8(white), bg8(black), xAppType(0), sFirstPass(true), tInd(""), tAlert(""), xFib1(iFib1), xFib2(iFib2), xFib3(iFib3), xFib4(iFib4), xFib5(iFib5), tFib(""), xLowestLow(0), xHighestHigh(0), xRange(0), xPosition(0), oExtremeVal( 0 ), oExtremeBar( 0 ) ; variables: xBars( 0 ), xPeriods(05), xOldPeriods(0), Dynamic_R( 0 ), Dynamic_S( 0 ), OldDynamic_R( 0 ), OldDynamic_S( 0 ), PrevDynamic_R( 0 ), PrevDynamic_S( 0 ) ; {commentary variables} variables: xcomm(0), oComm1( "" ), oComm2( "" ), oComm3( "" ), oComm4( "" ), oComm5( "" ), oComm6( "" ), oComm7( "" ), oComm8( "" ), oComm9( "" ), oComm10( "" ); {first time through} if sFirstPass then begin sFirstPass = false; { APP TYPE TEST } sFirstPass = false; xAppType = GetAppInfo(aiApplicationType); end; {if sFirstPass} { INITIALIZE } tInd = ""; tAlert = ""; { CALCULATIONS } If date this bar >= iStartDate then begin {save old values} If Dynamic_R <> PrevDynamic_R then OldDynamic_R = PrevDynamic_R; If Dynamic_S <> PrevDynamic_S then OldDynamic_S = PrevDynamic_S ; OldDynamic_R = PrevDynamic_R ; OldDynamic_S = PrevDynamic_S ; PrevDynamic_R = Dynamic_R ; PrevDynamic_S = Dynamic_S ; { high / low for period } xBars = xBars + 1; oExtremeVal = Extremes( L, iPeriods, -1, Dynamic_S , oExtremeBar ) ; oExtremeVal = Extremes( H, iPeriods, 1, Dynamic_R , oExtremeBar ) ; If Dynamic_R <> H and Dynamic_R < PrevDynamic_R then if PrevDynamic_R <> 0 then Dynamic_R = PrevDynamic_R; If Dynamic_S <> L and Dynamic_S > PrevDynamic_S then if PrevDynamic_S <> 0 then Dynamic_S = PrevDynamic_S; { If iLow <> iLow[1] Or iHigh <> iHigh[1] then begin } If iFibPlot = "R" Or iFibPlot = "r" then begin xLowestLow = Dynamic_S ; xRange = Dynamic_R - Dynamic_S ; xFib1 = iFib1 * xRange + xLowestLow; xFib2 = iFib2 * xRange + xLowestLow; xFib3 = iFib3 * xRange + xLowestLow; xFib4 = iFib4 * xRange + xLowestLow; xFib5 = iFib5 * xRange + xLowestLow; end else Begin xLowestLow = Dynamic_S ; xHighestHigh = Dynamic_R ; xRange = xHighestHigh - xLowestLow; If close > OpenD(0) then begin xFib1 = iFib1 * xRange + xHighestHigh; xFib2 = iFib2 * xRange + xHighestHigh; xFib3 = iFib3 * xRange + xHighestHigh; xFib4 = iFib4 * xRange + xHighestHigh; xFib5 = iFib5 * xRange + xHighestHigh; end else begin xFib1 = xLowestLow - iFib1 * xRange ; xFib2 = xLowestLow - iFib2 * xRange ; xFib3 = xLowestLow - iFib3 * xRange ; xFib4 = xLowestLow - iFib4 * xRange ; xFib5 = xLowestLow - iFib5 * xRange ; end; end; { Alert criteria } If high >= Dynamic_R then begin Fg8 = red; Bg8 = white; tAlert = "Price touched Resistance" ; end else If Low <= Dynamic_S then begin Fg8 = blue; Bg8 = white; tAlert = "Price touched Support" ; end; { Alert } if iAlert and tAlert <> "" then Alert( tAlert ) ; if iPlotFibs then begin Plot1(xFib1 , "fib1", iFib1Color ) ; Plot2(xFib2 , "fib2", iFib2Color ) ; Plot3(xFib3 , "fib3", iFib3Color ) ; Plot4(xFib4 , "fib4", iFib4Color ) ; Plot5(xFib5 , "fib5", iFib5Color ) ; end; if iPlotSR then begin Plot6(Dynamic_R , "Resistance", HighColor ) ; Plot7(Dynamic_S , "Support", LowColor ) ; end; if iPlotTrade then begin if Low[1] = Dynamic_S and Close[1] > Low[1] then Plot9 (Dynamic_S , "go long", white ) ; if High[1] = Dynamic_R and Close[1] < High[1] then Plot10 (Dynamic_R , "go short", white ) ; end ; end; if xAppType = 2 then begin if close = xFib1 then SetPlotBGColor( 1, white ); if close = xFib2 then SetPlotBGColor( 2, white ); if close = xFib3 then SetPlotBGColor( 3, white ); if close = xFib4 then SetPlotBGColor( 4, white ); if close = xFib5 then SetPlotBGColor( 5, white ); if close = Dynamic_R then SetPlotBGColor( 6, white ); if close = Dynamic_S then SetPlotBGColor( 7, white ); {Plot8(tAlert , "Alert", yellow ) ;} end; CommentaryCl( "Dynamic_R: ", NumToStr( Dynamic_R , iDecimals) ); CommentaryCl( "Dynamic_S: ", NumToStr( Dynamic_S , iDecimals) );