Блог им. autotrade

Новая версия индикатора на IMOEX 60 мин

Новая версия индикатора на IMOEX 60 мин
свободный доступ к исходникам в ТК
Новая версия индикатора на IMOEX 60 мин
--[[
SMA list template v1
--]]
Settings=              
        {                          
            Name = "SMA_list_magic_template_v3",   -- indicator name
			sign=0,			
            prf=0,				
            ln1=10,               -- period		
			ln2=20,               -- period					
			ln3=30,               -- period		
            ln4=40,               -- period		
			ln5=50,               -- period					
			ln6=60,               -- period				
			ln7=70,               -- period		
            ln8=80,               -- period		
			ln9=90,               -- period					
			ln10=100,               -- period					
			ln11=110,               -- period				
			ln12=120,               -- period					
			ln13=130,               -- period	
			ln14=140,               -- period					
			ln15=150,               -- period	
			ln16=160,               -- period					
			ln17=170,               -- period	
			ln18=180,               -- period					
			ln19=190,               -- period	
			ln20=200,               -- period				
            line=                                     
                {                               
                    {  
                        Name = "SMA_TEMPL",
                        Type =TYPE_LINE,
                        Width = 1,
                        Color = RGB(0,0,0)
                    },
                    {  
                        Name = "SMA_TEMPL",
                        Type =TYPE_LINE,
                        Width = 1,
                        Color = RGB(255,0,0)
                    },
					{  
                        Name = "cur3",
                        Type =TYPE_TRIANGLE_DOWN,
                        Width = 5,
                        Color = RGB(255, 0, 0)
                    },
					{  
                        Name = "cur4",
                        Type =TYPE_TRIANGLE_UP,
                        Width = 5,
                        Color = RGB(0, 0, 255)
                    }
                }
       }


function Init()
  sma = {{},{}}
  sum = {{},{}}
  ln = {}
  n = {}
  sumln = 0
  m = {}
  prof = {}    
  return 4
end

function GetSMA(index, num)

  if index == 1 then 
    if num == 1 then 
      ln[num] = Settings.ln1 		
	end 
    if num == 2 then 	
      ln[num] = Settings.ln2
	end 
	if num == 3 then 
      ln[num] = Settings.ln3     
	end 
    if num == 4 then 
      ln[num] = Settings.ln4 
	end 
    if num == 5 then 	
      ln[num] = Settings.ln5
	end 
	if num == 6 then 
      ln[num] = Settings.ln6     
	end 			
	if num == 7 then 
      ln[num] = Settings.ln7
	end 
    if num == 8 then 
      ln[num] = Settings.ln8 
	end 
    if num == 9 then 	
      ln[num] = Settings.ln9
	end 
	if num == 10 then 
      ln[num] = Settings.ln10     
	end 
	if num == 11 then 
      ln[num] = Settings.ln11 		
	end 
    if num == 12 then 	
      ln[num] = Settings.ln12
	end 
	if num == 13 then 
      ln[num] = Settings.ln13     
	end 
    if num == 14 then 
      ln[num] = Settings.ln14 
	end 
    if num == 15 then 	
      ln[num] = Settings.ln15
	end 
	if num == 16 then 
      ln[num] = Settings.ln16     
	end 			
	if num == 17 then 
      ln[num] = Settings.ln17
	end 
    if num == 18 then 
      ln[num] = Settings.ln18 
	end 
    if num == 19 then 	
      ln[num] = Settings.ln19
	end 
	if num == 20 then 
      ln[num] = Settings.ln20     
	end 	
	
	sumln = sumln + ln[num]
    
	sum[num] = {}
    sum[num][index] = O(index)
    n[num]=1
  else   
    if index > ln[num] then     
      sum[num][index] = sum[num][index-1] + O(index)
	  sum[num][index] = sum[num][index] - O(index-ln[num])
    else 
      sum[num][index] = sum[num][index-1] + O(index)
      n[num] = n[num] + 1	
    end 
  end 

  
  if n[num] ~= 0 then 
    if num == 1 then 
      sma[index] = {} 
	end   
    sma[index][num] = sum[num][index]/n[num]
  end  

  return sma[index][num]
  
end

