To draw those lines (supported by v11 only), you need to use two slightly different copies, with different names, of the same indicator.
This is the same indicator as yours (ITF file attached, as well as a screenshot), but I commented out drawing red and green segments, then I added instructions to keep track of the last two green and red segment to draw those elongated lines at the end:
DEFPARAM DrawOnLastBarOnly = true
ONCE MyHigh1 = 0
ONCE MyHigh2 = 0
ONCE MyLow1 = 0
ONCE MyLow2 = 0
ONCE BarHigh1 = 0
ONCE BarHigh2 = 0
ONCE BarLow1 = 0
ONCE BarLow2 = 0
// This indicator marks highs and lows based on the Stochastic cycle
K = stochastic[5,2]
D = average[3](K)
//start of cycle low looking for the lowest price and lowest MACD as long as Stochastic %D<50
If D =< 50 and D[1] => 50 then
incyclelow = 1
lowestprice2 = lowestprice
Lowestprice = low
Dlowest2 = Dlowest
Dlowest = D
endif
//End of cycle low
If D > 50 and D[1] < 50 then
incyclelow = 0
endif
//lowest macd and price in Stochastic cycle %D<50
if incyclelow then
lowestprice = min(lowestprice, low)
Dlowest = min(Dlowest, D)
endif
//what is the lowest price bar of this cycle?
if lowestprice<>lowestprice[1] then
lowestpriceBar=barindex
endif
//LONG
if incyclelow = 0 then
if lowestpricebar <> BarLow1 then
MyLow2 = MyLow1
BarLow2 = BarLow1
MyLow1 = lowestPrice
BarLow1 = lowestpriceBar
ENDIF
//DRAWSEGMENT(lowestpriceBar,lowestprice,lowestpriceBar,lowestprice-50) COLOURED(0,50,0) STYLE(dottedline, 1)
//DRAWSEGMENT(lowestpriceBar,lowestprice,lowestpriceBar-4,lowestprice) COLOURED(300,0,0) STYLE(line, 3)
endif
//____________________________________________________________________________________________________________________
//start of cycle high looking for the higestest price and higest MACD as long as Stochastic %D>50
If D => 50 and D[1] =< 50 then
incyclehigh = 1
highestprice2 = highestprice
HighestPrice = high
endif
//End of cycle high
If D < 50 and D[1] > 50 then
incyclehigh = 0
endif
//highest stoch and price in cycle high
if incyclehigh then
highestPrice = max(highestPrice, high)
endif
//what is the lowest price bar of this cycle?
if highestprice<>highestprice[1] then
highestpriceBar=barindex
endif
//SHORT
if incyclehigh = 0 then
if highestpricebar <> BarHigh1 then
MyHigh2 = MyHigh1
BarHigh2 = BarHigh1
MyHigh1 = highestPrice
BarHigh1 = highestpriceBar
ENDIF
//DRAWSEGMENT(highestpriceBar,highestprice,highestpriceBar,highestprice+50) COLOURED(50,0,0) STYLE(dottedline, 1)
//DRAWSEGMENT(highestpriceBar,highestprice,highestpriceBar-4,highestprice) COLOURED(0,300,0) STYLE(line, 3)
endif
DrawRay(BarHigh2,MyHigh2,BarHigh1,MyHigh1) coloured(0,0,255,255)
DrawRay(BarLow2 ,MyLow2, BarLow1, MyLow1) coloured(0,0,255,255)
return
as to missing Red/Green segments, please let me know instrument, TF, date and time there should have been one.