Maz

Triple RAFF Channel projection (On Price)

Category: Indicators By: Maz Created: February 10, 2017, 1:51 PM
February 10, 2017, 1:51 PM
Indicators
16 Comments
Triple RAFF Channel projection (On Price)

Triple Raff Channel linear projection indicator for PRT.

Premise

PRT implementation of the “Bianca” trends visualization of 3 linear regressions. This indicator adopts the Raff channel algorithm and outputs 3 sets of support and resistance lines on the same chart. These sets represent:

  • Primary trend (blue)
  • Secondary trend (green)
  • Tertiary trend (red)

Interpretation:

If all three sets of trend-lines align, a strong sentiment is established. This could be bullish, bearish or consolidating.

If tertiary trend and/or secondary trend are diverging from primary trend, or diverging from each other, a breakout of the wider trend is more probable.

If you are not familiar with this concept and associated trading systems, read up on raf channels and/or bianca trends.
http://stockcharts.com/school/doku.php?id=chart_school:chart_analysis:raff_regression_chan

Variables

Defaults are 50 bars (primary); 20 (secondary); 10 (tertiary). These can be changed by you.

Developer Information

  • The mid lines are not plotted but they are available of course. If you would like to view them or adapt further then use reg
  • Support and resistance lines are averaged from raff and riff lines. If you want to see both, replace averaging code (source code is commented)

Enjoy!

Maz

— code —

// Triple RAF Channel (Bianca) indicator for PRT
// Written by "Maz" at prorealcode.com
// Adopted from RAFF algorithm
// --

for i = 1 to 3

// Blue (Long term)
if i = 1 then
k   = blue
det = DPO[k*2](close)
if det=det[1] and det[1]=det[2] and det[2]<>det[3] then
flag = 1
endif
n      = (k*2)-4
p      = (n/2)-1
d100   = DPO[n](close)
moy100 = close-d100
co     = (moy100-moy100[1]+(close[p])/n)*n
h100   = dpo[n](high)
moyh   = high-h100
hi     = (moyh-moyh[1]+(high[p])/n)*n
l100   = dpo[n](low)
moyl   = low-l100
lo     = (moyl-moyl[1]+(low[p])/n)*n
if flag=1 and flag[1]=0 then
somx  = 0
somy  = 0
somxx = 0
somxy = 0
for i=1 to k
somx = somx+i
next
for i=0 to k-1
somy=somy+co[i]
next
for i=1 to k
somxx=somxx+(i*i)
next
for i=0 to k-1
somxy=somxy+(co[i]*(k-i))
next
a = (k*somxy-somx*somy)/(k*somxx-somx*somx)
b = (somy-a*somx)/k
for i=0 to k-1
ecah = hi[i]-a*(k-i)-b
maxh = max(maxh,ecah)
ecal = a*(k-i)+b-lo[i]
maxl = max(maxl,ecal)
next
endif
if flag=0 then
reg = undefined
else
j = j + 1
reg = a * j + b
endif

raffBlue  = max(maxh,maxl)
rafflBlue = reg-raffBlue
raffhBlue = reg+raffBlue

riffBlue  = min(maxh,maxl)
riffhBlue = reg+riffBlue
rifflBlue = reg-riffBlue

// (optional) - let's take an average of the riff and raff
BlueResistance = (raffhBlue + riffhBlue) / 2
BlueSupport    = (rafflBlue + rifflBlue) / 2


elsif i = 2 then // Green (Medium term)
k = green
Gdet = DPO[k*2](close)
if Gdet = Gdet[1] and Gdet[1] = Gdet[2] and Gdet[2] <> Gdet[3] then
Gflag = 1
endif
Gn      = (k*2)-4
Gp      = (Gn/2)-1
Gd100   = DPO[Gn](close)
Gmoy100 = close-Gd100
Gco     = (Gmoy100 - Gmoy100[1]+(close[Gp])/Gn)*Gn
Gh100   = dpo[Gn](high)
Gmoyh   = high-Gh100
Ghi     = (Gmoyh - Gmoyh[1]+(high[Gp])/Gn)*Gn
Gl100   = dpo[Gn](low)
Gmoyl   = low-Gl100
Glo     = (Gmoyl-Gmoyl[1]+(low[Gp])/Gn)*Gn
if Gflag = 1 and Gflag[1] = 0 then
Gsomx  = 0
Gsomy  = 0
Gsomxx = 0
Gsomxy = 0
for i = 1 to k
Gsomx = Gsomx+i
next
for i = 0 to k-1
Gsomy=Gsomy+Gco[i]
next
for i = 1 to k
Gsomxx=Gsomxx+(i*i)
next
for i = 0 to k-1
Gsomxy=Gsomxy+(Gco[i]*(k-i))
next
Ga = (k*Gsomxy-Gsomx*Gsomy)/(k*Gsomxx-Gsomx*Gsomx)
Gb = (Gsomy-Ga*Gsomx)/k
for i=0 to k-1
Gecah = Ghi[i]-Ga*(k-i)-Gb
Gmaxh = max(Gmaxh,Gecah)
Gecal = Ga*(k-i)+Gb-Glo[i]
Gmaxl = max(Gmaxl,Gecal)
next
endif
if Gflag = 0 then
Greg = undefined
else
Gj = Gj + 1
Greg = Ga * Gj + Gb
endif

raffGreen  = max(Gmaxh,Gmaxl)
rafflGreen = Greg-raffGreen
raffhGreen = Greg+raffGreen

