我试图在一段时间的True循环中设置一个变量(不是全局变量,这不适用于我的线程)。
基本上,while循环运行,购买硬币,等待直到macd指示器变为绿色以表示准备出售如果变量名为“waitwait”且if语句将此设置为true。然后,我想要的功能是它一次又一次地循环使用该变量集,直到我收到macd down信号,并且当两个语句在sell“elif”语句中都为真时,我希望系统运行elif语句(同时“waitwait”设置为True。
代码很长,主要代码在这里的“runrun”def语句中: https://github.com/TheRoboKitten/ZenAii/blob/master/development2.py
以下是代码示例:
def runrun():
waitwait = False
print('Waitwait set to False before sell and waiting on macd up signal before sell.')
while True:
global sellstr
global buystr
global coincoin
global coin
global flag
btcc='BTC_'
coin= btcc + coincoin
word=coin
from poloniex import Poloniex
api = Poloniex(jsonNums=float)
df = Chart(api, word).dataFrame()
df.dropna(inplace=True)
data = (df.tail(2)[['macd']])
data1 = (df.tail(2)[['emasig']])
#Turn Data into a string
txt=str(data)
txt1=str(data1)
# search for floats in the returned data
re1='.*?' # Non-greedy match on filler
re2='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 1
re3='.*?' # Non-greedy match on filler
re4='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 2
rg = re.compile(re1+re2+re3+re4,re.IGNORECASE|re.DOTALL)
m = rg.search(txt)
re1='.*?' # Non-greedy match on filler
re2='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 1
re3='.*?' # Non-greedy match on filler
re4='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 2
rg = re.compile(re1+re2+re3+re4,re.IGNORECASE|re.DOTALL)
m1 = rg.search(txt1)
# Search for floats that are too small to trade decision on
re1='.*?' # Non-greedy match on filler
re2='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 1
re3='((?:[a-z][a-z0-9_]*))' # Variable Name 1
re4='([-+]\\d+)' # Integer Number 1
re5='.*?' # Non-greedy match on filler
re6='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 2
re7='((?:[a-z][a-z0-9_]*))' # Variable Name 2
re8='([-+]\\d+)' # Integer Number 2
rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8,re.IGNORECASE|re.DOTALL)
deny = rg.search(txt)
re1='.*?' # Non-greedy match on filler
re2='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 1
re3='((?:[a-z][a-z0-9_]*))' # Variable Name 1
re4='([-+]\\d+)' # Integer Number 1
re5='.*?' # Non-greedy match on filler
re6='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])' # Float 2
re7='((?:[a-z][a-z0-9_]*))' # Variable Name 2
re8='([-+]\\d+)' # Integer Number 2
rg = re.compile(re1+re2+re3+re4+re5+re6+re7+re8,re.IGNORECASE|re.DOTALL)
deny1 = rg.search(txt1)
# Two if statements to decide what will happen... buy/sell/deny trade on limited data
print(data)
print(data1)
if deny and deny1:
float1=deny.group(1) + deny.group(2) + deny.group(3)
float2=deny.group(4) + deny.group(5) + deny.group(6)
float3 = float(float1)
float4 = float(float2)
float5=deny1.group(1) + deny1.group(2) + deny1.group(3)
float6=deny1.group(4) + deny1.group(5) + deny1.group(6)
float7 = float(float5)
float8 = float(float6)
print(float3, float4, float7, float8)
# Calculate the difference in the two numbers
diff = Decimal(float(float7 - float3))
diff1 = Decimal(float(float8 - float4))
diffstr = str(diff)
diffstr1 = str(diff1)
diff4 = (diff1 - diff)
diff4str=str(diff4)
print(diffstr1)
print('Buying ' + word + ' on error correction loop.')
ke1=word.replace('BTC_', '')
ke3='-BTC'
ke8=ke1+ke3
buystr=ke8
buybuy()
# HERE DIFF 4 IS HISTOGRAM SIGNAL ON UPTREND. DIFF 1 IS ACTUAL MACD SIGNAL
if (Decimal(diff1) > 1):
waitwait = True
print('Waiting... MACD is on UP signal for: ' + word)
elif (Decimal(diff1) < 0)and (waitwait == True):
print(word)
print('Current macd hist diff is: ' + diff4str)
sellstr=ke8
print('Selling... MACD is on DOWN Signal for: ' + word)
sellsell()
break
else:
print(word)
print('Current macd diff is: ' + diff4str)
print('Waiting for MACD UP Signal for: ' + word)