OPEN-SOURCE SCRIPT

4th Day Performance After 3 Down Days 5 years

//version=5
indicator("4th Day Performance After 3 Down Days", overlay=true)

// Define the starting date for 5 years ago
fromDate = timestamp(year=year - 5, month=1, day=1, hour=0, minute=0)

// Variables to track market performance
isDown = close < open
threeDaysDown = isDown[1] and isDown[2] and isDown[3] and (time >= fromDate)

// Variables to store entry and exit points
var float entryPrice = na
var float exitPrice = na
var float totalPnL = 0.0
var int tradeCount = 0
var int positiveDays = 0
var int negativeDays = 0

if threeDaysDown
entryPrice := close[1] // 3rd day close
exitPrice := close // 4th day close
pnl = exitPrice - entryPrice
totalPnL += pnl
tradeCount += 1
if pnl > 0
positiveDays += 1
else if pnl < 0
negativeDays += 1

// Display total PnL, trade count, positive and negative day counts
defineTable() =>
var table myTable = table.new(position.top_right, 5, 2, bgcolor=color.new(color.white, 90))
table.cell(myTable, 0, 0, "Metric", text_color=color.black, bgcolor=color.new(color.gray, 70))
table.cell(myTable, 0, 1, "Value", text_color=color.black, bgcolor=color.new(color.gray, 70))
myTable

var table myTable = na
myTable := defineTable()
table.cell(myTable, 1, 0, "Total PnL", text_color=color.black)
table.cell(myTable, 1, 1, str.tostring(totalPnL, format.mintick), text_color=color.black)
table.cell(myTable, 2, 0, "Trade Count", text_color=color.black)
table.cell(myTable, 2, 1, str.tostring(tradeCount), text_color=color.black)
table.cell(myTable, 3, 0, "Positive Days", text_color=color.black)
table.cell(myTable, 3, 1, str.tostring(positiveDays), text_color=color.black)
table.cell(myTable, 4, 0, "Negative Days", text_color=color.black)
table.cell(myTable, 4, 1, str.tostring(negativeDays), text_color=color.black)
Cycles

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer