MA Crossover with Performance Dashboard
This MA Crossover with Performance Dashboard indicator uses the 50-period and 200-period Simple Moving Averages (SMA) to identify bullish and bearish trends. The dashboard displays key performance metrics such as the number of profitable and losing trades, total profit, and the longest winning streak, helping traders evaluate their strategy’s effectiveness in real-time. It also plots signals for potential entries and alerts for crossover events.

Example chart using the MA Crossover with Performance Dashboard
Key Features
- MA Crossover: Tracks the crossover of 50-period and 200-period SMAs for potential buy and sell signals.
- Trade Performance Dashboard: Displays key metrics like profitable trades, losing trades, and total profit.
- Win Streak Tracker: Tracks the longest winning streak in the strategy for performance analysis.
- Alerts: Provides alerts for crossover events to notify traders in real-time.
- Customizable Lot Size: Allows traders to adjust the lot size for simulated trades.
Additional Features and Strategies
This Pine Script helps traders using moving averages by providing insights into the overall performance of their strategy. The following key features outline its benefits:
- Alert Options: The script provides alerts for bullish and bearish crossovers, allowing users to be notified via TradingView alerts.
- Performance Dashboard: Displays key statistics such as the number of profitable and losing trades, total profit, longest winning streak, and total trades to assess performance.
- Lot Size Adjustment: Users can define a custom lot size to simulate the impact of their trades and better understand potential outcomes.
- Visual Signals: The script plots arrows for bullish and bearish crossovers, visually indicating potential entry points.
- Simulated Trade Outcome: Each trade is simulated with a defined outcome, allowing traders to visualize the results of their strategy over time.
Key Conditions
- Bullish Crossover: When the 50-period SMA crosses above the 200-period SMA, a potential buy signal is triggered.
- Bearish Crossover: When the 50-period SMA crosses below the 200-period SMA, a potential sell signal is triggered.
- Trade Outcome: The outcome of each trade is evaluated based on the difference between the entry and exit price.
Plotting
- SMAs: Plots the 50-period and 200-period Simple Moving Averages for trend identification.
- Signals: Arrows are plotted on the chart for buy and sell signals based on MA crossovers.
- Performance Dashboard: Displays a summary of the strategy’s performance, including profitable trades, total profit, longest winning streak, and more.
Indicator Code
//@version=6
indicator("MA Crossover with Performance Dashboard", shorttitle="MACrossover", format=format.price, precision=2)
// Parameters
length50 = input.int(50, title="Short-term MA length", minval=1)
length200 = input.int(200, title="Long-term MA length", minval=1)
lotSize = input.float(0.1, title="Lot Size", step=0.01)
// Calculating MAs
src = close
ma50 = ta.sma(src, length50)
ma200 = ta.sma(src, length200)
// Plot MAs
plot(ma50, color=color.blue, linewidth=2, title="50-period MA")
plot(ma200, color=color.red, linewidth=2, title="200-period MA")
// Crossover detection
longCondition = ta.crossover(ma50, ma200)
shortCondition = ta.crossunder(ma50, ma200)
// Variables for trade tracking
var int profitableTrades = 0
var int losingTrades = 0
var int totalTrades = 0
var int longestWinStreak = 0
var int currentWinStreak = 0
var float lastTradePrice = na
var float totalProfit = 0.0
if (longCondition)
// Simulating a long trade
lastTradePrice := close
totalTrades += 1
if (shortCondition)
// Simulating a short trade (not implemented here; you can add logic for it)
lastTradePrice := na // Reset lastTradePrice for short trades
totalTrades += 1
// Simulate trade outcome after one bar
if not na(lastTradePrice)
// Calculate profit for this trade
tradeOutcome = close - lastTradePrice
tradeProfit = tradeOutcome * lotSize
totalProfit += tradeProfit // Accumulate total profit
if tradeProfit > 0
profitableTrades += 1
currentWinStreak += 1
else
losingTrades += 1
currentWinStreak := 0
// Update longest win streak
longestWinStreak := math.max(longestWinStreak, currentWinStreak)
// Plot arrows for signals
if longCondition
label.new(bar_index, low, "Bullish Crossover!", style=label.style_label_up, color=color.green, textcolor=color.white)
else if shortCondition
label.new(bar_index, high, "Bearish Crossover!", style=label.style_label_down, color=color.red, textcolor=color.white)
// Alerts on new crossover
alertcondition(longCondition, title="Bullish Crossover", message="50-period MA crosses above 200-period MA")
alertcondition(shortCondition, title="Bearish Crossover", message="50-period MA crosses below 200-period MA")
// Dashboard Display
var label dashboardLabel = na
if bar_index == 0
dashboardLabel := label.new(x=bar_index, y=high + 10, text="", color=color.black, style=label.style_label_down, textcolor=color.white)
// Set label details
label.set_xy(dashboardLabel, bar_index, high + 10)
label.set_text(dashboardLabel, str.tostring(profitableTrades) + " Profitable Trades\n" + str.tostring(losingTrades) + " Losing Trades\n" + str.tostring(longestWinStreak) + " Longest Winning Streak\n" + str.tostring(totalTrades) + " Total Trades\n" + "Total Profit: $" + str.tostring(totalProfit, format.price))
How to Use
Follow these steps to use the indicator:
- Click the "Copy Code" button above to copy the script to your clipboard.
- Open TradingView and navigate to the Pine Script editor.
- Paste the code into the editor and click "Add to Chart".
- Customize the inputs to match your trading strategy.