简体   繁体   English

将tradingview脚本转换为python3

[英]convert tradingview script into python3

I am looking for a converting from TV to python.我正在寻找从电视到 python 的转换。 Just a little code.只是一个小代码。 This is the code in tradingview:这是交易视图中的代码:

last_signal = 0
long_final = longCond and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == -1)
short_final = shortCond and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)

last_signal := long_final ? 1 : short_final ? -1 : last_signal[1]

for variable: -> longCond and shortCond, i have the right value (I compared between plot)对于变量:-> longCond 和 shortCond,我有正确的值(我在绘图之间进行了比较)

But for others, i have some differences (i think, because of last_signal)但对于其他人,我有一些差异(我认为,因为 last_signal)

this is my code in python:这是我在 python 中的代码:

  for x in range(0,len(mavi),1):
    last_signal[i] = 0
    if x == 0:
      longCond_tmp = 0
      shortCond_tmp  = 0
      last_signal_tmp  = 0
      short_final_tmp  = 0
      long_final_tmp  = 0

    else:
      if ((longCond_tmp and ((last_signal[i-1])) == 0) or ((last_signal[i-1]) == -1)):
        long_final_tmp = 1
      else:
        long_final_tmp = 0

      if ((shortCond_tmp and ((last_signal[i-1])) == 0) or ((last_signal[i-1]) == 1)):
        short_final_tmp = 1
      else:
        short_final_tmp = 0

      if long_final_tmp != 0:
        last_signal_tmp = 1
      else:
        if short_final_tmp != 0:
          last_signal_tmp = -1
        else:
          last_signal_tmp = last_signal[i-1]

    last_signal[i] += last_signal_tmp

Are there errors in my script in python?我的 python 中的脚本是否有错误?

Ok i found.好的,我找到了。 Just the number of "(" in只是“(”的数量

      if ((longCond_tmp and ((last_signal[i-1])) == 0) or ((last_signal[i-1]) == -1)):
    long_final_tmp = 1
  else:
    long_final_tmp = 0

  if ((shortCond_tmp and ((last_signal[i-1])) == 0) or ((last_signal[i-1]) == 1)):
    short_final_tmp = 1
  else:
    short_final_tmp = 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM