
이 전략은 간단한 이동 평균 ((SMA) 의 교차를 기반으로 한 자동 거래 시스템이며, 동적 정지 및 중단 메커니즘을 결합합니다. 그것은 두 개의 다른 주기적 SMA를 사용하여 구매 및 판매 신호를 생성합니다. 동시에, 전략은 위험을 제어하고 수익을 잠금하기 위해 퍼센트 기반의 정지 및 중단 수준을 설정합니다.
이 쌍평선 교차를 기반으로 한 거래 전략은 자동화 거래에 입문하는 초보자에게 적합한 간단하고 효과적인 프레임 워크를 제공합니다. 트렌드 추적과 위험 관리의 요소를 결합하여 동적으로 스톱 손실을 설정하여 자금을 보호합니다. 그러나 실제 거래에서 더 나은 효과를 얻기 위해서는 추가적인 최적화와 개선이 필요합니다. 필터로 더 많은 기술 지표를 추가하여 스톱 손실을 설정하는 방법을 최적화하고 더 복잡한 위치 관리 전략을 도입하는 것을 고려 할 수 있습니다.
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © Pubgentleman
//@version=5
//@version=5
strategy("TSLA 1-Hour SMA Crossover Strategy with Buy/Sell Signals", overlay=true)
// Parameters
shortSmaLength = input.int(50, title="Short SMA Length")
longSmaLength = input.int(100, title="Long SMA Length")
takeProfitPerc = input.float(5.0, title="Take Profit Percentage", step=0.1) // 5.0% take profit
stopLossPerc = input.float(3.0, title="Stop Loss Percentage", step=0.1) // 3.0% stop loss
// Calculate SMAs
shortSma = ta.sma(close, shortSmaLength)
longSma = ta.sma(close, longSmaLength)
// Plot SMAs
plot(shortSma, color=color.blue, title="Short SMA")
plot(longSma, color=color.red, title="Long SMA")
// Entry Conditions
longCondition = ta.crossover(shortSma, longSma)
shortCondition = ta.crossunder(shortSma, longSma)
// Trade Management
var float entryPrice = na
var float takeProfitLevel = na
var float stopLossLevel = na
if (longCondition)
entryPrice := close
takeProfitLevel := entryPrice * (1 + takeProfitPerc / 100)
stopLossLevel := entryPrice * (1 - stopLossPerc / 100)
strategy.entry("Long", strategy.long)
label.new(x=bar_index, y=low, text="Buy", style=label.style_label_up, color=color.green, textcolor=color.white)
if (shortCondition)
entryPrice := close
takeProfitLevel := entryPrice * (1 - takeProfitPerc / 100)
stopLossLevel := entryPrice * (1 + stopLossPerc / 100)
strategy.entry("Short", strategy.short)
label.new(x=bar_index, y=high, text="Sell", style=label.style_label_down, color=color.red, textcolor=color.white)
// Exit Conditions
if (strategy.position_size > 0)
if (close >= takeProfitLevel or close <= stopLossLevel)
strategy.close("Long")
if (strategy.position_size < 0)
if (close <= takeProfitLevel or close >= stopLossLevel)
strategy.close("Short")
// Plot Take Profit and Stop Loss Levels
plot(strategy.position_size > 0 ? takeProfitLevel : na, title="Take Profit Level", color=color.green, style=plot.style_stepline)
plot(strategy.position_size > 0 ? stopLossLevel : na, title="Stop Loss Level", color=color.red, style=plot.style_stepline)
plot(strategy.position_size < 0 ? takeProfitLevel : na, title="Take Profit Level (Short)", color=color.green, style=plot.style_stepline)
plot(strategy.position_size < 0 ? stopLossLevel : na, title="Stop Loss Level (Short)", color=color.red, style=plot.style_stepline)