// 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")
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.