OPEN-SOURCE SCRIPT

4 EMA Strategy with Stop Loss

//version=5
strategy("4 EMA Strategy with Stop Loss", overlay=true)

// Define the EMA lengths
ema1_length = input(9, title="EMA 1 Length")
ema2_length = input(21, title="EMA 2 Length")
ema3_length = input(50, title="EMA 3 Length")
ema4_length = input(200, title="EMA 4 Length")

// Calculate the EMAs
ema1 = ta.ema(close, ema1_length)
ema2 = ta.ema(close, ema2_length)
ema3 = ta.ema(close, ema3_length)
ema4 = ta.ema(close, ema4_length)

// Plot EMAs on the chart
plot(ema1, color=color.blue, title="EMA 9")
plot(ema2, color=color.orange, title="EMA 21")
plot(ema3, color=color.green, title="EMA 50")
plot(ema4, color=color.red, title="EMA 200")

// Define conditions for Buy and Sell signals
buy_condition = (ema1 > ema2 and ema2 > ema3 and ema3 > ema4)
sell_condition = (ema1 < ema2 and ema2 < ema3 and ema3 < ema4)

// Input stop loss percentage
stop_loss_perc = input(2.0, title="Stop Loss %")

// Execute buy signal
if (buy_condition)
strategy.entry("Buy", strategy.long)

// Set stop loss at a percentage below the entry price
strategy.exit("Sell", "Buy", stop=strategy.position_avg_price * (1 - stop_loss_perc / 100))

// Execute sell signal
if (sell_condition)
strategy.entry("Sell", strategy.short)

// Set stop loss at a percentage above the entry price
strategy.exit("Cover", "Sell", stop=strategy.position_avg_price * (1 + stop_loss_perc / 100))
concept

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

면책사항