Awesome. Very much wanted and needed. Thank you!
Any chance that code could be modified for intraday periods?
Here is my code modified for use intraday. However please note that as per L. Williams the COT Proxy Index was designed for Weekly use only and tested by him. Intraday may give you allots of false signals.
Happy Trading ;-)
#########################################################
#Created by dag. 07.06.2022
#Version 1.1 #Added Code for Intraday usage. Suggest using AggregationPeriod.Week as per Williams.
#This Script mimics the COT Large Traders Net position
declare lower;
#declare hide_on_intraday;
DefineGlobalColor("HeavyBought", color.Green);
DefineGlobalColor("Normal", Color.Gray);
DefineGlobalColor("HeavySelling", Color.Red);
input ManualWeeklyBarsAgo = 8;
input Commodity = {default Stocks, Currencies, Metal, Meats, Softs_Sugar_coffee, Cotton, Grains, DollarIndex, Bonds, Energies, Manual};
def barsAgo; #Williams is using the 13 weeks or 65 Daily for /SI (Silver or /Gold and 90 daysFromDate for Currencies;
def CurrentPeriod = GetAggregationPeriod();
switch (Commodity) {
case Stocks:
barsAgo = 13;
case Currencies:
barsAgo = 26;
case Metal:
barsAgo = 26;
case Meats:
barsAgo = 13;
case Softs_Sugar_coffee:
barsAgo = 13;
case Cotton:
barsAgo = 26;
case Grains:
barsAgo = 26;
case DollarIndex:
barsAgo = 13;
case Bonds:
barsAgo = 52;
case Energies:
barsAgo = 13;
case Manual:
barsAgo = ManualWeeklyBarsAgo;
}
input ForIntradayUsePeriod = {default No_DefaultAsPerWilliams, Yes_Auto, Yes_Manual};
input PeriodManual = aggregationPeriod.DAY;
def AggregationPeriod = if ForIntradayUsePeriod == ForIntradayUsePeriod.Yes_Auto then getaggregationPeriod() else if ForIntradayUsePeriod == ForIntradayUsePeriod.Yes_Manual then PeriodManual else if ForIntradayUsePeriod == ForIntradayUsePeriod.No_DefaultAsPerWilliams then (if getaggregationPeriod() == AggregationPeriod.Month then AggregationPeriod.Month else if getaggregationPeriod() == AggregationPeriod.Week then AggregationPeriod.Week else AggregationPeriod.Week) else double.nan ;
def c = close(period = AggregationPeriod);
def o = open(period = AggregationPeriod);
def h = high(period = AggregationPeriod);
def l = low(period = AggregationPeriod);
def WilliamsRange = trueRange(h,c,l);
plot COTIndex = Average(o - c, barsAgo) / Average(WilliamsRange, barsAgo) * 50 + 50; # instead you may use *100
#################### Levels ###########
input IndexColoring = {default AutoLevels, ManualLevels};
Input HeavyBaughtLevelManual= 60;
Input HeavySoldLevelManual = 30;
def BarAgoForLimits = barsAgo;
input levelsMultiplier = 5;
input ShowLevels = yes;
plot UnderV = HeavyBaughtLevelManual;
UnderV.assignValueColor(Color.Green);
UnderV.setHiding(!ShowLevels);
plot OverVal = HeavySoldLevelManual;
OverVal.assignValueColor(Color.Red);
OverVal.setHiding(!ShowLevels);
###### Auto Levels
def HighestHigh = Highest(COTIndex, BarAgoForLimits);
def LowestLow = Lowest(COTIndex, BarAgoForLimits);
def HeavyBuyers = Average(HighestHigh, BarAgoForLimits*levelsMultiplier);
def HeavySellers = Average(LowestLow, BarAgoForLimits*levelsMultiplier);
COTIndex.AssignValueColor (if IndexColoring == IndexColoring.AutoLevels then (if COTIndex >= HeavyBuyers then GlobalColor("HeavyBought") else if COTIndex <= HeavySellers then GlobalColor("HeavySelling") else GlobalColor("Normal")) else (if COTIndex >= HeavyBaughtLevelManual then GlobalColor("HeavyBought") else if COTIndex <= HeavySoldLevelManual then GlobalColor("HeavySelling") else GlobalColor("Normal")));
#########################################################