![]() RSI 和 SuperTrend 指標是我們擁有的最強大的技術工具之一,因此將它們結合起來可以獲利豐厚。 本文討論了一種依賴于這兩個指標的常見策略。 RSIRSI 無疑是最著名的動量指標,這是意料之中的,因為它具有許多優(yōu)勢,尤其是在區(qū)間市場中。 它也被限制在 0 到 100 之間,這使得它更容易解釋。 此外,它的知名度有助于發(fā)揮其潛力。這是因為越多的交易者和投資組合經(jīng)理關注 RSI,就會有越多的人根據(jù)其信號做出反應,這反過來會推高市場價格。 當然,我們無法證明這個想法,但它是直觀的,因為技術分析的基礎之一是它是自我實現(xiàn)的。 RSI 是使用一種相當簡單的方法計算的。 我們首先從一個時期的價格差異開始。 這意味著我們必須從之前的收盤價中減去每個收盤價。 然后,我們將計算正差異的平滑平均值并將其除以負差異的平滑平均值。 最后的計算為我們提供了相對強度,然后將其用于 RSI 公式中以轉(zhuǎn)換為 0 到 100 之間的度量。 ![]() 要計算相對強度指數(shù),我們需要一個 OHLC 數(shù)組(不是dataframe)。 這意味著我們將查看一個包含 4 列的數(shù)組。 因此,相對強度指數(shù)的函數(shù)是: def adder(Data, times): for i in range(1, times + 1): new = np.zeros((len(Data), 1), dtype = float) Data = np.append(Data, new, axis = 1) return Data
def jump(Data, jump): Data = Data[jump:, ] return Data
def ema(Data, alpha, lookback, what, where): alpha = alpha / (lookback + 1.0) beta = 1 - alpha # First value is a simple SMA Data = ma(Data, lookback, what, where) # Calculating first EMA Data[lookback + 1, where] = (Data[lookback + 1, what] * alpha) + (Data[lookback, where] * beta) # Calculating the rest of EMA for i in range(lookback + 2, len(Data)): try: Data[i, where] = (Data[i, what] * alpha) + (Data[i - 1, where] * beta) except IndexError: pass return Data
![]() 查看我的每周市場情緒報告,了解當前的定位,并通過并存的復雜和簡單模型來估計幾個主要市場的未來方向。 通過此鏈接了解有關該報告的更多信息,該鏈接涵蓋了 2022 年 7 月 8 日至 2022 年 8 月 14 日之間的分析: 超級趨勢指標在創(chuàng)建 SuperTrend 指標之前,我們應該了解的第一個概念是波動率。 我們有時使用平均真實范圍來衡量波動率。 雖然 ATR 被認為是一個滯后指標,但它提供了一些關于當前波動率和上一時期波動率(日、周、月等)的見解。 但在此之前,我們應該了解 True Range 是如何計算的(ATR 只是該計算的平均值)。 真實范圍只是三個價格差異中最大的一個:
一旦我們從上述三個中獲得最大值,我們只需取真實范圍的 n 個周期的平均值來獲得平均真實范圍。 一般來說,由于在恐慌和價格貶值期間我們看到波動性上升,因此 ATR 在這些時期很可能會走高,同樣在穩(wěn)定的上升趨勢或下降趨勢中,ATR 會趨于走低。 人們應該永遠記住,這個指標是滯后的,因此必須格外小心地使用。 下面是計算 ATR 的函數(shù)代碼。 確保您有一個 OHLC 歷史數(shù)據(jù)數(shù)組。 def adder(Data, times): for i in range(1, times + 1): new = np.zeros((len(Data), 1), dtype = float) Data = np.append(Data, new, axis = 1) return Data
def jump(Data, jump): Data = Data[jump:, ] return Data
def ema(Data, alpha, lookback, what, where): alpha = alpha / (lookback + 1.0) beta = 1 - alpha # First value is a simple SMA Data = ma(Data, lookback, what, where) # Calculating first EMA Data[lookback + 1, where] = (Data[lookback + 1, what] * alpha) + (Data[lookback, where] * beta) # Calculating the rest of EMA for i in range(lookback + 2, len(Data)): try: Data[i, where] = (Data[i, what] * alpha) + (Data[i - 1, where] * beta) except IndexError: pass return Data
![]() 現(xiàn)在我們已經(jīng)了解了 ATR 是什么以及如何計算它,我們可以進一步使用 SuperTrend 指標。 該指標旨在為趨勢追隨者提供進入和退出水平。 您可以將其視為移動平均線或 MACD。 它的獨特性是它的主要優(yōu)勢,雖然它的計算方法比其他兩個指標復雜得多,但本質(zhì)上是直觀的,并不難理解。 基本上,我們有兩個變量可供選擇。 ATR 回顧和乘數(shù)的值。 前者只是用于計算 ATR 的周期,而后者通常是一個整數(shù)(通常為 2 或 3)。 ![]() 首先要做的是計算價格柱的最高點和最低點的平均值,然后我們將加上或減去所選乘數(shù)乘以 ATR 的平均值,如上面的公式所示。 這將為我們提供兩個數(shù)組,基本上波段和基本下波段,它們構成了 SuperTrend 指標的第一個構建塊。 下一步是使用以下公式計算最終的上頻帶和最終的下頻帶。 ![]() ![]() 它可能看起來很復雜,但其中大部分條件都是重復的,無論如何,我將在下面提供 Python 代碼,以便您可以使用該函數(shù)并根據(jù)您的交易偏好對其進行優(yōu)化。 最后,使用前面的兩個計算,我們可以找到 SuperTrend。 ![]() def supertrend(Data, multiplier, atr_col, close, high, low, where): Data = adder(Data, 6) for i in range(len(Data)): # Average Price Data[i, where] = (Data[i, high] + Data[i, low]) / 2 # Basic Upper Band Data[i, where + 1] = Data[i, where] + (multiplier * Data[i, atr_col]) # Lower Upper Band Data[i, where + 2] = Data[i, where] - (multiplier * Data[i, atr_col]) # Final Upper Band for i in range(len(Data)): if i == 0: Data[i, where + 3] = 0 else: if (Data[i, where + 1] < Data[i - 1, where + 3]) or (Data[i - 1, close] > Data[i - 1, where + 3]): Data[i, where + 3] = Data[i, where + 1] else: Data[i, where + 3] = Data[i - 1, where + 3] # Final Lower Band for i in range(len(Data)): if i == 0: Data[i, where + 4] = 0 else: if (Data[i, where + 2] > Data[i - 1, where + 4]) or (Data[i - 1, close] < Data[i - 1, where + 4]): Data[i, where + 4] = Data[i, where + 2] else: Data[i, where + 4] = Data[i - 1, where + 4] # SuperTrend for i in range(len(Data)): if i == 0: Data[i, where + 5] = 0 elif (Data[i - 1, where + 5] == Data[i - 1, where + 3]) and (Data[i, close] <= Data[i, where + 3]): Data[i, where + 5] = Data[i, where + 3] elif (Data[i - 1, where + 5] == Data[i - 1, where + 3]) and (Data[i, close] > Data[i, where + 3]): Data[i, where + 5] = Data[i, where + 4] elif (Data[i - 1, where + 5] == Data[i - 1, where + 4]) and (Data[i, close] >= Data[i, where + 4]): Data[i, where + 5] = Data[i, where + 4] elif (Data[i - 1, where + 5] == Data[i - 1, where + 4]) and (Data[i, close] < Data[i, where + 4]): Data[i, where + 5] = Data[i, where + 3] # Cleaning columns Data = deleter(Data, where, 5) return Data ![]() 上圖顯示了具有 10 個周期的超級趨勢(由 ATR 周期表示)和 1.25 乘數(shù)的 EURUSD 的每小時值。 我們應該理解該指標的方式是,當它高于市場價格時,我們應該尋求做空,當它低于市場價格時,我們應該尋求做多,因為我們預期牛市趨勢。 請記住,SuperTrend 是趨勢跟蹤指標。 這里的目的是在開始時捕捉趨勢,并在趨勢結束時關閉。 ![]() 制定和評估戰(zhàn)略現(xiàn)在,我們的工作是擁有一個包含 OHLC 數(shù)據(jù)的數(shù)組,以及 RSI 和 SuperTrend 的列。 我們可以通過遵循此代碼來做到這一點,我們已經(jīng)導入了必要的歷史數(shù)據(jù)。
# Adding a few columnsmy_data = adder(my_data, 10)
# Calling the ATR function to be used in the SuperTrendmy_data = atr(my_data, lookback_supertrend, 1, 2, 3, 5, genre = 'Smoothed')
![]() 該策略基于 SuperTrend 的翻轉(zhuǎn),條件是 RSI 高于其 50% 的中性水平。 這強化了看漲偏見,反之亦然。
![]() def signal(Data, close, rsi_column, supertrend_column, buy, sell): Data = adder(Data, 10) for i in range(len(Data)): if Data[i, rsi_column] > 50 and Data[i, close] > Data[i, supertrend_column] and Data[i - 1, close] < Data[i - 1, supertrend_column]: Data[i, buy] = 1 elif Data[i, rsi_column] < 50 and Data[i, close] < Data[i, supertrend_column] and Data[i - 1, close] > Data[i - 1, supertrend_column]: Data[i, sell] = -1 return Data 默認形式的策略不太可能提供有價值的信號,必須進行調(diào)整以捕獲更好的信號。 也許進一步的研究可能會顯示出更好的信號? ![]() |
|