RicardoSantos

[RS]Average Advance and Decline Curved Lines V0

exponential curve linear regression , use falloff multiplier to control curve falloff strength.
Remove from Favorite Scripts Add to Favorite Scripts
study("[RS]AA&DCL.V0", overlay=true)
//  ||---   Inputs: 
tempname = input("text")
risingdecaymultiplier = (syminfo.mintick*input(30.000, type=float))
fallingdecaymultiplier = (syminfo.mintick*input(30.000, type=float))
marginmultiplier = input(10)
hidefallingline = input(false)
hiderisingline = input(false)
hidetopmargin = input(false)
hidebottommargin = input(false)
//  ||---   Get the decay averages for tops and bottoms.
topdecay = high >= nz(topdecay[1]) ? high : nz(topdecay[1]) - nz(fallingdecay[1])
botdecay = n < 10 ? low : low <= nz(botdecay[1]) ? low : nz(botdecay[1]) + nz(risingdecay[1])
//  ||---   Counters for decay
falloffmultiplier = input(1.1)

fallingdecaycounter = topdecay < topdecay[1] ? nz(fallingdecaycounter[1]) * sqrt(falloffmultiplier) : falloffmultiplier
risingdecaycounter = botdecay > botdecay[1] ? nz(risingdecaycounter[1]) * sqrt(falloffmultiplier) : falloffmultiplier

fallingdecay = (fallingdecaymultiplier * fallingdecaycounter)// * avgdecaymultiplier
risingdecay = (risingdecaymultiplier * risingdecaycounter)// * avgdecaymultiplier

//topdecay2 = topdecay - fallingdecay
//botdecay2 = botdecay + risingdecay
//  ||---   Get the margin for entry
tmargin = topdecay - (fallingdecaymultiplier*marginmultiplier)
bmargin = botdecay + (risingdecaymultiplier*marginmultiplier)
//  ||---   Detect if price is in challenge zone or outside(trending/breakout)
breakoutup = close > bmargin ? true : false
breakoutdown = close < tmargin ? true : false
//  ||---   Color Switchs:
topdecaycolor = breakoutdown ? topdecay < topdecay[1] and topdecay >= high ? maroon : na : topdecay < topdecay[1] and topdecay >= high ? gray : na
botdecaycolor = breakoutup ? botdecay > botdecay[1] and botdecay <= low ? green : na : botdecay > botdecay[1] and botdecay <= low ? gray : na
//  ||---   Outputs:
plot(hidefallingline ? na : topdecay, color=topdecaycolor, style=linebr, linewidth=2, join=true)
plot(hiderisingline ? na : botdecay, color=botdecaycolor, style=linebr, linewidth=2, join=true)
//plot(topdecay+fallingdecaymultiplier, color=topdecaycolor, style=circles, linewidth=2)
//plot(botdecay-risingdecaymultiplier, color=botdecaycolor, style=circles, linewidth=2)
plot(hidetopmargin ? na : tmargin, color=topdecaycolor, style=linebr, linewidth=1, join=true)
plot(hidebottommargin ? na : bmargin, color=botdecaycolor, style=linebr, linewidth=1, join=true)

Comments

This is great! Is it possible to extend the lines similar to automatic trendlines that use circles?
Reply
Secksy, Thanks
Reply
Absolutely fantastic work here Ricardo. Will be studying this in detail - thankyou for sharing!
Reply
Just have to give you kudos -- really clever programming here! Well done :D
Reply
RicardoSantos SPYderCrusher
thx :)
Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Ideas Published Followers Following Private Messages Chat Sign Out