TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));…
- User
TR1:=MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW)); UP:=(HIGH+LOW)/2+MA(TR1,19)*2; DN:=(HIGH+LOW)/2-MA(TR1,19)2; L1:=REF(UP,BARSLAST(UP<=REF(UP,1))); L2:=LLV(UP,N1.5); LL:=IF(L2!=REF(L2,1) AND L1<REF(L1,1),L1,IF(L1=L2,L1,L2)); S1:=BARSLAST(CROSS(0.5,UP=LL))+1; S2:=CROSS(COUNT((CROSS(C,LL) OR CROSS(C,REF(LL,2))) AND UP>LL,S1),0.5); A6:=BARSLAST(S2); B6:=BARSLAST(CROSS(HHV(DN,A6+1),C)); BY:=CROSS(B6,A6); SL:=CROSS(A6,B6); BARSLAST表示上次成立到当前的周期数,从通达信语言改成python
- Assistant
import numpy as np
def TR1(HIGH, LOW, CLOSE): tr1 = np.maximum(np.maximum(HIGH - LOW, np.abs(CLOSE.shift(1) - HIGH)), np.abs(CLOSE.shift(1) - LOW)) return tr1
def UP(HIGH, LOW, CLOSE): tr1 = TR1(HIGH, LOW, CLOSE) up = (HIGH + LOW) / 2 + tr1.rolling(window=19).mean() * 2 return up
def DN(HIGH, LOW, CLOSE): tr1 = TR1(HIGH, LOW, CLOSE) dn = (HIGH + LOW) / 2 - tr1.rolling(window=19).mean() * 2 return dn
def L1(UP): l1 = UP.shift(UP[UP <= UP.shift(1)].index[-1]) return l1
def L2(UP, N): l2 = UP.rolling(window=(N * 1.5)).min() return l2
def LL(UP, L1, L2): ll = np.where((L2 != L2.shift(1)) & (L1 < L1.shift(1)), L1, np.where(L1 == L2, L1, L2)) return ll
def S1(UP, LL): s1 = (UP <= LL.shift(1)).astype(int).cumsum() + 1 return s1
def S2(C, LL, S1): condition = ((C > LL) | (C > LL.shift(2))).rolling(window=S1.max()).sum() > 0.5 s2 = np.where(condition.shift(1), 1, 0.5) return s2
def A6(S2): a6 = S2.index[-1] return a6
def B6(HIGH, LOW, C, A6): b6 = (HHV(DN(HIGH, LOW, C), A6+1) > C).sum() return b6
def BY(B6, A6): by = (B6 > A6).astype(int) return by
def SL(A6, B6): sl = (A6 > B6).astype(int) return sl
- User
File "strategy.py", line 58 price_diffs = [high - low, high - close.shift(), close.shift() - low]
TabError:inconsistent use of tabs and spaces in indentation这是什么意思
- Assistant
这个错误意味着在代码中使用了不一致的缩进方式,即有的地方使用了制表符(Tab),而有的地方使用了空格。Python要求在代码中只能使用一种缩进方式(推荐使用四个空格),不能混合使用。
为了解决这个问题,你可以检查代码中的缩进并将其统一为一种方式,例如将所有的制表符换成四个空格。
- User
price_diffs=[high-low,high-close.shift(1),close.shift(1)-low]这是什么意思
- Assistant
这行代码创建了一个名为
price_diffs的变量,它是一个包含三个元素的列表。这三个元素分别是high-low、high-close.shift(1)和close.shift(1)-low这三个表达式的结果。high - low表示当期的高点减去低点,得到的是价格范围。high - close.shift(1)表示当期的高点减去前一期的收盘价,得到的是当期的高点与前一期收盘价之间的价格差。close.shift(1) - low表示前一期的收盘价减去当期的低点,得到的是前一期收盘价与当期低点之间的价格差。这样,
price_diffs列表中的三个元素表示了当前周期内的价格范围、当前周期内的高点与前一周期收盘价的价格差以及前一周期收盘价与当前周期内的低点的价格差。 - User
2023-09-04 10:17:20 - ERROR
File "strategy.py", line 58 price_diffs=[high-low,high-close.shift(1),close.shift(1)-low]
TabError:inconsistent use of tabs and spaces in indentation怎么改
- Assistant
这个错误是由于代码中混合使用了制表符(Tab)和空格所导致的。为了解决这个问题,你可以将代码中的所有制表符重新替换为四个空格。
在文件 "strategy.py" 的第 58 行,你可以将代码修改为以下形式:
price_diffs = [high - low, high - close.shift(1), close.shift(1) - low]请注意,确保在
[high - low, high - close.shift(1), close.shift(1) - low]这行代码之前和之后的所有代码行缩进方式都一致,使用相同数量的空格。这样就能避免 "TabError: inconsistent use of tabs and spaces in indentation" 这个错误。 - User
true_range = pd.concat(price_diffs, axis=1)这句报错File "strategy.py", line 58 true_range = pd.concat(price_diffs, axis=1)
TabError:inconsistent use of tabs and spaces in indentation
- Assistant
同样的错误,这个错误是由于代码中混合使用了制表符(Tab)和空格所导致的。为了解决这个问题,你可以将代码中的所有制表符重新替换为四个空格。
在文件 "strategy.py" 的第 58 行,你可以将代码修改为以下形式:
true_range = pd.concat(price_diffs, axis=1)请注意,确保在
pd.concat(price_diffs, axis=1)这行代码之前和之后的所有代码行缩进方式都一致,使用相同数量的空格。这样就能避免 "TabError: inconsistent use of tabs and spaces in indentation" 这个错误。