// Entry Logic - Buy when MACD crosses above the Signal Line and Sell when MACD crosses below the Signal Line entry_condition_long = ta.crossover(macd_line, signal_line) entry_condition_short = ta.crossunder(macd_line, signal_line)
// Exit Logic exit_long = strategy.position_avg_price <= fix_stop_loss or low <= atr_stop_loss exit_short = strategy.position_avg_price >= fix_stop_loss or high >= atr_stop_loss
// Trail Stop Logic trail_stop_long = close >= trail_stop trail_stop_short = close <= trail_stop
// Submit entry orders if entry_condition_long strategy.entry("Buy", strategy.long) if entry_condition_short strategy.entry("Sell", strategy.short)
// Plot MACD lines and Signal line for reference plot(macd_line, title="MACD", color=color.blue) plot(signal_line, title="Signal Line", color=color.red)
// Plot ATR value for reference plot(atr_value, color=color.green)
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.