
この戦略は,線形回帰と波動率の指標を使用して,異なる市場の状態を識別し,購入または販売の条件を満たしたときに,戦略は,相応の多頭または空頭ポジションを確立する.同時に,この戦略は,市場の状況に応じてパラメータを最適化し,異なる市場環境に対応するために調整することを許可する.この戦略は,指数移動平均を取引信号を確認するための追加指標としても使用する.
この戦略は,線形回帰と波動率の指標を通して市場の状態を識別し,EMAを確認指標として使用し,適応力のある,論理的に明確な取引戦略を構築する.戦略の優点は,傾向と波動性を組み合わせ,パラメータの最適化を許容し,異なる市場環境に適用することにある.しかし,戦略には,パラメータ選択,震動市場およびブラック天気予報などのリスクがあり,実用的なアプリケーションで継続的に最適化および改善する必要がある.豊富な信号源,パラメータ選択の最適化,リスク管理措置の改善などの側面から,戦略の改善は,その安定性と収益性を向上させるために行うことができる.
/*backtest
start: 2023-05-22 00:00:00
end: 2024-05-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_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("Regime de Mercado com Regressão e Volatilidade Otimizado", overlay=true)
// Parâmetros para otimização
upperThreshold = input.float(1.0, title="Upper Threshold")
lowerThreshold = input.float(-1.0, title="Lower Threshold")
length = input.int(50, title="Length", minval=1)
// Indicadores de volatilidade
atrLength = input.int(14, title="ATR Length")
atrMult = input.float(2.0, title="ATR Multiplier")
atr = ta.atr(atrLength)
volatility = atr * atrMult
// Calculando a regressão linear usando função incorporada
intercept = ta.linreg(close, length, 0)
slope = ta.linreg(close, length, 1) - ta.linreg(close, length, 0)
// Sinal de compra e venda
buySignal = slope > upperThreshold and close > intercept + volatility
sellSignal = slope < lowerThreshold and close < intercept - volatility
// Entrando e saindo das posições
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)
// Indicadores adicionais para confirmação
emaFastLength = input.int(10, title="EMA Fast Length")
emaSlowLength = input.int(50, title="EMA Slow Length")
emaFast = ta.ema(close, emaFastLength)
emaSlow = ta.ema(close, emaSlowLength)
// Confirmando sinais com EMAs
if (buySignal and emaFast > emaSlow)
strategy.entry("Buy Confirmed", strategy.long)
if (sellSignal and emaFast < emaSlow)
strategy.entry("Sell Confirmed", strategy.short)
// Exibindo informações no gráfico
plot(slope, title="Slope", color=color.blue)
plot(intercept, title="Intercept", color=color.red)
plot(volatility, title="Volatility", color=color.green)
hline(upperThreshold, "Upper Threshold", color=color.green, linestyle=hline.style_dotted)
hline(lowerThreshold, "Lower Threshold", color=color.red, linestyle=hline.style_dotted)