Advertisement
asytyi

Simple HV

Jan 28th, 2022 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. Settings=
  2. {
  3.     Name = "HV Example",
  4.     period = 8,
  5.     line =
  6.     {
  7.         {
  8.             Name = "HV",
  9.             Color = RGB(255, 0, 0),
  10.             Type = TYPE_LINE,
  11.             Width = 2
  12.         }
  13.     }
  14. }
  15.  
  16. function Init()
  17.     return 1
  18. end
  19.  
  20. function OnCalculate(index)
  21.     if index < Settings.period then
  22.         return nil
  23.     else
  24.         local start_index = index - Settings.period + 1
  25.        
  26.         local high = H(start_index)
  27.         local low = L(start_index)
  28.         local open = O(start_index)
  29.        
  30.         for i = start_index, index do
  31.             if H(i) > high then
  32.                 high = H(i)
  33.             end
  34.             if L(i) < low then
  35.                 low = L(i)
  36.             end
  37.         end
  38.        
  39.         return (high - low) / open * 16
  40.     end
  41. end
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement