Блог им. autotrade

Индикатор горизонтальные уровни

Индикатор горизонтальные уровни
канал с индикаторами
Индикатор горизонтальные уровни
--[[
вопросы к автору: https://t.me/autotrade_ru
параметры: 
Procent - процент зигзага 
--]]
Settings={
Name="ZIG_levels_Template_v4",
Procent=2,
mindelt=2,
    line=                                     
                {  
					{  
                        Name = "cur1",
                        Type =TYPE_LINE,
                        Width = 1,
                        Color = RGB(0,0, 0)
                    },
					{  
                        Name = "cur2",
                        Type =TYPE_LINE,
                        Width = 1,
                        Color = RGB(0,0, 0)
                    }
                }
}

function Init()
  
  y1 = nil
  y2 = nil
  x1 = 1
  x2 = 1
  
  lvs = {}
  lvsval = {}
  lvsi = {}
       
  return 2
  
end

function getlevels(index)

  uplvs = nil
  dwlvs = nil

  for i = 3, #lvsval  do
    if lvsval[i] > O(index) and lvsval[i-1] < O(index) and lvsval[i] > lvsval[i-1]*(1 + Settings.mindelt/100) then
	  uplvs = lvsval[i]
	  dwlvs = lvsval[i-1]	 
	  uplvsi = lvsi[i]
	  dwlvsi = lvsi[i-1]	  
      if lvsval[i-2] > O(index) and lvsval[i-1] < O(index) and lvsval[i-2] < lvsval[i] and lvsval[i-2] > lvsval[i-1]*(1 + Settings.mindelt/100) then
	    uplvs = lvsval[i-2]
	    dwlvs = lvsval[i-1]	
	    uplvsi = lvsi[i-2]
	    dwlvsi = lvsi[i-1]		
      end 		  	  
	end	
    if lvsval[i] < O(index) and lvsval[i-1] > O(index) and lvsval[i-1] > lvsval[i]*(1 + Settings.mindelt/100) then
	  uplvs = lvsval[i-1]
	  dwlvs = lvsval[i]	 
	  uplvsi = lvsi[i-1]
	  dwlvsi = lvsi[i]		  
      if lvsval[i-2] < O(index) and lvsval[i-1] > O(index) and lvsval[i-2] > lvsval[i] and lvsval[i-1] > lvsval[i-2]*(1 + Settings.mindelt/100) then
	    uplvs = lvsval[i-1]
	    dwlvs = lvsval[i-2]	
	    uplvsi = lvsi[i-1]
	    dwlvsi = lvsi[i-2]			
      end 		  
	end	

    if lvsval[i-2] > O(index) and lvsval[i] < O(index) and lvsval[i] > lvsval[i-1] and lvsval[i-2] > lvsval[i]*(1 + Settings.mindelt/100) then
	  uplvs = lvsval[i-2]
	  dwlvs = lvsval[i]	 
	  uplvsi = lvsi[i-2]
	  dwlvsi = lvsi[i]	  	  	  
	end	
    if lvsval[i-2] < O(index) and lvsval[i] > O(index) and lvsval[i] < lvsval[i-1] and lvsval[i] > lvsval[i-2]*(1 + Settings.mindelt/100) then
	  uplvs = lvsval[i]
	  dwlvs = lvsval[i-2]	 
	  uplvsi = lvsi[i]
	  dwlvsi = lvsi[i-2]	  	  	  
	end	
	
    if lvsval[i-2] < O(index) and lvsval[i] > O(index) and lvsval[i] > lvsval[i-1] and lvsval[i] > lvsval[i-2]*(1 + Settings.mindelt/100) then
	  uplvs = lvsval[i]
	  dwlvs = lvsval[i-2]	 
	  uplvsi = lvsi[i]
	  dwlvsi = lvsi[i-2]	  	  	  
	end	
    if lvsval[i-2] > O(index) and lvsval[i] < O(index) and lvsval[i] < lvsval[i-1] and lvsval[i-2] > lvsval[i]*(1 + Settings.mindelt/100) then
	  uplvs = lvsval[i-2]
	  dwlvs = lvsval[i]	 
	  uplvsi = lvsi[i-2]
	  dwlvsi = lvsi[i]	  	  	  
	end		
	
  end  
  
  return uplvs, dwlvs, uplvsi, dwlvsi

end

function OnCalculate(index)

  de = Settings.Procent

  vl = O(index)
  if index == 1 then 
	y1 = vl
    y2 = vl
	lvs[index] = 0	
  else   
    lvs[index] = lvs[index-1]
	  if O(index) > y1*(1+de/100) and y1 < y2 then 
		x2 = x1
		y2 = y1	
		x1 = index 
		y1 = O(index)	
        lvs[index] = lvs[index]+1		
		lvsval[lvs[index]] = y2
		lvsi[lvs[index]] = x2
	  else 
		if O(index) > y1 and y1 >= y2 
		then 
		  x1 = index 
		  y1 = O(index)	  			  
		end 		
	  end 	

				
	  if O(index) < y1*(1-de/100) and y1 > y2 then 
		x2 = x1
		y2 = y1
		x1 = index 
		y1 = O(index)	
        lvs[index] = lvs[index]+1		
		lvsval[lvs[index]] = y2
		lvsi[lvs[index]] = x2
	  else 
		if O(index) < y1 and y1 <= y2 
		then 
		  x1 = index 
		  y1 = O(index)	  			  
		end 		
	  end 		
  end 	
  --[[
  if index == Size() then 
    uplvs, dwlvs, uplvsi, dwlvsi = getlevels(index)
    for i = 1, index  do	          
	  SetValue(i, 1, nil)
	  SetValue(i, 2, nil)
    end  	
    for i = uplvsi, index  do	          
	  SetValue(i, 1, uplvs)
    end  
    for i = dwlvsi, index  do	          
	  SetValue(i, 2, dwlvs)
    end    	
  end --]]
  
  uplvs, dwlvs, uplvsi, dwlvsi = getlevels(index)
  
  return uplvs, dwlvs
 
  
end
★2
4 комментария
Вы бы назвали свой индикатор как-нибудь. Например: «сливастик» или «рубероид».
avatar
NOT A HAMSTER, нормальный
avatar
Сложно такие индикаторы без ООП писать?)
avatar
Replikant_mih, да там нужен навык, скриптовый язык простой но есть ньюансы как и в любом другом деле
avatar

теги блога autotrade

....все тэги



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