tasarıma ekleyince...belli olsun diye kalınlık arttı...olasılık kısmı fusya oldu...saatlik tasarlanmış gibi oldu...
https://i.hizliresim.com/wf5p6x5.png
PHP Code:
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Predictive Ranges [LuxAlgo]", "*", overlay = true,max_boxes_count = 500, max_lines_count = 500, max_bars_back = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(200, 'Length', minval = 2)
mult = input.float(6., 'Factor', minval = 0, step = .5)
tf = input.timeframe('', 'Timeframe')
src = input(close, 'Source')
//-----------------------------------------------------------------------------}
//Function
//-----------------------------------------------------------------------------{
pred_ranges(length, mult)=>
var avg = src
var hold_atr = 0.
atr = nz(ta.atr(length)) * mult
avg := src - avg > atr ? avg + atr :
avg - src > atr ? avg - atr :
avg
hold_atr := avg != avg[1] ? atr / 2 : hold_atr
[avg + hold_atr * 2, avg + hold_atr, avg, avg - hold_atr, avg - hold_atr * 2]
//-----------------------------------------------------------------------------}
//Calculation
//-----------------------------------------------------------------------------{
[prR2
, prR1
, avg
, prS1
, prS2] = request.security(syminfo.tickerid, tf, pred_ranges(length, mult))
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot_pru2 = plot(prR2, 'Direnç2', avg != avg[1] ? na : #f2364600)
plot_pru1 = plot(prR1, 'Direnç1', avg != avg[1] ? na : #f2364600)
plot_pravg = plot(avg , 'Ortalama', avg != avg[1] ? na : #f1ce0b)
plot_prl1 = plot(prS1, 'Destek1', avg != avg[1] ? na : #08998100)
plot_prl2 = plot(prS2, 'Destek2', avg != avg[1] ? na : #08998100)
//Fills
fill(plot_pru2, plot_pru1, avg != avg[1] ? na : color.new(#f23645, 65))
fill(plot_prl1, plot_prl2, avg != avg[1] ? na : color.new(#089981, 65))
//-----------------------------------------------------------------------------}
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length11 = input(20)
src11 = input(close)
//------------------------------------------------------------------------------
//Signal moving average
//-----------------------------------------------------------------------------{
var ma = 0.
var os = 0.
target = ta.sma(src11, length11)
abs_diff = math.abs(target - target[1])
r2 = math.pow(ta.correlation(close, bar_index, length11), 2)
os := r2 > 0.5 ? math.sign(src11[1] - target[1]) : os
ma := r2 > 0.5 ? r2 * target + (1 - r2) * nz(ma[1], target)
: ma[1] - abs_diff * os
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plot0 = plot(src11, display = display.none, editable = false)
css = os == 1 ? #0cb51a : #ff1100
plot1 = plot(ma, 'Signal MA'
, css)
fill_css = src > ma ? color.new(#0cb51a, 80) : color.new(#ff1100, 80)
//fill(plot0, plot1, fill_css, 'Fill')
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
per = input.float(10., 'Threshold %', minval = 0, maxval = 100)
div = input.int(50, 'Resolution' , minval = 2, maxval = 500)
//tf = input.timeframe('', 'Intrabar TF')
//Colors
showSupply = input(true ,'Supply********', inline = 'supply', group = 'Style')
supplyCss = input(#2157f3, '' , inline = 'supply', group = 'Style')
supplyArea = input(false ,'Area' , inline = 'supply', group = 'Style')
supplyAvg = input(false ,'Average' , inline = 'supply', group = 'Style')
supplyWavg = input(true ,'Weighted' , inline = 'supply', group = 'Style')
showEqui = input(true ,'Equilibrium' , inline = 'equi' , group = 'Style')
equiCss = input(color.gray, '' , inline = 'equi' , group = 'Style')
equiAvg = input(false ,'Average' , inline = 'equi' , group = 'Style')
equiWavg = input(true ,'Weighted' , inline = 'equi' , group = 'Style')
showDemand = input(true ,'Demand****' , inline = 'demand', group = 'Style')
demandCss = input(#ff5d00, '' , inline = 'demand', group = 'Style')
demandArea = input(false ,'Area' , inline = 'demand', group = 'Style')
demandAvg = input(false ,'Average' , inline = 'demand', group = 'Style')
demandWavg = input(true ,'Weighted' , inline = 'demand', group = 'Style')
//-----------------------------------------------------------------------------}
//UDT's
//-----------------------------------------------------------------------------{
type bin
float lvl
float prev
float sum
float prev_sum
float csum
float avg
bool isreached
type area
box bx
line avg
line wavg
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
get_hlv()=> [high, low, volume]
method set_area(area id, x1, top, btm, avg, wavg, showArea, showAvg, showWavg)=>
if showArea
id.bx.set_lefttop(x1, top)
id.bx.set_rightbottom(n, btm)
if showAvg
id.avg.set_xy1(x1, avg)
id.avg.set_xy2(n, avg)
if showWavg
id.wavg.set_xy1(x1, wavg)
id.wavg.set_xy2(n, wavg)
//-----------------------------------------------------------------------------}
//Main variables
//-----------------------------------------------------------------------------{
var max = 0.
var min = 0.
var x1 = 0
var csum = 0.
var area supply_area = na
var area demand_area = na
//Intrabar data
[h, l, v] = request.security_lower_tf(syminfo.tickerid, tf, get_hlv())
//Accumulate
max := math.max(high[1], max)
min := math.min(low[1], min)
csum += volume[1]
//-----------------------------------------------------------------------------}
//Set zones
//-----------------------------------------------------------------------------{
var float supply_wavg = na
var float demand_wavg = na
if dayofmonth != dayofmonth[1]
r = (max - min) / div
supply = bin.new(max, max, 0, 0, 0, 0, false)
demand = bin.new(min, min, 0, 0, 0, 0, false)
//Loop trough intervals
for i = 0 to div-1
supply.lvl -= r
demand.lvl += r
//Loop trough bars
for j = 1 to (n - x1)-1
//Loop trough intrabars
for k = 0 to (v[j]).size()-1
//Accumulate if within upper internal
supply.sum += (h[j]).get(k) > supply.lvl and (h[j]).get(k) < supply.prev ? (v[j]).get(k) : 0
supply.avg += supply.lvl * (supply.sum - supply.prev_sum)
supply.csum += supply.sum - supply.prev_sum
supply.prev_sum := supply.sum
//Accumulate if within lower interval
demand.sum += (l[j]).get(k) < demand.lvl and (l[j]).get(k) > demand.prev ? (v[j]).get(k) : 0
demand.avg += demand.lvl * (demand.sum - demand.prev_sum)
demand.csum += demand.sum - demand.prev_sum
demand.prev_sum := demand.sum
//Test if supply accumulated volume exceed threshold and set box
if supply.sum / csum * 100 > per and not supply.isreached
avg = math.avg(max, supply.lvl)
supply_wavg := supply.avg / supply.csum
//Set Box/Level coordinates
if showSupply
supply_area := area.new(
box.new(na, na, na, na, na, bgcolor = color.new(supplyCss, 80))
, line.new(na, na, na, na, color = supplyCss)
, line.new(na, na, na, na, color = supplyCss, style = line.style_dashed))
supply_area.set_area(x1, max, supply.lvl, avg, supply_wavg, supplyArea, supplyAvg, supplyWavg)
supply.isreached := true
//Test if demand accumulated volume exceed threshold and set box
if demand.sum / csum * 100 > per and not demand.isreached and showDemand
avg = math.avg(min, demand.lvl)
demand_wavg := demand.avg / demand.csum
//Set Box/Level coordinates
if showDemand
demand_area := area.new(
box.new(na, na, na, na, na, bgcolor = color.new(demandCss, 80))
, line.new(na, na, na, na, color = demandCss)
, line.new(na, na, na, na, color = demandCss, style = line.style_dashed))
demand_area.set_area(x1, demand.lvl, min, avg, demand_wavg, demandArea, demandAvg, demandWavg)
demand.isreached := true
if supply.isreached and demand.isreached
break
supply.prev := supply.lvl
demand.prev := demand.lvl
max := high
min := low
csum := volume
x1 := n
if barstate.islast
if showSupply
supply_area.bx.set_right(n)
supply_area.avg.set_x2(n)
supply_area.wavg.set_x2(n)
if showDemand
demand_area.bx.set_right(n)
demand_area.avg.set_x2(n)
demand_area.wavg.set_x2(n)
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length22 = input(100)
incr = input(10, "Increment")
fast = input(10)
src22 = input(close)
//-----------------------------------------------------------------------------}
//Calculations
//-----------------------------------------------------------------------------{
var ma22 = 0.
var fma = 0.
var alpha = 0.
var k = 1 / incr
upper = ta.highest(length22)
lower = ta.lowest(length22)
init_ma = ta.sma(src22, length22)
cross = ta.cross(src22,ma22)
alpha := cross ? 2 / (length + 1)
: src22 > ma22 and upper > upper[1] ? alpha + k
: src22 < ma22 and lower < lower[1] ? alpha + k
: alpha
ma22 := nz(ma22[1] + alpha[1] * (src22 - ma22[1]), init_ma)
fma := nz(cross ? math.avg(src22, fma[1])
: src22 > ma22 ? math.max(src22, fma[1]) + (src22 - fma[1]) / fast
: math.min(src22, fma[1]) + (src22 - fma[1]) / fast,src22)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
css22 = fma > ma22 ? color.rgb(46, 245, 6) : color.red
plot122 = plot(ma22, "Converging MA"
, color = css22)
//-----------------------------------------------------------------------------}
//Settings
//-----------------------------------------------------------------------------{
length33 = input.int(70
, minval = 0)
extrapolate = input.int(10
, minval = 0)
degree = input.int(3, 'Polynomial Degree'
, minval = 0
, maxval = 8)
src33 = input(close)
lock = input(false, 'Lock Forecast')
//Style
up_css = input.color(#0cb51a, 'Upward Color'
, group = 'Style')
dn_css = input.color(#ff1100, 'Downward Color'
, group = 'Style')
ex_css = input.color(#ea00ff, 'Extrapolation Color'
, group = 'Style')
width = input(3, 'Width'
, group = 'Style')
//-----------------------------------------------------------------------------}
//Fill lines array
//-----------------------------------------------------------------------------{
var lines = array.new_line(0)
if barstate.isfirst
for i = -extrapolate to length33-1
array.push(lines, line.new(na, na, na, na))
//-----------------------------------------------------------------------------}
//Get design matrix & partially solve system
//-----------------------------------------------------------------------------{
n33 = bar_index
var design = matrix.new<float>(0, 0)
var response = matrix.new<float>(0, 0)
if barstate.isfirst
for i = 0 to degree
column = array.new_float(0)
for j = 0 to length33-1
array.push(column, math.pow(j,i))
matrix.add_col(design, i, column)
var a = matrix.inv(matrix.mult(matrix.transpose(design), design))
var b = matrix.mult(a, matrix.transpose(design))
//-----------------------------------------------------------------------------}
//Get response matrix and compute roling polynomial regression
//-----------------------------------------------------------------------------{
var pass = 1
var matrix<float> coefficients = na
var x = -extrapolate
var float forecast = na
if barstate.islast
if pass
prices = array.new_float(0)
for i = 0 to length33-1
array.push(prices, src33[i])
matrix.add_col(response, 0, prices)
coefficients := matrix.mult(b, response)
float y1 = na
idx = 0
for i = -extrapolate to length33-1
y2 = 0.
for j = 0 to degree
y2 += math.pow(i, j)*matrix.get(coefficients, j, 0)
if idx == 0
forecast := y2
//------------------------------------------------------------------
//Set lines
//------------------------------------------------------------------
css33 = y2 < y1 ? up_css : dn_css
get_line = array.get(lines, idx)
line.set_xy1(get_line, n - i + 1, y1)
line.set_xy2(get_line, n - i, y2)
line.set_color(get_line, i <= 0 ? ex_css : css33)
line.set_width(get_line, width)
y1 := y2
idx += 1
if lock
pass := 0
else
y2 = 0.
x -= 1
for j = 0 to degree
y2 += math.pow(x, j)*matrix.get(coefficients, j, 0)
forecast := y2
plot(pass == 0 ? forecast : na, 'Extrapolation'
, color = ex_css
, offset = extrapolate
, linewidth = width)
//-----------------------------------------------------------------------------}