Type/to search
1
Follow
0
Followers
Estou aprendendo código PINE. Quais são os problemas com a configuração de stop loss? O stop loss não é executado durante o backtesting, mas é executado durante a negociação real. No entanto, as orden...
Help
Created 2024-10-22 05:50:32  Updated 2024-10-22 05:51:23
 0
 765

//@version=5
strategy("RSI(6) Buy at 30, EMA(34) Sell with Stop Loss", overlay=true)

// Configuração de parâmetros
rsiPeriod = 6
emaPeriod = 54
buyLevel = 30
positionSize = 0.02

// Calcular RSI e EMA
rsiValue = ta.rsi(close, rsiPeriod)
emaValue = ta.ema(close, emaPeriod)

// Condições de compra: RSI abaixo de 30
buySignal = ta.crossunder(rsiValue, buyLevel)

// Condições de venda: preço acima da EMA 54
sellSignal = close > emaValue

// Registre o preço de abertura
var float entryPrice = na

// Comprar lógica: apenas faça mais
if (buySignal and strategy.position_size == 0)
strategy.entry("Buy", strategy.long, qty=positionSize)
entryPrice: = close // Regista o preço de abertura da posição no momento da compra

// Stop Loss Logic: Definição de Stop Loss em 0.5%
if (strategy.position_size > 0)
stopLossPrice = entryPrice * 0.995 // 0.5% Stop Loss
if (close <= stopLossPrice)
strategy.close (("Buy", comment="Stop Loss") // Cessar a perda de liquidez

// Lógica de equilíbrio: preço acima da EMA 54 equilíbrio
if (strategy.position_size > 0 and sellSignal)
strategy.close (("Buy", comment="Take Profit") // atingir a posição de equilíbrio

Related Recommendations
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)