//defparam drawonlastbaronly=true
//------------------------------------------------------------//
//------------------------------------------------------------//
prd = 5 //periods for pivot calculation
pivottype=1 //method to calculate pivots
ratio=2 // ratio reward/risk
tradetype=1 // 1= long trade / 0= short trade
//------------------------------------------------------------//
if pivottype then
src1 = low
src2 = high
else
src1 = min(open,close)
src2 = max(open,close)
endif
//------------------------------------------------------------//
/////pivots low
if src1 > src1[prd] and lowest[prd](src1) > src1[prd] and src1[prd] < lowest[prd](src1)[prd+1] then
$plow[z+1] = src1[prd]
$plowidx[z+1] = barindex[prd]
z=z+1
drawpoint(barindex[prd],src1[prd],2)coloured("red",100)
endif
/////pivots high
if src2 < src2[prd] and highest[prd](src2)<src2[prd] and src2[prd]>highest[prd](src2)[prd+1] then
$phigh[t+1]=src2[prd]
$phighidx[t+1]=barindex[prd]
t=t+1
drawpoint(barindex[prd],src2[prd],2)coloured("blue",100)
endif
//------------------------------------------------------------//
if islastbarupdate then
dist=abs($phigh[t]-$plow[z])
if tradetype then
TP=$phigh[t]+ratio*dist
drawsegment($phighidx[t],TP,barindex+10,TP)coloured("green")style(line,2)
drawsegment($plowidx[z],$plow[z],barindex+10,$plow[z])coloured("red")style(line,2)
drawsegment($phighidx[t],$phigh[t],barindex+10,$phigh[t])coloured("blue")style(dottedline,2)
else
TP=$plow[z]-ratio*dist
drawsegment($plowidx[z],TP,barindex+10,TP)coloured("green")style(line,2)
drawsegment($plowidx[z],$plow[z],barindex+10,$plow[z])coloured("blue")style(dottedline,2)
drawsegment($phighidx[t],$phigh[t],barindex+10,$phigh[t])coloured("red")style(line,2)
endif
endif
return