#рисует линии Пивота по Фибоначчи на графике. #built by tinkorswim UT_kyiv, sylchenko input DynamicHide = {"No", default "Yes"}; input showOnlyToday = YES; input Market_Open_Time = 0830; input Market_Close_Time = 1616; def h = DynamicHide; def day = GetDay(); def lastDay = GetLastDay(); def isToday = If(day == lastDay, 1, 0); def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0)); def pastOpen = If((SecondsTillTime(Market_Open_Time) > 0), 0, 1); def pastClose = If((SecondsTillTime(Market_Close_Time) > 0), 0, 1); def marketOpen = If(pastOpen and !pastClose, 1, 0); def firstBar = If (day[1] != day, 1, 0); def closingBell = if SecondsTillTime(Market_Close_Time)[1] > 0 and SecondsTillTime(Market_Close_Time) <= 0 or (SecondsTillTime(Market_Close_Time)[1] < SecondsTillTime(Market_Close_Time) and SecondsTillTime(Market_Close_Time)[1] > 0) then 1 else 0; rec lclose = if IsNaN(close[-1]) then lclose[1] else close; rec regHoursHigh = If(high > regHoursHigh[1] and marketOpen, high, If(marketOpen and !firstBar, regHoursHigh[1], high)); rec regHoursLow = If(low < regHoursLow[1] and marketOpen, low, If(marketOpen and regHoursLow[1] > 0 and !firstBar, regHoursLow[1], low)); rec runningClose = CompoundValue(1, if closingBell then close[1] else runningClose[1], close); rec prevClose = CompoundValue(1, if closingBell then runningClose else prevClose[1], close); rec prevHigh = CompoundValue(1, if closingBell then regHoursHigh[1] else prevHigh[1], high); rec prevLow = CompoundValue(1, if closingBell then regHoursLow[1] else prevLow[1], low); rec prevHigh2 = CompoundValue(1, if closingBell then prevHigh[1] else prevHigh2[1], high); rec prevLow2 = CompoundValue(1, if closingBell then prevLow[1] else prevLow2[1], low); plot pivot = if shouldPlot then (prevHigh + prevClose + prevLow) / 3 else Double.NaN; pivot.SetStyle(Curve.FIRM); pivot.SetDefaultColor(Color.BLACK); plot s1 = if shouldPlot then pivot - 0.382 * (prevHigh - prevLow) else Double.NaN; s1.SetStyle(Curve.FIRM); s1.SetDefaultColor(Color.DARK_GREEN); plot s2 = if shouldPlot then pivot - 0.618 * (prevHigh - prevLow) else Double.NaN; s2.SetStyle(Curve.FIRM); s2.SetDefaultColor(Color.DARK_GREEN); plot s3 = if shouldPlot then pivot - 1 * (prevHigh - prevLow) else Double.NaN; s3.SetStyle(Curve.FIRM); s3.SetDefaultColor(Color.DARK_GREEN); plot s4 = if shouldPlot then pivot - 1.382 * (prevHigh - prevLow) else Double.NaN; s4.SetStyle(Curve.FIRM); s4.SetDefaultColor(Color.DARK_GREEN); plot r1 = if shouldPlot then pivot + 0.382 * (prevHigh - prevLow) else Double.NaN; r1.SetStyle(Curve.FIRM); r1.SetDefaultColor(Color.DARK_RED); plot r2 = if shouldPlot then pivot + 0.618 * (prevHigh - prevLow) else Double.NaN; r2.SetStyle(Curve.FIRM); r2.SetDefaultColor(Color.DARK_RED); plot r3 = if shouldPlot then pivot + 1 * (prevHigh - prevLow) else Double.NaN; r3.SetStyle(Curve.FIRM); r3.SetDefaultColor(Color.DARK_RED); plot r4 = if shouldPlot then pivot + 1.382 * (prevHigh - prevLow) else Double.NaN; r4.SetStyle(Curve.FIRM); r4.SetDefaultColor(Color.DARK_RED); pivot.SetHiding(h and (lclose > r2 or lclose < s2)); r1.SetHiding(h and lclose < s1); r2.SetHiding(h and lclose < r1); r3.SetHiding(h and lclose < r2); r4.setHiding(h and lclose < r3); s1.SetHiding(h and lclose > r1); s2.SetHiding(h and lclose > s1); s3.SetHiding(h and lclose > s2); s4.SetHiding(h and lclose > s3);