问题描述
这是针对我的算法交易机器人,因为通过 api 接收的数据然后附加到列表的末尾,我将使用负索引,-1 是进入过去价格的最新价格
给定值列表
prices = [32,31,30,29,28,27,26,32,34]
for i in range(3,len(prices)):
#check first condition
if(prices[-1] > prices[i]):
# for this example we will take index[i] to be index[0],so this condition is true and executed
另一个包含不同值的列表
check_list = [28,25,24,23,30]
对于嵌套条件,我想检查价格 [-1] 和价格 [i] 之间的任何一个值是否小于 check_list 中的相同索引值。这是真的
prices[-5] < check_list[-5]
在我的策略中,我不知道索引 'i' 的值,但必须检查 [-1] 和 [i] 之间的任何一个值是否小于 Check_list 中的相同索引
解决方法
您可能需要编辑您的问题以明确您的问题所在。
但据我所知,
您可能想在 if(prices[-1] > prices[i]):
内使用循环
prices = [32,31,30,29,28,27,26,32,34]
check_list = [28,25,24,23,30]
for i in range(3,len(prices)):
#check first condition
if(prices[-1] > prices[i]):
for j in range(i,len(prices)): #This loop will start from the i index and will go till the end of the price list.
if check_list[j]> prices[j]: #This condition will check if the price in {price list} is less then the price in the {check_list} at same index
#further code
你在找这个吗?