//@version=6 indicator("MA/EMA Crossover — Daily Pips Breakdown", overlay=true, max_bars_back=5000) // ====== INPUTS ====== showMAs = input.bool(true, "Show Moving Averages") showStats = input.bool(true, "Show Daily Pips Table") // ====== TP/SL ====== tpPips = 50.0 slPips = 50.0 pipValue = 0.10 tpDistance = tpPips * pipValue slDistance = slPips * pipValue // ====== MOVING AVERAGES ====== sma20 = ta.sma(close, 20) sma50 = ta.sma(close, 50) sma200 = ta.sma(close, 200) ema200 = ta.ema(close, 200) plot(showMAs ? sma20 : na, "SMA 20", color=color.blue, linewidth=2) plot(showMAs ? sma50 : na, "SMA 50", color=color.purple, linewidth=2) plot(showMAs ? sma200 : na, "SMA 200", color=color.red, linewidth=2) plot(showMAs ? ema200 : na, "EMA 200", color=color.orange, linewidth=2) // ====== SIGNALS ====== highestMA = math.max(sma20, math.max(sma50, math.max(sma200, ema200))) lowestMA = math.min(sma20, math.min(sma50, math.min(sma200, ema200))) buySignal = ta.crossover(close, highestMA) sellSignal = ta.crossunder(close, lowestMA) // ====== TRADE STATE ====== var bool inTrade = false var bool isLong = false var float entryPrice = na var int entryBar = na var float entryLong = na var float entryShort = na var float exitPrice = na var int exitType = 0 // 1=TP, -1=SL // Background shading var float bgTop = na var float bgBottom = na var color bgColor = na // ====== TRADE LOGIC ====== if buySignal and not inTrade inTrade := true isLong := true entryPrice := highestMA entryBar := bar_index entryLong := low bgTop := na bgBottom := na if sellSignal and not inTrade inTrade := true isLong := false entryPrice := lowestMA entryBar := bar_index entryShort := high bgTop := na bgBottom := na // ====== TRADE MANAGEMENT ====== tpPrice = isLong ? entryPrice + tpDistance : entryPrice - tpDistance slPrice = isLong ? entryPrice - slDistance : entryPrice + slDistance tpHit = inTrade and (isLong ? high >= tpPrice : low <= tpPrice) slHit = inTrade and (isLong ? low <= slPrice : high >= slPrice) if tpHit or slHit win = tpHit exitPrice := close exitType := win ? 1 : -1 // Entry → Exit dotted line line.new(x1=entryBar, y1=entryPrice, x2=bar_index, y2=exitPrice, color=(win ? color.green : color.red), width=2, style=line.style_dotted) // Background shading bgTop := math.max(entryPrice, exitPrice) bgBottom := math.min(entryPrice, exitPrice) bgColor := win ? color.new(color.green, 85) : color.new(color.red, 85) inTrade := false entryPrice := na entryBar := na entryLong := na entryShort := na // ====== PLOT ENTRY/EXIT SIGNALS ====== plotshape(not na(entryLong), style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="BUY Entry") plotshape(not na(entryShort), style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="SELL Entry") plotshape(exitType == 1, style=shape.circle, location=location.abovebar, color=color.green, size=size.tiny, title="TP Hit +50") plotshape(exitType == -1, style=shape.circle, location=location.belowbar, color=color.red, size=size.tiny, title="SL Hit -50") // ====== EXIT LABELS ====== if exitType != 0 exitY = exitType == 1 ? high * 1.002 : low * 0.998 exitText = exitType == 1 ? "+50" : "-50" exitColor = exitType == 1 ? color.green : color.red label.new(bar_index, exitY, text=exitText, style=label.style_none, color=exitColor, textcolor=color.white, size=size.small) exitType := 0 // ====== BACKGROUND SHADING ====== p1 = plot(not na(bgTop) ? bgTop : na, display=display.none) p2 = plot(not na(bgBottom) ? bgBottom : na, display=display.none) fillColor = not na(bgTop) and not na(bgBottom) ? bgColor : na fill(p1, p2, color=fillColor) // ====== DAILY PIPS AGGREGATION (LAST 20 DAYS) ====== var string[] dayLabels = array.new_string() var int[] dayTrades = array.new_int() var int[] dayWins = array.new_int() var int[] dayLosses = array.new_int() var float[] dayPips = array.new_float() var int lastDayOfMonth = na var int dTrades = 0 var int dWins = 0 var int dLosses = 0 var int maxDays = 20 if na(lastDayOfMonth) lastDayOfMonth := dayofmonth // Count trade on ENTRY (not exit) - when trade opens if (buySignal or sellSignal) and not inTrade dTrades += 1 // Count win/loss on EXIT if tpHit or slHit if tpHit dWins += 1 if slHit dLosses += 1 // Day changed → store data if dayofmonth != lastDayOfMonth netPips = (dWins * tpPips) - (dLosses * slPips) dayString = str.tostring(year) + "-" + str.tostring(month, "00") + "-" + str.tostring(lastDayOfMonth, "00") array.push(dayLabels, dayString) array.push(dayTrades, dTrades) array.push(dayWins, dWins) array.push(dayLosses, dLosses) array.push(dayPips, netPips) // Keep only last 20 days if array.size(dayLabels) > maxDays array.shift(dayLabels) array.shift(dayTrades) array.shift(dayWins) array.shift(dayLosses) array.shift(dayPips) // Reset counters for new day dTrades := 0 dWins := 0 dLosses := 0 lastDayOfMonth := dayofmonth // ====== DISPLAY DAILY TABLE (LAST 20 DAYS) ====== if showStats and barstate.islast n = array.size(dayLabels) var table dailyTable = table.new(position=position.top_right, columns=5, rows=n+1, border_width=2, bgcolor=color.new(color.black, 80)) table.cell(dailyTable, 0, 0, "Last 20 Days", bgcolor=color.blue, text_color=color.white, text_size=size.small) table.cell(dailyTable, 1, 0, "Trades", bgcolor=color.blue, text_color=color.white, text_size=size.small) table.cell(dailyTable, 2, 0, "Wins", bgcolor=color.green, text_color=color.white, text_size=size.small) table.cell(dailyTable, 3, 0, "Losses", bgcolor=color.red, text_color=color.white, text_size=size.small) table.cell(dailyTable, 4, 0, "Pips", bgcolor=color.gray, text_color=color.white, text_size=size.small) for i = 0 to n - 1 tradesStr = str.tostring(array.get(dayTrades, i)) winsStr = str.tostring(array.get(dayWins, i)) lossesStr = str.tostring(array.get(dayLosses, i)) pipsStr = str.tostring(array.get(dayPips, i), "0.00") pipsColor = array.get(dayPips, i) >= 0 ? color.new(color.green, 60) : color.new(color.red, 60) table.cell(dailyTable, 0, i+1, array.get(dayLabels, i), text_size=size.small) table.cell(dailyTable, 1, i+1, tradesStr, text_size=size.small) table.cell(dailyTable, 2, i+1, winsStr, text_size=size.small) table.cell(dailyTable, 3, i+1, lossesStr, text_size=size.small) table.cell(dailyTable, 4, i+1, pipsStr, text_size=size.small, bgcolor=pipsColor, text_color=color.white)