Блог им. autotrade
Settings={ Name="STATDIVPROF", period=30, showprof=0, line= { { Name="curve", Color=RGB(0,0,255), Type=TYPE_LINE, Width=1 }, { Name="line", Color=RGB(255,0,0), Type=TYPE_LINE, Width=1 } } } function Init() prof=0 bp=0 prevval=0 return 2 end function OnCalculate(index) local sum1=0 local sum2=0 local j=0 local dprof=0 if index < Settings.period then return nil, nil else for i=index-Settings.period+1, index do j = j + 1 if C(i) > O(i) then sum1 = sum1 + (C(i) - O(i))*V(i)*j sum2 = sum2 + (C(i) - O(i))*V(i)*j else sum2 = sum2 + (O(i) - C(i))*V(i)*j end end sum1 = sum1/sum2 end if index > Settings.period+1 then if prevval < 0.5 and sum1 >= 0.5 then bp=C(index) end if prevval > 0.5 and sum1 <= 0.5 then if bp ~= 0 then prof=prof+C(index)-bp bp=0 end end if bp ~= 0 then dprof = C(index) - bp else dprof = 0 end end prevval=sum1 if Settings.showprof == 0 then return sum1, 0.5 end if Settings.showprof == 1 then return prof+dprof, nil end end