Блог им. autotrade |Шаблон для индикатора Зизаг

Шаблон для индикатора Зизаг


--[[
параметры: 
Procent - процент зигзага 
--]]
Settings={
Name="ZIGZAG_Templ",
Procent=2,
    line=                                     
                {  
					{  
                        Name = "cur1",
                        Type =TYPE_LINE,
                        Width = 2,
                        Color = RGB(0,0, 0)
                    }				
                }
}

function Init()
  
  y1 = nil
  y2 = nil
  x1 = 1
  x2 = 1
       
  return 1
  
end

function OnCalculate(index)

  de = Settings.Procent

  vl = C(index)
  if index == 1 then 
	y1 = vl
    y2 = vl
  else   
	  if C(index) > y1*(1+de/100) and y1 < y2 then 
	    x2 = x1
	    y2 = y1	
	    x1 = index 
	    y1 = C(index)		
      else 
	    if C(index) > y1 and y1 >= y2 
		then 
	      x1 = index 
	      y1 = C(index)	  			  
	    end 		
	  end 	

	  	  		
	  if C(index) < y1*(1-de/100) and y1 > y2 then 
	    x2 = x1
	    y2 = y1
	    x1 = index 
	    y1 = C(index)				
      else 
	    if C(index) < y1 and y1 <= y2 
		then 
	      x1 = index 
	      y1 = C(index)	  			  
	    end 		
	  end 	
	  	  		
	end 	
  
  if x1 ~= index then 
    curfrom = x1
	curto = index
  else 
    curfrom = x2
	curto = x1
  end 

  if curto ~= curfrom and curfrom ~= nil and curto ~= nil then 
    if C(curto) ~= nil and C(curfrom) ~= nil then 
      k = (C(curto)- C(curfrom))/(curto- curfrom)  
      for i = curfrom, index  do
        curv = i*k + C(curto) - curto*k  		          
	    SetValue(i, 1, curv)
      end   	
	end 
  end 
  
  return vl
 
  
end

....все тэги
UPDONW
Новый дизайн