
このピンスクリプト戦略は,比較的強い指数である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")