I’m looking for a Script that will lookback 5 days plus the current day (last closed candle on current chart) I’m mainly interested in 1hr, 15 min, and 5 min.
AI came up with this code which does not work, but maybe it will help you understand what I’m looking for.
I want colored lines drawn from the upper and lower pivot points of the day. I want to be able to be used for the /ES futures and /NQ futures.
I want the line from 5 full days back to be extended to the right to the current time until it is no longer within the range of 5 full days back plus the current day.
I’d like the lines to be colored by strength: Strongest= red, then Orange, then yellow, green, Blue, Violet being the weakest. Strongest is the line that had the price come within input ticks of that level the most amount of times Violet (weakest) would be the level that was revisited 0 or the least amount of times.
I think this script would give a good visualization of where big money buyers/sellers would be at.
I hope this is not to hard, and I hope it helps people here in this community.
If its too difficult if it could be made without the coloring of the lines that still would be great!
One of the AI’s I put this code in said there was a problem with the “Day detection” or definition for 23hr like the /ES.
Here is the code the the AI returned that doesn't work. It may not be complete either because it seemed to be cutting off it's response.
Sorry I'm not a coder at all I've only modified some simple code to my liking, but this is defiantly way beyond me!
Thanks for any help anyone can give!
Here is the code that doesn't work!
AI came up with this code which does not work, but maybe it will help you understand what I’m looking for.
I want colored lines drawn from the upper and lower pivot points of the day. I want to be able to be used for the /ES futures and /NQ futures.
I want the line from 5 full days back to be extended to the right to the current time until it is no longer within the range of 5 full days back plus the current day.
I’d like the lines to be colored by strength: Strongest= red, then Orange, then yellow, green, Blue, Violet being the weakest. Strongest is the line that had the price come within input ticks of that level the most amount of times Violet (weakest) would be the level that was revisited 0 or the least amount of times.
I think this script would give a good visualization of where big money buyers/sellers would be at.
I hope this is not to hard, and I hope it helps people here in this community.
If its too difficult if it could be made without the coloring of the lines that still would be great!
One of the AI’s I put this code in said there was a problem with the “Day detection” or definition for 23hr like the /ES.
Here is the code the the AI returned that doesn't work. It may not be complete either because it seemed to be cutting off it's response.
Sorry I'm not a coder at all I've only modified some simple code to my liking, but this is defiantly way beyond me!
Thanks for any help anyone can give!
Here is the code that doesn't work!
Code:
# DailyPivotLines_StrengthColored
Input lookbackDays = 5;
Input pivotLen = 2;
Input proximityTicks = 2; # how close (in ticks) counts as a touch
Input maxCountForScale = 12; # maximum count mapped to strongest bucket
Input showCurrentDay = yes;
Input lineWidth = 2;
Input lineStyle = Curve.SHORT_DASH;
# Colors by strength: 6 levels (1 strongest -> 6 weakest)
Def c1 = Color.RED;
Def c2 = Color.ORANGE;
Def c3 = Color.YELLOW;
Def c4 = Color.GREEN;
Def c5 = Color.BLUE;
Def c6 = Color.VIOLET;
# helper
Def tickSize = TickSize();
# Day detection
Def day = GetYYYYMMDD();
Def isNewDay = day != day[1];
Def barIndex = BarNumber();
# Pivot detection
Def pivotHigh = high > Highest(high[1], pivotLen) and high >= Highest(high[-pivotLen], pivotLen);
Def pivotLow = low < Lowest(low[1], pivotLen) and low <= Lowest(low[-pivotLen], pivotLen);
# Store last 5 full days’ pivot highs/lows as values and bars (same logic as earlier script)
Rec dayHighVal;
Rec dayHighBar;
Rec dayLowVal;
Rec dayLowBar;
If barIndex == 1 {
dayHighVal = Double.NaN;
dayLowVal = Double.NaN;
dayHighBar = 0;
dayLowBar = 0;
} else {
dayHighVal = dayHighVal[1];
dayLowVal = dayLowVal[1];
dayHighBar = dayHighBar[1];
dayLowBar = dayLowBar[1];
}
If pivotHigh then {
If IsNaN(dayHighVal) or high > dayHighVal then {
dayHighVal = high;
dayHighBar = barIndex;
}
}
If pivotLow then {
If IsNaN(dayLowVal) or low < dayLowVal then {
dayLowVal = low;
dayLowBar = barIndex;
}
}
Rec sH1; rec sHB1; rec sL1; rec sLB1;
Rec sH2; rec sHB2; rec sL2; rec sLB2;
Rec sH3; rec sHB3; rec sL3; rec sLB3;
Rec sH4; rec sHB4; rec sL4; rec sLB4;
Rec sH5; rec sHB5; rec sL5; rec sLB5;
If isNewDay then {
sH5 = sH4[1]; sHB5 = sHB4[1]; sL5 = sL4[1]; sLB5 = sLB4[1];
sH4 = sH3[1]; sHB4 = sHB3[1]; sL4 = sL3[1]; sLB4 = sLB3[1];
sH3 = sH2[1]; sHB3 = sHB2[1]; sL3 = sL2[1]; sLB3 = sLB2[1];
sH2 = sH1[1]; sHB2 = sHB1[1]; sL2 = sL1[1]; sLB2 = sLB1[1];
sH1 = dayHighVal[1]; sHB1 = dayHighBar[1]; sL1 = dayLowVal[1]; sLB1 = dayLowBar[1];
} else {
sH5 = sH5[1]; sHB5 = sHB5[1]; sL5 = sL5[1]; sLB5 = sLB5[1];
sH4 = sH4[1]; sHB4 = sHB4[1]; sL4 = sL4[1]; sLB4 = sLB4[1];
sH3 = sH3[1]; sHB3 = sHB3[1]; sL3 = sL3[1]; sLB3 = sLB3[1];
sH2 = sH2[1]; sHB2 = sHB2[1]; sL2 = sL2[1]; sLB2 = sLB2[1];
sH1 = sH1[1]; sHB1 = sHB1[1]; sL1 = sL1[1]; sLB1 = sLB1[1];
}
# Function to count touches for a given horizontal level from its bar forward to last closed bar
Script CountTouches {
Input level = 0.0;
Input startBar = 0;
Input proximityTicks = 2;
Def idx = BarNumber();
Def within = AbsValue(close – level) <= proximityTicks * TickSize();
# only count from startBar forward
Def active = idx >= startBar and !IsNaN(level);
Rec cnt = if active and within then cnt[1] + 1 else cnt[1];
# initialize
If idx == 1 then cnt = 0;
Plot touchCount = cnt;
}
# Compute touch counts for each stored level
Def tcH1 = CountTouches(level = sH1, startBar = sHB1, proximityTicks = proximityTicks);
Def tcL1 = CountTouches(level = sL1, startBar = sLB1, proximityTicks = proximityTicks);
Def tcH2 = CountTouches(level = sH2, startBar = sHB2, proximityTicks = proximityTicks);
Def tcL2 = CountTouches(level = sL2, startBar = sLB2, proximityTicks = proximityTicks);
Def tcH3 = CountTouches(level = sH3, startBar = sHB3, proximityTicks = proximityTicks);
Def tcL3 = CountTouches(level = sL3, startBar = sLB3, proximityTicks = proximityTicks);
Def tcH4 = CountTouches(level = sH4, startBar = sHB4, proximityTicks = proximityTicks);
Def tcL4 = CountTouches(level = sL4, startBar = sLB4, proximityTicks = proximityTicks);
Def tcH5 = CountTouches(level = sH5, startBar = sHB5, proximityTicks = proximityTicks);
Def tcL5 = CountTouches(level = sL5, startBar = sLB5, proximityTicks = proximityTicks);
# Map count to 6 buckets (1..6) — 1 strongest (red) when count >= top threshold
Script Bucket {
Input count = 0;
Input maxForScale = 12;
Def scaled = Round(6 – (Min(count, maxForScale) / maxForScale) * 5);
Plot b = Min(Max(scaled, 1), 6);
}
Def bH1 = Bucket(tcH1, maxCountForScale);
Def bL1 = Bucket(tcL1, maxCountForScale);
Def bH2 = Bucket(tcH2, maxCountForScale);
Def bL2 = Bucket(tcL2, maxCountForScale);
Def bH3 = Bucket(tcH3, maxCountForScale);
Def bL3 = Bucket(tcL3, maxCountForScale);
Def bH4 = Bucket(tcH4, maxCountForScale);
Def bL4 = Bucket(tcL4, maxCountForScale);
Def bH5 = Bucket(tcH5, maxCountForScale);
Def bL5 = Bucket(tcL5, maxCountForScale);
# Helper to select color by bucket
Script ColorByBucket {
Input bucket = 6;
Plot col = if bucket == 1 then c1 else if bucket == 2 then c2 else if bucket == 3 then c3 else if bucket == 4 then c4 else if bucket == 5 then c5 else c6;
}
Def colH1 = ColorByBucket(bH1);
Def colL1 = ColorByBucket(bL1);
Def colH2 = ColorByBucket(bH2);
Def colL2 = ColorByBucket(bL2);
Def colH3 = ColorByBucket(bH3);
Def colL3 = ColorByBucket(bL3);
Def colH4 = ColorByBucket(bH4);
Def colL4 = ColorByBucket(bL4);
Def colH5 = ColorByBucket(bH5);
Def colL5 = ColorByBucket(bL5);
# Plot lines
Plot Day1High = if !IsNaN(sH1) then sH1 else Double.NaN;
Day1High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day1High.SetLineWeight(lineWidth);
Day1High.SetStyle(lineStyle);
Day1High.SetDefaultColor(colH1);
Plot Day1Low = if !IsNaN(sL1) then sL1 else Double.NaN;
Day1Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day1Low.SetLineWeight(lineWidth);
Day1Low.SetStyle(lineStyle);
Day1Low.SetDefaultColor(colL1);
Plot Day2High = if !IsNaN(sH2) then sH2 else Double.NaN;
Day2High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day2High.SetLineWeight(lineWidth);
Day2High.SetStyle(lineStyle);
Day2High.SetDefaultColor(colH2);
Plot Day2Low = if !IsNaN(sL2) then sL2 else Double.NaN;
Day2Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day2Low.SetLineWeight(lineWidth);
Day2Low.SetStyle(lineStyle);
Day2Low.SetDefaultColor(colL2);
Plot Day3High = if !IsNaN(sH3) then sH3 else Double.NaN;
Day3High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day3High.SetLineWeight(lineWidth);
Day3High.SetStyle(lineStyle);
Day3High.SetDefaultColor(colH3);
Plot Day3Low = if !IsNaN(sL3) then sL3 else Double.NaN;
Day3Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day3Low.SetLineWeight(lineWidth);
Day3Low.SetStyle(lineStyle);
Day3Low.SetDefaultColor(colL3);
Plot Day4High = if !IsNaN(sH4) then sH4 else Double.NaN;
Day4High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day4High.SetLineWeight(lineWidth);
Day4High.SetStyle(lineStyle);
Day4High.SetDefaultColor(colH4);
Plot Day4Low = if !IsNaN(sL4) then sL4 else Double.NaN;
Day4Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day4Low.SetLineWeight(lineWidth);
Day4Low.SetStyle(lineStyle);
Day4Low.SetDefaultColor(colL4);
Plot Day5High = if !IsNaN(sH5) then sH5 else Double.NaN;
Day5High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day5High.SetLineWeight(lineWidth);
Day5High.SetStyle(lineStyle);
Day5High.SetDefaultColor(colH5);
Plot Day5Low = if !IsNaN(sL5) then sL5 else Double.NaN;
Day5Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day5Low.SetLineWeight(lineWidth);
Day5Low.SetStyle(lineStyle);
Day5Low.SetDefaultColor(colL5);
Last edited by a moderator: