
이 전략은 이동 평균의 교차를 기반으로 한 정량 거래 전략이다. 이 전략은 두 가지 다른 주기의 이동 평균을 계산하여 (고속선과 느린선) 빠른 선이 아래에서 위로 슬로우 라인을 통과할 때 구매 신호를 생성하고 빠른 선이 위에서 아래로 슬로우 라인을 통과할 때 판매 신호를 생성한다. 이 전략은 또한 동적 포지션 관리의 개념을 도입하여 계좌의 적자를 따라 매 거래의 포지션 크기를 동적으로 조정하여 위험을 제어한다.
이동평균선 교차전략 (영어: Moving Average Cross Line Strategy) 은 두 개의 다른 주기 이동평균의 교차 신호를 통해 가격 트렌드를 포착하는 간단한 실용적인 정량 거래 전략이며, 동시에 위험을 제어하기 위해 동적 위치 관리 규칙을 도입한다. 이 전략의 논리는 명확하고, 구현하기 쉽고, 적용 범위는 넓다. 그러나 실제 응용에서는 빈번한 거래, 불안한 시장 성능 및 파라미터 최적화와 같은 잠재적인 위험에 주의를 기울이고, 필요에 따라 전략에 최적화 및 개선이 필요합니다.
/*backtest
start: 2024-06-06 00:00:00
end: 2024-06-13 00:00:00
period: 5m
basePeriod: 1m
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/
// © okolienicholas
//@version=5
strategy("Moving Average Crossover Strategy", overlay=true)
// Input parameters
fast_length = input(9, title="Fast MA Length")
slow_length = input(21, title="Slow MA Length")
source = close
account_balance = input(100, title="Account Balance") // Add your account balance here
// Calculate moving averages
fast_ma = ta.sma(source, fast_length)
slow_ma = ta.sma(source, slow_length)
// Plot moving averages
plot(fast_ma, color=color.blue, title="Fast MA")
plot(slow_ma, color=color.red, title="Slow MA")
// Generate buy/sell signals
buy_signal = ta.crossover(fast_ma, slow_ma)
sell_signal = ta.crossunder(fast_ma, slow_ma)
// Plot buy/sell signals
plotshape(buy_signal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(sell_signal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")
// Calculate the risk per trade
risk_per_trade = account_balance * 0.01
// Calculate the number of shares to buy
shares_to_buy = risk_per_trade / (high - low)
// Calculate the profit or loss
profit_or_loss = strategy.netprofit
// Adjust the position size based on the profit or loss
if (profit_or_loss > 0)
shares_to_buy = shares_to_buy * 1.1 // Increase the position size by 10% when in profit
else
shares_to_buy = shares_to_buy * 0.9 // Decrease the position size by 10% when in loss
// Execute orders
if (buy_signal)
strategy.entry("Buy", strategy.long, qty=shares_to_buy)
if (sell_signal)
strategy.entry("Sell", strategy.short, qty=shares_to_buy)