defparam drawonlastbaronly = true
//-----Inputs---------------------------------------------//
barsReq=6//Consecutive Bars Required
percGain=0.0//Percent Gain Required
opposites=0//Boolean//Require Opposite Order Block
//--------------------------------------------------------//
gainBull=abs(low[barsReq]-close)/low[barsReq]*100
gainBear=abs(high[barsReq]-close)/high[barsReq]*100
gainCheck=gainBull >= percGain or gainBear >= percGain
lastDown=close[barsReq]<open[barsReq]
lastUp=close[barsReq]>open[barsReq]
barsCount1=0
if lastDown then
for i=0 to barsReq do
if close[i]>open[i] then
barsCount1=barsCount1+1
endif
next
endif
barsCount=0
if lastUp then
for j=0 to barsReq do
if close[j]<open[j] then
barsCount=barsCount+1
endif
next
endif
//--------------------------------------------------------//
if opposites then
bullish=lastDown and barsCount1>=barsReq and gainCheck and not bu
bearish=lastUp and barsCount>=barsReq and gainCheck and not be
else
bullish=lastDown and barsCount1>=barsReq and gainCheck and (not bu or bu)
bearish=lastUp and barsCount>=barsReq and gainCheck and (not be or be)
endif
//--------------------------------------------------------//
once bu=0
once be=0
if bullish then
bu=1
be=0
$Bull[z+1]=1
$Bear[t]=0
$ObBullTop[z+1]=high[barsReq]
$ObBullBot[z+1]=low[barsReq]
$ObBullX[z+1]=barindex[barsReq]
$ObBullX2[z+1]=barindex[barsReq]
z=z+1
endif
if bearish then
bu=0
be=1
$Bull[z]=0
$Bear[t+1]=1
$ObBearTop[t+1]=High[barsReq]
$ObBearBot[t+1]=Low[barsReq]
$ObBearX[t+1]=barindex[barsReq]
$ObBearX2[t+1]=barindex[barsReq]
t=t+1
endif
if islastbarupdate then
for i=z downto 0 do
for k=barindex downto 0 do
if barindex[k]>$ObBullX[i]+barsReq and close[k] < $ObBullTop[i] then
$ObBullX2[i]=barindex[k]
break
else
$ObBullX2[i]=barindex//$ObBullX[i]+150
endif
next
drawrectangle($ObBullX[i],$ObBullBot[i],$ObBullX2[i],$ObBullTop[i])fillcolor("green",35)coloured("green")
next
for j=t downto 0 do
for w=barindex downto 0 do
if barindex[w]>$ObBearX[j]+barsReq and close[w] > $ObBearTop[j] then
$ObBearX2[j]=barindex[w]
break
else
$ObBearX2[j]=barindex//$ObBearX[j]+150
endif
next
drawrectangle($ObBearX[j],$ObBearBot[j],$ObBearX2[j],$ObBearTop[j])fillcolor("red",35)coloured("red")
next
if $ObBullX[z]>$ObBearX[t] then
barsfibBull=barindex-$ObBullX[z]
lev0bu=highest[barsfibBull](high)
lev1bu=$ObBullBot[z]
fibTotalbu=lev0bu-lev1bu
lev236bu=lev0bu-(fibTotalbu*0.236)
lev382bu=lev0bu-(fibTotalbu*0.382)
lev50bu=lev0bu-(fibTotalbu*0.500)
lev618bu=lev0bu-(fibTotalbu*0.618)
lev786bu=lev0bu-(fibTotalbu*0.786)
drawsegment($ObBullX[z],lev0bu,$ObBullX2[z]+20,lev0bu)style(line)
drawsegment($ObBullX[z],lev1bu,$ObBullX2[z]+20,lev1bu)style(line)
drawsegment($ObBullX[z],lev236bu,$ObBullX2[z]+20,lev236bu)style(dottedline2)
drawsegment($ObBullX[z],lev382bu,$ObBullX2[z]+20,lev382bu)style(dottedline2)
drawsegment($ObBullX[z],lev50bu,$ObBullX2[z]+20,lev50bu)style(dottedline2,2)coloured("blue")
drawsegment($ObBullX[z],lev618bu,$ObBullX2[z]+20,lev618bu)style(dottedline2,2)coloured("red")
drawsegment($ObBullX[z],lev786bu,$ObBullX2[z]+20,lev786bu)style(dottedline2)
else
barsfib=barindex-$ObBearX[t]
lev0be=lowest[barsfib](low)
lev1be=$ObBearTop[t]
fibTotalbe=lev1be-lev0be
lev236be=lev0be+(fibTotalbe*0.236)
lev382be=lev0be+(fibTotalbe*0.382)
lev50be=lev0be+(fibTotalbe*0.500)
lev618be=lev0be+(fibTotalbe*0.618)
lev786be=lev0be+(fibTotalbe*0.786)
drawsegment($ObBearX[t],lev0be,$ObBearX2[t],lev0be)style(line)
drawsegment($ObBearX[t],lev1be,$ObBearX2[t],lev1be)style(line)
drawsegment($ObBearX[t],lev236be,$ObBearX2[t],lev236be)style(dottedline2)
drawsegment($ObBearX[t],lev382be,$ObBearX2[t],lev382be)style(dottedline2)
drawsegment($ObBearX[t],lev50be,$ObBearX2[t],lev50be)style(dottedline2,2)coloured("blue")
drawsegment($ObBearX[t],lev618be,$ObBearX2[t],lev618be)style(dottedline2,2)coloured("red")
drawsegment($ObBearX[t],lev786be,$ObBearX2[t],lev786be)style(dottedline2)
endif
endif
//--------------------------------------------------------//
//--------------------------------------------------------//
//--------------------------------------------------------//
//--------------------------------------------------------//
return