
이 파인 스크립트 전략은 상대적으로 약한 지수 RSI와 가격의 변동률 표준차 DEV를 기반으로 가격과 상하 궤도를 비교하여 진입점을 판단하며, RSI를 보조 필터링 지표로 사용하며, 가격이 상하 궤도에 도달하고 RSI가 초과 오버셀 영역에 도달하면 포지션 개시 신호를 발생시키고, 가격이 역으로 외출 궤도를 돌파하거나 RSI가 역으로 초과 오버셀 영역에 도달하면 포지션을 평정합니다. 이 전략은 시장의 변동 상황에 따라 동적으로 조정할 수 있으며, 변동률이 높을 때 손실을 감수하고, 변동률이 낮을 때 포지션을 취득합니다.
이 전략은 변동률 채널과 상대적으로 강한 지수를 결합하여 가격 변동과 동시에 RSI 지표를 참조하여 평형 입장을 판단하여 단계적 추세를 더 잘 파악하고 적시에 중단 및 수익을 얻을 수 있습니다. 그러나 전략의 성능은 파라미터 설정에 민감하며, 다양한 시장 환경과 지표의 자산에 대해 최적화가 필요하며, 다른 지표의 시장 추세에 대한 보조 판단을 도입하는 것을 고려하여 전략의 장점을 최대한 활용 할 수 있습니다.
/*backtest
start: 2024-05-20 00:00:00
end: 2024-05-27 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tmalvao
//@version=5
strategy("Estratégia de Desvio Padrão com RSI", overlay=true, margin_long=100, margin_short=100)
// Parâmetros
length = input.int(20, title="Período do Desvio Padrão")
thresholdEntry = input.float(1.5, title="Limite de Entrada")
thresholdExit = input.float(0.5, title="Limite de Saída")
rsiLength = input.int(14, title="Período do RSI")
rsiOverbought = input.int(70, title="RSI Overbought")
rsiOversold = input.int(30, title="RSI Oversold")
// Cálculo do Desvio Padrão
price = close
stdDev = ta.stdev(price, length)
// Média Móvel Simples
sma = ta.sma(price, length)
// Limites baseados no Desvio Padrão
upperLimit = sma + thresholdEntry * stdDev
lowerLimit = sma - thresholdEntry * stdDev
exitUpperLimit = sma + thresholdExit * stdDev
exitLowerLimit = sma - thresholdExit * stdDev
// Cálculo do RSI
rsi = ta.rsi(price, rsiLength)
// Condições de Entrada com RSI
longCondition = ta.crossover(price, lowerLimit) and rsi < rsiOversold
shortCondition = ta.crossunder(price, upperLimit) and rsi > rsiOverbought
// Condições de Saída com RSI
exitLongCondition = ta.crossunder(price, exitLowerLimit) or rsi > rsiOverbought
exitShortCondition = ta.crossover(price, exitUpperLimit) or rsi < rsiOversold
// Plotar Linhas
plot(upperLimit, color=color.red, title="Limite Superior")
plot(lowerLimit, color=color.green, title="Limite Inferior")
plot(exitUpperLimit, color=color.orange, title="Limite de Saída Superior")
plot(exitLowerLimit, color=color.blue, title="Limite de Saída Inferior")
plot(sma, color=color.gray, title="SMA")
hline(rsiOverbought, "RSI Overbought", color=color.red)
hline(rsiOversold, "RSI Oversold", color=color.green)
plot(rsi, title="RSI", color=color.purple)
// Estratégia de Trade
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
if (exitLongCondition)
strategy.close("Long")
if (exitShortCondition)
strategy.close("Short")