--[[ средние на разных TF(15/60/D) одной длины индикатор позволяет сократить количество окон с разными таймфреймами --]] Settings= { Name = "SMA_mult_template_v3", -- indicator name D=200, -- period M60=200, M15=200, line= { { Name = "cur1", Type =TYPE_LINE, Width = 1, Color = RGB(0,0,255) }, { Name = "cur2", Type =TYPE_LINE, Width = 1, Color = RGB(0,0,255) }, { Name = "cur3", Type =TYPE_LINE, Width = 1, Color = RGB(0,0,255) } } } function Init() return 3 end function OnCalculate(index) lnd = Settings.D lnh = Settings.M60 ln = Settings.M15 if index == 1 then hour = {} day = {} sum = {} sma = {} n = {} sumh = {} smah = {} nh = {} nhi = {} sumd = {} smad = {} nd = {} ndi = {} sum[index] = O(index) n[index]=1 sumh[index] = O(index) nh[index]=1 nhi[index]=1 sumd[index] = O(index) nd[index]=1 ndi[index]=1 hour[index] = T(index).hour day[index] = T(index).day else if index > ln then sum[index] = sum[index-1] + O(index) sum[index] = sum[index] - O(index-ln) n[index] = n[index-1] else sum[index] = sum[index-1] + O(index) n[index] = n[index-1] + 1 end if hour[index-1] ~= T(index).hour then nh[index] = nh[index-1] + 1 nhi[nh[index]] = index if nh[index] > lnh then sumh[index] = sumh[index-1] + O(index)-O(nhi[nh[index]-lnh]) smah[index] = sumh[index]/lnh else sumh[index] = sumh[index-1] + O(index) smah[index] = nil end else nh[index] = nh[index-1] sumh[index] = sumh[index-1] smah[index] = smah[index-1] end if day[index-1] ~= T(index).day then nd[index] = nd[index-1] + 1 ndi[nd[index]] = index if nd[index] > lnd then sumd[index] = sumd[index-1] + O(index)-O(ndi[nd[index]-lnd]) smad[index] = sumd[index]/lnd else sumd[index] = sumd[index-1] + O(index) smad[index] = nil end else nd[index] = nd[index-1] sumd[index] = sumd[index-1] smad[index] = smad[index-1] end hour[index] = T(index).hour day[index] = T(index).day end if n[index] ~= 0 then sma[index] = sum[index]/n[index] end return sma[index], smah[index], smad[index] end