RAAM 1234//@version=5
strategy("MNQ EMA Strategy", overlay=true)
// User Inputs
emaShortLength = input.int(50, "Short EMA Length")
emaLongLength = input.int(200, "Long EMA Length")
stopLossPerc = input.float(1.0, "Stop Loss (%)") // 1% stop loss
takeProfitPerc = input.float(2.0, "Take Profit (%)") // 2% take profit
// Calculate EMAs
emaShort = ta.ema(close, emaShortLength)
emaLong = ta.ema(close, emaLongLength)
// Entry Condition: When Short EMA crosses above Long EMA
longCondition = ta.crossover(emaShort, emaLong)
// Exit Condition: When Short EMA crosses below Long EMA
exitCondition = ta.crossunder(emaShort, emaLong)
// Strategy Logic
if (longCondition)
// Open a new long position if not already in one
strategy.entry("Long", strategy.long)
// If we want to automatically exit the long position via Stop Loss and Take Profit:
strategy.exit(
"Exit Long",
from_entry = "Long",
stop_loss = strategy.position_avg_price * (1 - stopLossPerc/100),
limit = strategy.position_avg_price * (1 + takeProfitPerc/100)
)
// Also, if exit condition is triggered by EMA cross:
if (exitCondition)
strategy.close("Long")