
この戦略は,2つの移動平均線の交差を利用して市場動向を判断し,短期移動平均線に長期移動平均線を穿越したときに多ポジションを開き,逆に空いている.同時に,この戦略は,価格が想定された利益レベルに達したときに,分量的にポジションを平らにして,それによって利益を最大化し,リスクをコントロールする.
この戦略の核心は,異なる周期の移動平均を利用して市場トレンドを捉えることである.短期移動平均の上部に長期移動平均を穿越すると,市場は上昇傾向に突入する可能性があることを意味し,このとき多ポジションを開く.短期移動平均の下部に長期移動平均を穿越すると,市場は下部傾向に突入する可能性があることを意味し,このとき空白ポジションを開く.同時に,この戦略は,複数の利益のレベルを設定し,価格がこれらのレベルに達すると,預定されたポジションの比率で平衡状態に置く.
移動平均線交差多層利得戦略は,多層利得結束の方法によって,トレンドの中でより多くの利得を得ることができ,リスクをコントロールする簡単な効果的なトレンド追跡戦略である.しかし,この戦略には,特定の市場状況とユーザーのニーズに応じて最適化および改善を必要とするいくつかの制限とリスクがあります.全体的に,この戦略は,有効な取引ツールとして使用できますが,完全に依存することはできません.
/*backtest
start: 2023-04-20 00:00:00
end: 2024-04-25 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/
// © ValdesTradingBots
//Follow Us for More Insights and Updates!
//Join our community and be the first to know about our new releases and trading tips
//Facebook Group: Join our vibrant community at https://www.facebook.com/groups/707469081464839/
//Twitter: Follow us for quick updates and insights at https://twitter.com/ValdesBots
//We're excited to have you with us!
//@version=5
strategy("Valdes Trading Bots MA Cross with Multiple Take Profits", overlay=true)
shortPeriod = input(18, title="Short MA Period")
longPeriod = input(32, title="Long MA Period")
// Take Profit Settings
tp1Enabled = input(true, title="Enable Take Profit 1")
tp1Perc = input(15, title="Take Profit 1 (%)") / 100
tp1QtyPerc = input(25, title="Take Profit 1 Qty (%)") / 100
tp2Enabled = input(true, title="Enable Take Profit 2")
tp2Perc = input(30, title="Take Profit 2 (%)") / 100
tp2QtyPerc = input(25, title="Take Profit 2 Qty (%)") / 100
tp3Enabled = input(true, title="Enable Take Profit 3")
tp3Perc = input(45, title="Take Profit 3 (%)") / 100
tp3QtyPerc = input(25, title="Take Profit 3 Qty (%)") / 100
tp4Enabled = input(true, title="Enable Take Profit 4")
tp4Perc = input(60, title="Take Profit 4 (%)") / 100
tp4QtyPerc = input(25, title="Take Profit 4 Qty (%)") / 100
shortMA = ta.sma(close, shortPeriod)
longMA = ta.sma(close, longPeriod)
// Determine the trend
uptrend = shortMA > longMA
downtrend = shortMA < longMA
// Assign candle colors based on the trend
candleColor = uptrend ? color.rgb(9, 112, 0) : downtrend ? color.rgb(255, 0, 0) : color.new(color.blue, 0)
plot(shortMA, title="Short MA", color=color.rgb(9, 112, 0))
plot(longMA, title="Long MA", color=color.rgb(255, 0, 0))
// Create a cross signal
longCross = ta.crossover(shortMA, longMA)
shortCross = ta.crossunder(shortMA, longMA)
// Strategy entry
if (longCross)
strategy.entry("Long", strategy.long)
if (shortCross)
strategy.entry("Short", strategy.short)
// Strategy take profit
if (tp1Enabled and strategy.position_size > 0)
strategy.exit("TP1 Long", "Long", qty_percent=tp1QtyPerc, limit=strategy.position_avg_price * (1 + tp1Perc))
if (tp1Enabled and strategy.position_size < 0)
strategy.exit("TP1 Short", "Short", qty_percent=tp1QtyPerc, limit=strategy.position_avg_price * (1 - tp1Perc))
if (tp2Enabled and strategy.position_size > 0)
strategy.exit("TP2 Long", "Long", qty_percent=tp2QtyPerc, limit=strategy.position_avg_price * (1 + tp2Perc))
if (tp2Enabled and strategy.position_size < 0)
strategy.exit("TP2 Short", "Short", qty_percent=tp2QtyPerc, limit=strategy.position_avg_price * (1 - tp2Perc))
if (tp3Enabled and strategy.position_size > 0)
strategy.exit("TP3 Long", "Long", qty_percent=tp3QtyPerc, limit=strategy.position_avg_price * (1 + tp3Perc))
if (tp3Enabled and strategy.position_size < 0)
strategy.exit("TP3 Short", "Short", qty_percent=tp3QtyPerc, limit=strategy.position_avg_price * (1 - tp3Perc))
if (tp4Enabled and strategy.position_size > 0)
strategy.exit("TP4 Long", "Long", qty_percent=tp4QtyPerc, limit=strategy.position_avg_price * (1 + tp4Perc))
if (tp4Enabled and strategy.position_size < 0)
strategy.exit("TP4 Short", "Short", qty_percent=tp4QtyPerc, limit=strategy.position_avg_price * (1 - tp4Perc))
// Plotting the signals on the chart
plotshape(series=longCross, title="Long Cross", location=location.belowbar, color=color.rgb(9, 112, 0), style=shape.triangleup, size=size.small)
plotshape(series=shortCross, title="Short Cross", location=location.abovebar, color=color.rgb(255, 0, 0), style=shape.triangledown, size=size.small)
// Apply candle color
barcolor(candleColor)