Избранное трейдера Kerby
# Created by SciFi, 2016 runUnluck <- function(n) { runArray <- numeric(10000) for(i in 1:10000) { runArray[i] <- sum(rle(sample(c(-1, 1), 1000, TRUE))$lengths == n) } hist(runArray, main="Гистограмма") mean(runArray) }
> source("D:\\Dropbox\\R\\RunUnluck.r") > runUnluck(6) [1] 7.8161 > runUnluck(2) [1] 125.2208 > runUnluck(3) [1] 62.4047 > runUnluck(4) [1] 31.179 > runUnluck(5) [1] 15.6559 > runUnluck(6) [1] 7.7635 > runUnluck(7) [1] 3.8831 > runUnluck(8) [1] 1.9382 > runUnluck(9) [1] 0.9738 > runUnluck(10) [1] 0.4922
Settings={ Name = "Fractal_Chennal", period=5, line={ { Name = "Level_High", Type =TYPE_LINE,-- = LINE --линии = DASH -- тире = POINT -- точки Width = 1, Color = RGB(0,255, 0)--green }, { Name = "Level_Low", Type =TYPE_LINE, Width = 1, Color = RGB(255,0,0)--root }}} idx_prosl=0 function Init() return 2 end function OnCalculate(idx) if idx==1 then P = math.floor(Settings.period/2)*2+1 message("Код бумаги: "..getDataSourceInfo().sec_code.." ; период индикатора: "..P,1) t_H,t_L={},{} end if idx~=nil and idx>P then if idx_prosl~=idx then local l=idx-P for l=l,idx-1 do t_H[l]=H(l) t_L[l]=L(l) end if t_H[#t_H-(P-1)/2]==math.max(unpack(t_H,#t_H-P+1,#t_H)) then H_ind_value=t_H[#t_H-(P-1)/2] end if t_L[#t_L-(P-1)/2]==math.min(unpack(t_L,#t_L-P+1,#t_L)) then L_ind_value=t_L[#t_L-(P-1)/2] end end else H_ind_value=nil L_ind_value=nil end idx_prosl=idx return H_ind_value, L_ind_value endКак пользоваться: