
この戦略は,上昇傾向を識別し,特定の条件を満たしたときにポジションをさらに開くために,SMAの斜率に基づいています. 同時に,選択可能な追跡ストップメカニズムが導入され,ストップ・ロスの価格を動的に調整することで利益を保護します. さらに,この戦略は,ストップ・ロスの後に再入場の条件を設定し,価格が高くなったときにポジションを再建するのを防ぐことができます. これらの機能により,この戦略は,上昇傾向を効果的に捕捉し,リスクを制御し,規律化された取引を実現します.
この戦略は,SMAのトレンド追跡,ストップトラッキング,規律的な再入場などのメカニズムを利用して,上昇傾向を捉えながらリスクを制御します.パラメータ設定の最適化,リスク管理の強化,二方向取引と多時間枠確認のサポートなどの方法により,戦略の適応性と健全性をさらに向上させることができます.
/*backtest
start: 2023-05-28 00:00:00
end: 2024-06-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("MA Incline Strategy with Optional Trailing Stop-Loss", overlay=true, calc_on_every_tick=true)
// Input parameters
windowSize = input.int(20, title="Window Size")
maLength = input.int(150, title="Moving Average Length")
minSlope = input.float(0.1, title="Minimum Slope")
useTrailingStop = input.bool(true, title="Use Trailing Stop-Loss")
trailingStopPercentage = input.float(2.8, title="Trailing Stop Percentage (%)") / 100
// Calculate the moving average
ma = ta.sma(close, maLength)
// Calculate the slope of the moving average over the window size
previousMa = ta.sma(close[windowSize], maLength)
slopeMa = (ma - previousMa) / windowSize
// Check conditions
isAboveMinSlope = slopeMa > minSlope
isAboveMa = close > ma
// Buy condition
buyCondition = isAboveMinSlope and isAboveMa
// Execute strategy
if (buyCondition and strategy.opentrades == 0)
strategy.entry("Long", strategy.long)
// Trailing stop-loss (optional)
if (strategy.opentrades == 1 and useTrailingStop and isAboveMa)
// Calculate the trailing stop price
trailPrice = close * (1 - trailingStopPercentage)
// Use the built-in strategy.exit function with the trailing stop
strategy.exit("Trail Stop", "Long", stop=trailPrice)
// Exit condition
sellCondition = ta.crossover(ma, close)
if (sellCondition and strategy.opentrades == 1)
strategy.close("Long")