OPEN-SOURCE SCRIPT

BTC/USD Moving Average Crossover Strategy

//version=5
indicator("BTC/USD Moving Average Crossover Strategy", overlay=true)

// Input parameters for Moving Averages and RSI
lengthEMA1 = input.int(9, title="Short EMA")
lengthEMA2 = input.int(21, title="Long EMA")
rsiLength = input.int(14, title="RSI Length")
takeProfit = input.float(2.5, title="Take Profit %")
stopLoss = input.float(1.0, title="Stop Loss %")

// EMA Calculations
emaShort = ta.ema(close, lengthEMA1)
emaLong = ta.ema(close, lengthEMA2)

// RSI Calculation
rsi = ta.rsi(close, rsiLength)

// Entry Conditions
buySignal = ta.crossover(emaShort, emaLong) and rsi > 50
sellSignal = ta.crossunder(emaShort, emaLong) or rsi < 50

// Track position entry price
var float entryPrice = na

// Buy and sell logic
if (buySignal)
entryPrice := close

// Set stop-loss and take-profit levels
takeProfitLevel = entryPrice * (1 + takeProfit / 100)
stopLossLevel = entryPrice * (1 - stopLoss / 100)
exitCondition = close >= takeProfitLevel or close <= stopLossLevel or sellSignal

// Exit trade
if (exitCondition)
entryPrice := na // Reset entry price

// Plot Buy and Sell signals
plotshape(series=buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Plotting EMA lines for reference
plot(emaShort, title="9 EMA", color=color.blue)
plot(emaLong, title="21 EMA", color=color.orange)
Bands and Channels

Open-source Skript

Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun das Script auch andere Trader verstehen und prüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.

Möchten Sie dieses Skript auf einem Chart verwenden?

Haftungsausschluss