COTIndex OTC
COTIndex OTC
//@version=5
int weeks = input.int(26, "Number of weeks", minval=1)
int upperExtreme = input.int(80, "Upper Threshold in %", minval=50)
int lowerExtreme = input.int(20, "Lower Threshold in %", minval=1)
bool hideCurrentWeek = input(true, "Hide the current week until market close")
bool markExtremes = input(false, "Mark long and short extremes")
bool showSmallSpecs = input(true, "Show small speculators index")
bool showProducers = input(true, "Show producers index")
bool showLargeSpecs = input(true, "Show large speculators index")
indicator("COT INDEX", shorttitle="COT INDEX", format=format.percent, precision=0)
netLongLargePositions() =>
largeSpecsLong = dataRequest("Noncommercial Positions", true)
largeSpecsShort = dataRequest("Noncommercial Positions", false)
largeSpecsLong - largeSpecsShort
netLongSmallPositions() =>
smallSpecsLong = dataRequest("Nonreportable Positions", true)
smallSpecsShort = dataRequest("Nonreportable Positions", false)
smallSpecsLong - smallSpecsShort
calcIndex(netPos) =>
minNetPos = ta.lowest(netPos, weeks)
maxNetPos = ta.highest(netPos, weeks)
if maxNetPos != minNetPos
100 * (netPos - minNetPos) / (maxNetPos - minNetPos)
else
na