The resource loading... loading...

Learn the PINE code, please ask what is the problem with the stop loss setting? Stop loss is not executed when retested, stop loss is executed when played, but subsequently does not open a straightforward, uninterrupted position according to the conditions.

Author: Fland, Created: 2024-10-22 05:50:32, Updated: 2024-10-22 05:51:23

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

// Parameter setting rsiPeriod is equal to 6 EmaPeriod is 54 buyLevel is equal to 30. positionSize is 0.02

// Calculate RSI and EMA rsiValue = ta.rsi ((close, rsiPeriod)) emaValue = ta.ema ((close, emaPeriod) is the value of the data.

// Purchase conditions: RSI below 30 BuySignal = ta.crossunder ((rsiValue, buyLevel))

// Selling conditions: price above the EMA 54 sellSignal = close > emaValue

// Record the opening price var float entryPrice = na

// Buying logic: just do more if (buySignal and strategy.position_size == 0) This is a list of all the different ways Strategy.entry is credited in the database. entryPrice := close // records the opening price at the time of purchase

// Stop loss logic: set the stop loss to 0.5% if (strategy.position_size > 0) stopLossPrice = entryPrice * 0.995 // 0.5% stop loss if (close <= stopLossPrice) strategy.close ((Buy button, comment=Stop Loss button) // Stop loss and closing position

// Equalization logic: Equalization when the price is above the EMA 54 if (strategy.position_size > 0 and sellSignal) strategy.close ((Buy button, comment=Take Profit button) // reached the condition of break even


More