Paste this complete script into a new strategy. It counts eligible bars, raw SMA crosses and calls to strategy.entry(), then shows open and closed trades separately. The diagnostic market-order mode bypasses the SMA signal and requests an entry every 20 bars, followed by a close five bars later. It is an isolation test, not a trading system. Use at least 30 loaded bars and enough simulated capital for one tradable unit; neither mode guarantees a fill on every symbol.
Complete Pine Script v6 diagnostic strategy. Entry-call counts measure code execution, not accepted or filled orders.pinescript
//@version=6
strategy("No data diagnostic", overlay = true, initial_capital = 100000,
margin_long = 100, margin_short = 100, pyramiding = 0)
bool testMode = input.bool(false, "Diagnostic market-order mode")
float orderQty = input.float(1.0, "Quantity (tradable units)", minval = 0.000001)
bool useDates = input.bool(false, "Enable date filter")
int startTime = input.time(timestamp("01 Jan 2024 00:00 +0000"), "Start")
int endTime = input.time(timestamp("31 Dec 2030 23:59 +0000"), "End")
bool inRange = not useDates or (time >= startTime and time <= endTime)
float fast = ta.sma(close, 9)
float slow = ta.sma(close, 21)
bool ready = not na(fast) and not na(slow)
bool crossedUp = ta.crossover(fast, slow)
bool crossedDown = ta.crossunder(fast, slow)
bool entrySignal = testMode ? bar_index % 20 == 10 : ready and crossedUp
bool exitSignal = testMode ? bar_index % 20 == 15 : crossedDown
bool entryCall = inRange and entrySignal and strategy.position_size == 0
var int eligibleBars = 0
var int rawSignals = 0
var int entryCalls = 0
if inRange
eligibleBars += 1
if crossedUp
rawSignals += 1
if entryCall
entryCalls += 1
strategy.entry("Long", strategy.long, qty = orderQty)
if (exitSignal or not inRange) and strategy.position_size > 0
strategy.close("Long")
plot(fast, "Fast SMA", color.blue)
plot(slow, "Slow SMA", color.orange)
plotshape(crossedUp, title = "Raw SMA cross", style = shape.circle,
location = location.abovebar, color = color.blue, text = "S")
plotshape(entryCall, title = "Entry command called", style = shape.triangleup,
location = location.belowbar, color = color.green, text = "E")
plot(close * orderQty * syminfo.pointvalue, "Estimated notional in symbol currency",
display = display.data_window)
var table report = table.new(position.top_right, 2, 6,
bgcolor = color.white, border_width = 1)
if barstate.isconfirmed
table.cell(report, 0, 0, "Diagnostic", text_color = color.black)
table.cell(report, 1, 0, "Count", text_color = color.black)
table.cell(report, 0, 1, "Eligible bars", text_color = color.black)
table.cell(report, 1, 1, str.tostring(eligibleBars), text_color = color.black)
table.cell(report, 0, 2, "Raw SMA crosses", text_color = color.black)
table.cell(report, 1, 2, str.tostring(rawSignals), text_color = color.black)
table.cell(report, 0, 3, "Entry calls", text_color = color.black)
table.cell(report, 1, 3, str.tostring(entryCalls), text_color = color.black)
table.cell(report, 0, 4, "Open trades", text_color = color.black)
table.cell(report, 1, 4, str.tostring(strategy.opentrades), text_color = color.black)
table.cell(report, 0, 5, "Closed trades", text_color = color.black)
table.cell(report, 1, 5, str.tostring(strategy.closedtrades), text_color = color.black)