function GetMagic(index, num)

  res = 0
  val = 0
  cnt = 3+num  
  if index > ln[num] then 
    val = sma[index][num]
    for i = 1, cnt do  
	  dw = 0
	  up = 0
	  if index-cnt > 5 then
	    if O(index) < O(index-1) and O(index-1) < O(index-2) then 
		  dw = O(index-1) - O(index)
		end 
	    if O(index) > O(index-1) and O(index-1) > O(index-2) then 
		  up = O(index) - O(index-1)
		end 		
	  end
	  val = val + (O(index) - O(index-ln[num]+i))/ln[num]
      if O(index) >= val or up*i + O(index) > val --[[or val >= sma[index][num]--]] then 
        res = res + (ln[num]/sumln)*(i/cnt) 	  
	  end 
      if O(index) < val or - dw*i + O(index) < val --[[or val < sma[index][num]--]] then 
        res = res - (ln[num]/sumln)*(i/cnt) 	  
	  end 	  
	end   
  end 
   
  return res
end

function OnCalculate(index)

  prof[index] = 0 
  
  GetSMA(index, 1)
  GetSMA(index, 2)
  GetSMA(index, 3)
  GetSMA(index, 4)
  GetSMA(index, 5)
  GetSMA(index, 6)  
  GetSMA(index, 7)
  GetSMA(index, 8)
  GetSMA(index, 9)
  GetSMA(index, 10)   
  GetSMA(index, 11)
  GetSMA(index, 12)
  GetSMA(index, 13)
  GetSMA(index, 14)
  GetSMA(index, 15)
  GetSMA(index, 16)  
  GetSMA(index, 17)
  GetSMA(index, 18)
  GetSMA(index, 19)
  GetSMA(index, 20)   
  
  m[index] = GetMagic(index, 1)
  m[index] = m[index] + GetMagic(index, 2)
  m[index] = m[index] + GetMagic(index, 3)
  m[index] = m[index] + GetMagic(index, 4)
  m[index] = m[index] + GetMagic(index, 5)
  m[index] = m[index] + GetMagic(index, 6)
  m[index] = m[index] + GetMagic(index, 7)
  m[index] = m[index] + GetMagic(index, 8)
  m[index] = m[index] + GetMagic(index, 9)
  m[index] = m[index] + GetMagic(index, 10)
  m[index] = m[index] + GetMagic(index, 11)
  m[index] = m[index] + GetMagic(index, 12)
  m[index] = m[index] + GetMagic(index, 13)
  m[index] = m[index] + GetMagic(index, 14)
  m[index] = m[index] + GetMagic(index, 15)
  m[index] = m[index] + GetMagic(index, 16)
  m[index] = m[index] + GetMagic(index, 17)
  m[index] = m[index] + GetMagic(index, 18)
  m[index] = m[index] + GetMagic(index, 19)
  m[index] = m[index] + GetMagic(index, 20)  
  
  --[[
  if index > 10 then 
    m[index] = (9*m[index]+8*m[index-1]+7*m[index-2]+6*m[index-3]+5*m[index-4]+4*m[index-5]+3*m[index-6]+2*m[index-7]+m[index-8])/45
  end
  --]]
  
  if index > 3 then 
    m[index] = (3*m[index]+2*m[index-1]+m[index-2])/6
  end  
  
  if index == Size() then   
    if Settings.sign == 1 then 
      for i = 2, Size() do 
	    if m[i] ~= nil and m[i-1] ~= nil then 
	      if 0 < m[i] and 0 >= m[i-1] then
	        SetValue(i, 4, O(i))	
	      else	  
	       if 0 > m[i] and 0 <= m[i-1] then
	         SetValue(i, 3, O(i))		
	       else
	         SetValue(i, 3, nil)	
	         SetValue(i, 4, nil)	
	       end 	  
	      end 
	    end 
      end 
    end;
  end;  
  
  
  if Settings.prf==1 then
  
    if prof[index-1] ~= nil and m[index-1] ~= nil and O(index-1) ~= nil then 
      if 0 <= m[index-1] then 
        prof[index] = prof[index-1] +	O(index) - O(index-1)  
	  end 
      if 0 > m[index-1] then 
        prof[index] = prof[index-1] +	O(index-1) - O(index)  
	  end 	
    end  
    
	return prof[index], nil, nil, nil 
  else   
    if Settings.sign == 0 then   
      return 0, m[index], nil, nil
    end 
  end     
   

end



★5

теги блога autotrade

....все тэги



UPDONW
Новый дизайн