Question#1.
At bottom of program below i have:
(me.chartooverlaytext = "percent fit w/ r >= 80%:" & percent / 100). This label is now part of the
"price history" chart. The label remains when i delete my indicater?
question #2.
How to i re-gen the "price history" if i delete it?
'|*********************************************************************************
'|*** StockFinder RealCode Indicator - Version 5.0 www.worden.com
'|*** Indicator:linregslope
'|*** use linear regression to gen. variable lgth slopes in my own process
'|********************************************************************************
'|--- This indicator well Select the best fitting slopes.
'|--- It well test sloops from 30 days to 3 days by -1.
'|--- scaling: exponential plotstyle: line or bar paint: green & red
'=================================================================================
'*** data for: market array bars and size
Dim lowtstslp As Integer = 5 '*** min slope test
Dim maxnper As Integer = 30 '*** max slope test
Dim cof_r(maxnper+1) As Single
Dim cof_b(maxnper+1) As Single
Dim cof_m(maxnper+1) As Single
Dim cof_nper(maxnper+1) As Integer
Dim cof_bb(maxnper+1) As Integer
Dim cof_ee(maxnper+1) As Integer
'*** stats data for good fits
Dim stat_nper(price.Bar.count+1) As Integer
Dim stat_bb(price.Bar.count+1) As Integer
Dim stat_ee(price.Bar.count+1) As Integer
Dim stat_r(price.Bar.count+1) As Single
Dim stat_m(price.Bar.count+1) As Single
Dim stat_b(price.Bar.count+1) As Single
'*** bars
Dim y_datevalue(price.Bar.count+1) As Date
Dim y_value(price.Bar.count+1) As Single
'*** data for: table index
Dim x1 As Integer
Dim x2 As Integer
Dim x3 As Integer
Dim x4 As Integer
Dim x5 As Integer
Dim x6 As Integer
Dim x7 As Integer
Dim bb As Integer
Dim ee As Integer
'*** data For: linear regression slope calc.
Dim mex As Single
Dim mey As Single
Dim newy As Single
Dim xx As Single
Dim yy As Single
Dim xy As Single
Dim sumx As Single
Dim sumy As Single
Dim sumxy As Single
Dim sumsqx As Single
Dim sumsqy As Single
Dim m As Single
Dim b As Single
Dim rx As Single
Dim ry As Single
Dim r As Single
Dim ag1 As Single
Dim ag2 As Single
Dim ag3 As Single
Dim ag4 As Single
Dim ag5 As Single
Dim ag6 As Single
Dim pergodfit As Single
'*** debug
Dim tstcnt As Integer = 0
Dim nper As Integer
'*** save bar data for my close-price plot
For x1 = 0 To (price.Bar.count - 1)
y_datevalue(x1) = price.Bar.datevalue(x1)
y_value(x1) = price.Bar.value(x1)
Next x1
'--- skip bars 0 to "nper" to allow slope insert (if any).
'****************************************************************
x7 = 0 '*** store stats
x6 = 1 '*** store slope data in best fit table
nper = maxnper
ee = (price.Bar.count - 1) '*** apply slope to each bar
Do '--- bars loop; step thru bars current period to last.
bb = ee - (nper - 1) '*** "bb" = first point of slope
sumx = 0
sumy = 0
sumxy = 0
sumsqx = 0
sumsqy = 0
mex = 1 '*** count of x's is always = one unit of time
For x2 = bb To ee
mey = y_value(x2)
xx = mex * mex
yy = mey * mey
xy = mex * mey
sumx = sumx + mex
sumy = sumy + mey
sumxy = sumxy + xy
sumsqx = sumsqx + xx
sumsqy = sumsqy + yy
mex = mex + 1
Next x2
ag1 = nper * sumxy
ag2 = sumx * sumy
ag3 = nper * sumsqx
ag4 = sumx * sumx
ag5 = sumy * sumy
ag6 = nper * sumsqy
m = (ag1 - ag2) / (ag3 - ag4)
b = (sumy - (m * sumx)) / nper
rx = ag1 - ag2
ry = (ag3 - ag4) * (ag6 - ag5)
r = rx / math.Sqrt(ry)
r = math.abs(r)
cof_r(x6) = r
cof_b(x6) = b
cof_m(x6) = m
cof_nper(x6) = nper
cof_bb(x6) = bb
cof_ee(x6) = ee
x6 = x6 + 1
If nper > lowtstslp Then
nper = nper - 1
Else
For x3 = 2 To x6
If cof_r(x3) > cof_r(1)
cof_r(1) = cof_r(x3)
cof_b(1) = cof_b(x3)
cof_m(1) = cof_m(x3)
cof_bb(1) = cof_bb(x3)
cof_ee(1) = cof_ee(x3)
cof_nper(1) = cof_nper(x3)
End If
Next x3
r = cof_r(1)
b = cof_b(1)
m = cof_m(1)
bb = cof_bb(1)
ee = cof_ee(1)
nper = cof_nper(1)
mex = 1
For x4 = bb To ee
newy = b + (m * mex)
y_value(x4) = newy
mex = mex + 1
Next x4
stat_r(x7) = r
stat_m(x7) = m
stat_b(x7) = b
stat_nper(x7) = nper
stat_bb(x7) = bb
stat_ee(x7) = ee
x6 = 1
ee = bb - 1
nper = maxnper
x7 = x7 + 1
End If
If ee < (maxnper - 1) Then '*** test for end of bars loop
Exit Do
End If
Loop '*** end of bars loop
'*** sum up stats
x2 = 0
x3 = 0
For x1 = 1 To (x7 - 1)
If stat_r(x1) >= 0.80 Then
x2 = x2 + 1
Else
x3 = x3 + 1
End If
Next x1
x7 = (x2 / (x2 + x3)) * 10000
pergodfit = x7
For x5 = 0 To (price.Bar.count - 1)
MyBase.addtoOutput(y_datevalue(x5), y_value(x5))
Next x5
Me.chartoverlaytext = "Percent fit w/ R >= 80%: " & pergodfit / 100
'************** end of program ***********************************************
|