//@version=5 strategy(“RSI(6) Buy at 30, EMA(34) Sell with Stop Loss”, overlay=true)
参数設定 rsiPeriod = 6 emaPeriod = 54 buyLevel = 30 positionSize = 0.02
EMAとRSIを計算する rsiValue = ta.rsi(close, rsiPeriod) emaValue = ta.ema(close, emaPeriod)
RSIが30未満で buySignal = ta.crossunder(rsiValue, buyLevel)
EMA 54より高い価格で販売する sellSignal = close > emaValue
オープン価格を記録する var float entryPrice = na
買ってやる 論理は”多めにやる” if (buySignal and strategy.position_size == 0) strategy.entry(“Buy”, strategy.long, qty=positionSize) entryPrice:= close // 購入時の開設価格を記録する
// ストップ・ロジック: ストップ・ロジックを0.5%に設定する if (strategy.position_size > 0) stopLossPrice = エントリープライス * 0.995 // 0.5% ストップロスト if (close <= stopLossPrice) strategy.close (((“Buy”, comment=“Stop Loss”) // ストップ・ローズをクローズする
//平仓論理:価格が54のEMAより高いときの平仓 if (strategy.position_size > 0 and sellSignal) strategy.close ((“Buy”, comment=“Take Profit”) //条件平仓に達した