riffGreen  = min(Gmaxh,Gmaxl)
riffhGreen = Greg+riffGreen
rifflGreen = Greg-riffGreen

// (optional) - let's take an average of the riff and raff
GreenResistance = (raffhGreen + riffhGreen) / 2
GreenSupport    = (rafflGreen + rifflGreen) / 2

elsif i = 3 then // Red (Short Term)
k = red
Rdet = DPO[k*2](close)
if Rdet = Rdet[1] and Rdet[1] = Rdet[2] and Rdet[2] <> Rdet[3] then
Rflag = 1
endif
Rn      = (k*2)-4
Rp      = (Rn/2)-1
Rd100   = DPO[Rn](close)
Rmoy100 = close-Rd100
Rco     = (Rmoy100 - Rmoy100[1]+(close[Rp])/Rn)*Rn
Rh100   = dpo[Rn](high)
Rmoyh   = high-Rh100
Rhi     = (Rmoyh - Rmoyh[1]+(high[Rp])/Rn)*Rn
Rl100   = dpo[Rn](low)
Rmoyl   = low-Rl100
Rlo     = (Rmoyl-Rmoyl[1]+(low[Rp])/Rn)*Rn
if Rflag = 1 and Rflag[1] = 0 then
Rsomx  = 0
Rsomy  = 0
Rsomxx = 0
Rsomxy = 0
for i = 1 to k
Rsomx = Rsomx+i
next
for i = 0 to k-1
Rsomy=Rsomy+Rco[i]
next
for i = 1 to k
Rsomxx=Rsomxx+(i*i)
next
for i = 0 to k-1
Rsomxy=Rsomxy+(Rco[i]*(k-i))
next
Ra = (k*Rsomxy-Rsomx*Rsomy)/(k*Rsomxx-Rsomx*Rsomx)
Rb = (Rsomy-Ra*Rsomx)/k
for i=0 to k-1
Recah = Rhi[i]-Ra*(k-i)-Rb
Rmaxh = max(Rmaxh,Recah)
Recal = Ra*(k-i)+Rb-Rlo[i]
Rmaxl = max(Rmaxl,Recal)
next
endif
if Rflag = 0 then
Rreg = undefined
else
Rj = Rj + 1
Rreg = Ra * Rj + Rb
endif

raffRed  = max(Rmaxh,Rmaxl)
rafflRed = Rreg-raffRed
raffhRed = Rreg+raffRed

riffRed  = min(Rmaxh,Rmaxl)
riffhRed = Rreg+riffRed
rifflRed = Rreg-riffRed

// (optional) - let's take an average of the riff and raff
RedResistance = (raffhRed + riffhRed) / 2
RedSupport    = (rafflRed + rifflRed) / 2
endif

next


return BlueSupport coloured (10, 10, 200) as "Blue Support", BlueResistance coloured (10, 10, 255) as "Blue Resistance" , GreenSupport coloured (10, 200, 10) as "Green Support", GreenResistance coloured (10, 255, 10) as "Green Resistance", RedSupport coloured (200, 10, 10) as "Red Support", RedResistance coloured (255, 10, 10) as "Red Resistance"

Download
Filename: Triple-RAFF-Channel-projection.itf
Downloads: 501
Maz
Maz Veteran
Quant fund manager; Founder of institutional HFT engine. Background in market making, arbitrage, machine learning, indicator & algo design. Affection for PRC community - good discussions here. Welcome anyone to reach out, see posts :-)
Author’s Profile

Comments

leederbyshire
2 years ago
#

Here's the link to alternative linear regression channel indicator Nicolas is referring to that works on v12 since v10.3 being discontinued if anyone struggling to find it. https://www.prorealcode.com/prorealtime-indicators/standard-deviation-standard-error-linear-regression-channel/

Maz
Maz
6 years ago
#

Hi all, firstly happy to know that this is helping you. I look into updating it for PRT11 when I get the chance. All the best

Lotech123
6 years ago
#

PLEASE, PLEASE someone modify the code of this special indicator for V 11. Thank you in keen anticipation

Nicolas
6 years ago
#

just use 3 times a linear regression channel code you will find in the library.

Moritz Müller
7 years ago
#

hi there, I just checked and I does not work for me anymore neither - unfortunately. would be great if somebody could point to the right direction how to adjust the code. Would be great if the code could be adjusted to work as a screener as well - as shephinc mentioned. thanks

jums
6 years ago
#

Hi, Can you make an update for PRT v11 ? Best Regards,

ggolfet
7 years ago
#

it seems it's not working anymore with prorealtime 11, anyone has the same problem?

Kris75
8 years ago
#

fantastic job btw

Kris75
8 years ago
#

Hi Maz, How could we translate this in a strategy?

Maz
Maz
9 years ago
#

With PRT it's not currently possible to extend lines into the future (right) via the scripting language

lebrinque
9 years ago
#

Does anyone know how to make the lines extended? Like having an option for right and left?

lebrinque
9 years ago
#

This is AWESOME! Thank you Maz!!

Maz
Maz
9 years ago
#

You're welcome, thanks

alf
alf
9 years ago
#

Hello,

How can i project it on the chart?

Now it is below amongst the other indicators..

Thankss:)

shephinc
10 years ago
#

Is there an easy way get a value returned from the indicator that says if the blue channel is heading up or down ?

larouedegann
10 years ago
#

blue = 50

green = 20

red = 10

than you

ProRealCode ProRealCode
Loading...