Всем привет. Мне надо переделать драйвер RSI под обычный скрипт, чтобы я его мог запустить в терминале, указав в коде нужную мне бумагу.
Пытался сам и с гуглом, но ничего не получилось(
Пытался сам и с гуглом, но ничего не получилось(
Код |
---|
Settings= { Name = "*trdrobot.ru_RSI", RSIPeriod = 14, RSIVType = "Close", PivotRight = 5, PivotLeft = 5, RangeMax = 60, RangeMin = 5, line = { { Name = "RSI", Color = RGB(96, 96,255), Type = TYPE_LINE, Width = 2 }, { Name = "Diver_Bull", Type = TYPET_BAR, Color = RGB(96, 255,96), Width = 2 }, { Name = "Diver_Bear", Type = TYPET_BAR, Color = RGB(255, 96,96), Width = 2 } } } local function Value(I,VType) local Out = nil if VType == "C" then --Close Out = C(I) elseif VType == "O" then --Open Out = O(I) elseif VType == "H" then --High Out = H(I) elseif VType == "L" then --Low Out = L(I) elseif VType == "V" then --Volume Out = V(I) elseif VType == "M" then --Median Out = H(I) if Out~=nil then Out = ((Out + L(I)) / 2) end elseif VType == "T" then --Typical Out = H(I) if Out~=nil then Out = ((Out + L(I) + C(I))/3) end elseif VType == "W" then --Weighted Out = H(I) if Out~=nil then Out = (Out+L(I)+O(I)+C(I))/4 end elseif VType == "D" then --Difference Out = H(I) if Out~=nil then Out = (Out - L(I)) end end return Out end local math_min=math.min local math_max=math.max function LVolF() local ind_l = 0 local rsipd = 14 local rsiVT = "C" local Up = 0 local Down = 0 local rsisma_U = {0,0} local rsisma_D = {0,0} local V_p = 0 local V_l = 0 local c_a={0} local pvtr=5 local pvtl=5 local pvts = 11 local rmax=60 local rmin=5 local u_a={{0,0},{0,0}} local d_a={{0,0},{0,0}} return function(ind,FSettings) local j=0 local i = 0 local a1,a2=0,0 if ind==1 then rsipd = (FSettings.RSIPeriod or 14) rsiVT = (string.upper(string.sub(FSettings.RSIVType,1,1)) or "C") pvtr = (FSettings.PivotRight or 5) pvtl = (FSettings.PivotLeft or 5) rmax = (FSettings.RangeMax or 60) rmin = (FSettings.RangeMin or 5) pvts=pvtr+pvtl+1 u_a={{0,0},{0,0}} d_a={{0,0},{0,0}} ind_l = 0 Up = 0 Down = 0 rsisma_U = {0,0} rsisma_D = {0,0} V_l = Value(1,rsiVT) if V_l==nil then V_l = 0 end V_p = V_l c_a = {0} return nil end if ind_l~=ind then ind_l=ind V_p = V_l rsisma_U[2],rsisma_D[2] = rsisma_U[1],rsisma_D[1] if ind>pvts then local ul,dl=c_a[ind-1],c_a[ind-1] local un,dn=ind-1,ind-1 local flu,fld=false,false for i = 2,pvts do if ul<c_a[ind-i] then ul=c_a[ind-i];un=ind-i end if dl>c_a[ind-i] then dl=c_a[ind-i];dn=ind-i end end if un==(ind-pvtr-1) then u_a[2][1],u_a[2][2]=u_a[1][1],u_a[1][2] u_a[1][1],u_a[1][2]=ul,un flu=true end if dn==(ind-pvtr-1) then d_a[2][1],d_a[2][2]=d_a[1][1],d_a[1][2] d_a[1][1],d_a[1][2]=dl,dn fld=true end if flu and u_a[2][2]>0 and C(u_a[1][2])~=nil and C(u_a[2][2])~=nil then i=u_a[1][2]-u_a[2][2] if i>=rmin and i<=rmax then a1=math_max(C(u_a[1][2]),O(u_a[1][2])) a2=math_max(C(u_a[2][2]),O(u_a[2][2])) if u_a[1][1]<u_a[2][1] and a1>a2 then for j=u_a[2][2],u_a[1][2] do SetValue(j,2,u_a[2][1]-(u_a[2][1]-u_a[1][1])*((j-u_a[2][2])/i)) end message(tostring(j,3,d_a[2][1]-(d_a[2][1]-d_a[1][1])*((j-d_a[2][2])/i))) os.execute("C:\\Users\\Admin\\Documents\\finbot\\venv\\Scripts\\python.exe C:\\Users\\Admin\\Documents\\finbot\\quik_lua\\message.py") end end end if fld and d_a[2][2]>0 and C(d_a[1][2])~=nil and C(d_a[2][2])~=nil then i=d_a[1][2]-d_a[2][2] if i>=rmin and i<=rmax then a1=math_min(C(d_a[1][2]),O(d_a[1][2])) a2=math_min(C(d_a[2][2]),O(d_a[2][2])) if d_a[1][1]>d_a[2][1] and a1<a2 then for j=d_a[2][2],d_a[1][2] do SetValue(j,3,d_a[2][1]-(d_a[2][1]-d_a[1][1])*((j-d_a[2][2])/i)) end message(j,3,d_a[2][1]-(d_a[2][1]-d_a[1][1])*((j-d_a[2][2])/i)) os.execute("C:\\Users\\Admin\\Documents\\finbot\\venv\\Scripts\\python.exe C:\\Users\\Admin\\Documents\\finbot\\quik_lua\\message.py") end end end end end V_l = Value(ind,rsiVT) if V_l==nil then V_l = V_p end if V_p < V_l then Up = V_l - V_p else Up = 0 end if V_p > V_l then Down = V_p - V_l else Down = 0 end rsisma_U[1]=(rsisma_U[2]*(rsipd-1)+Up)/rsipd rsisma_D[1]=(rsisma_D[2]*(rsipd-1)+Down)/rsipd if rsisma_D[1]==0 then c_a[ind]=0 else c_a[ind] = 100-100 / (1 + (rsisma_U[1] / rsisma_D[1])) end return c_a[ind],nil,nil end end function Init() lvol_f = LVolF() return 3 end function OnCalculate(index) return lvol_f(index,Settings) end |