DailyPivotLines_StrengthColored

Josec

New member
VIP
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!
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:
Solution
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...
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!
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);
Code:
# DailyPivotLines_StrengthColored_FIXED
declare upper;

input pivotLen = 2;
input proximityTicks = 2;
input maxCountForScale = 12;
input showLines = yes;
input lineWidth = 2;

def bn = BarNumber();
def day = GetYYYYMMDD();
def isNewDay = day != day[1];
def tick = TickSize();

# Confirmed non-repaint pivots
def pivotHigh =
    high[pivotLen] == Highest(high, pivotLen * 2 + 1);

def pivotLow =
    low[pivotLen] == Lowest(low, pivotLen * 2 + 1);

def pivotHighVal = high[pivotLen];
def pivotLowVal  = low[pivotLen];
def pivotBarVal  = bn - pivotLen;

# Track best pivot high/low inside current day
rec dayHighVal =
    if bn == 1 or isNewDay then
        if pivotHigh then pivotHighVal else Double.NaN
    else if pivotHigh and (IsNaN(dayHighVal[1]) or pivotHighVal > dayHighVal[1]) then
        pivotHighVal
    else dayHighVal[1];

rec dayLowVal =
    if bn == 1 or isNewDay then
        if pivotLow then pivotLowVal else Double.NaN
    else if pivotLow and (IsNaN(dayLowVal[1]) or pivotLowVal < dayLowVal[1]) then
        pivotLowVal
    else dayLowVal[1];

# Store prior 5 completed days
rec sH1 = if bn == 1 then Double.NaN else if isNewDay then dayHighVal[1] else sH1[1];
rec sL1 = if bn == 1 then Double.NaN else if isNewDay then dayLowVal[1] else sL1[1];

rec sH2 = if bn == 1 then Double.NaN else if isNewDay then sH1[1] else sH2[1];
rec sL2 = if bn == 1 then Double.NaN else if isNewDay then sL1[1] else sL2[1];

rec sH3 = if bn == 1 then Double.NaN else if isNewDay then sH2[1] else sH3[1];
rec sL3 = if bn == 1 then Double.NaN else if isNewDay then sL2[1] else sL3[1];

rec sH4 = if bn == 1 then Double.NaN else if isNewDay then sH3[1] else sH4[1];
rec sL4 = if bn == 1 then Double.NaN else if isNewDay then sL3[1] else sL4[1];

rec sH5 = if bn == 1 then Double.NaN else if isNewDay then sH4[1] else sH5[1];
rec sL5 = if bn == 1 then Double.NaN else if isNewDay then sL4[1] else sL5[1];

# Touch counting
def prox = proximityTicks * tick;

def tH1 = !IsNaN(sH1) and AbsValue(close - sH1) <= prox;
def tL1 = !IsNaN(sL1) and AbsValue(close - sL1) <= prox;
def tH2 = !IsNaN(sH2) and AbsValue(close - sH2) <= prox;
def tL2 = !IsNaN(sL2) and AbsValue(close - sL2) <= prox;
def tH3 = !IsNaN(sH3) and AbsValue(close - sH3) <= prox;
def tL3 = !IsNaN(sL3) and AbsValue(close - sL3) <= prox;
def tH4 = !IsNaN(sH4) and AbsValue(close - sH4) <= prox;
def tL4 = !IsNaN(sL4) and AbsValue(close - sL4) <= prox;
def tH5 = !IsNaN(sH5) and AbsValue(close - sH5) <= prox;
def tL5 = !IsNaN(sL5) and AbsValue(close - sL5) <= prox;

rec cH1 = if bn == 1 then 0 else if isNewDay then 0 else cH1[1] + if tH1 then 1 else 0;
rec cL1 = if bn == 1 then 0 else if isNewDay then 0 else cL1[1] + if tL1 then 1 else 0;

rec cH2 = if bn == 1 then 0 else if isNewDay then cH1[1] else cH2[1] + if tH2 then 1 else 0;
rec cL2 = if bn == 1 then 0 else if isNewDay then cL1[1] else cL2[1] + if tL2 then 1 else 0;

rec cH3 = if bn == 1 then 0 else if isNewDay then cH2[1] else cH3[1] + if tH3 then 1 else 0;
rec cL3 = if bn == 1 then 0 else if isNewDay then cL2[1] else cL3[1] + if tL3 then 1 else 0;

rec cH4 = if bn == 1 then 0 else if isNewDay then cH3[1] else cH4[1] + if tH4 then 1 else 0;
rec cL4 = if bn == 1 then 0 else if isNewDay then cL3[1] else cL4[1] + if tL4 then 1 else 0;

rec cH5 = if bn == 1 then 0 else if isNewDay then cH4[1] else cH5[1] + if tH5 then 1 else 0;
rec cL5 = if bn == 1 then 0 else if isNewDay then cL4[1] else cL5[1] + if tL5 then 1 else 0;

script Bucket {
    input count = 0;
    input maxForScale = 12;
    def capped = Min(count, maxForScale);
    plot b = Round(6 - (capped / maxForScale) * 5, 0);
}

def bH1 = Bucket(cH1, maxCountForScale);
def bL1 = Bucket(cL1, maxCountForScale);
def bH2 = Bucket(cH2, maxCountForScale);
def bL2 = Bucket(cL2, maxCountForScale);
def bH3 = Bucket(cH3, maxCountForScale);
def bL3 = Bucket(cL3, maxCountForScale);
def bH4 = Bucket(cH4, maxCountForScale);
def bL4 = Bucket(cL4, maxCountForScale);
def bH5 = Bucket(cH5, maxCountForScale);
def bL5 = Bucket(cL5, maxCountForScale);

plot Day1High = if showLines then sH1 else Double.NaN;
plot Day1Low  = if showLines then sL1 else Double.NaN;
plot Day2High = if showLines then sH2 else Double.NaN;
plot Day2Low  = if showLines then sL2 else Double.NaN;
plot Day3High = if showLines then sH3 else Double.NaN;
plot Day3Low  = if showLines then sL3 else Double.NaN;
plot Day4High = if showLines then sH4 else Double.NaN;
plot Day4Low  = if showLines then sL4 else Double.NaN;
plot Day5High = if showLines then sH5 else Double.NaN;
plot Day5Low  = if showLines then sL5 else Double.NaN;

Day1High.SetStyle(Curve.SHORT_DASH);
Day1Low.SetStyle(Curve.SHORT_DASH);
Day2High.SetStyle(Curve.SHORT_DASH);
Day2Low.SetStyle(Curve.SHORT_DASH);
Day3High.SetStyle(Curve.SHORT_DASH);
Day3Low.SetStyle(Curve.SHORT_DASH);
Day4High.SetStyle(Curve.SHORT_DASH);
Day4Low.SetStyle(Curve.SHORT_DASH);
Day5High.SetStyle(Curve.SHORT_DASH);
Day5Low.SetStyle(Curve.SHORT_DASH);

Day1High.SetLineWeight(lineWidth);
Day1Low.SetLineWeight(lineWidth);
Day2High.SetLineWeight(lineWidth);
Day2Low.SetLineWeight(lineWidth);
Day3High.SetLineWeight(lineWidth);
Day3Low.SetLineWeight(lineWidth);
Day4High.SetLineWeight(lineWidth);
Day4Low.SetLineWeight(lineWidth);
Day5High.SetLineWeight(lineWidth);
Day5Low.SetLineWeight(lineWidth);

Day1High.AssignValueColor(if bH1 <= 1 then Color.RED else if bH1 == 2 then Color.ORANGE else if bH1 == 3 then Color.YELLOW else if bH1 == 4 then Color.GREEN else if bH1 == 5 then Color.BLUE else Color.VIOLET);
Day1Low.AssignValueColor(if bL1 <= 1 then Color.RED else if bL1 == 2 then Color.ORANGE else if bL1 == 3 then Color.YELLOW else if bL1 == 4 then Color.GREEN else if bL1 == 5 then Color.BLUE else Color.VIOLET);

Day2High.AssignValueColor(if bH2 <= 1 then Color.RED else if bH2 == 2 then Color.ORANGE else if bH2 == 3 then Color.YELLOW else if bH2 == 4 then Color.GREEN else if bH2 == 5 then Color.BLUE else Color.VIOLET);
Day2Low.AssignValueColor(if bL2 <= 1 then Color.RED else if bL2 == 2 then Color.ORANGE else if bL2 == 3 then Color.YELLOW else if bL2 == 4 then Color.GREEN else if bL2 == 5 then Color.BLUE else Color.VIOLET);

Day3High.AssignValueColor(if bH3 <= 1 then Color.RED else if bH3 == 2 then Color.ORANGE else if bH3 == 3 then Color.YELLOW else if bH3 == 4 then Color.GREEN else if bH3 == 5 then Color.BLUE else Color.VIOLET);
Day3Low.AssignValueColor(if bL3 <= 1 then Color.RED else if bL3 == 2 then Color.ORANGE else if bL3 == 3 then Color.YELLOW else if bL3 == 4 then Color.GREEN else if bL3 == 5 then Color.BLUE else Color.VIOLET);

Day4High.AssignValueColor(if bH4 <= 1 then Color.RED else if bH4 == 2 then Color.ORANGE else if bH4 == 3 then Color.YELLOW else if bH4 == 4 then Color.GREEN else if bH4 == 5 then Color.BLUE else Color.VIOLET);
Day4Low.AssignValueColor(if bL4 <= 1 then Color.RED else if bL4 == 2 then Color.ORANGE else if bL4 == 3 then Color.YELLOW else if bL4 == 4 then Color.GREEN else if bL4 == 5 then Color.BLUE else Color.VIOLET);

Day5High.AssignValueColor(if bH5 <= 1 then Color.RED else if bH5 == 2 then Color.ORANGE else if bH5 == 3 then Color.YELLOW else if bH5 == 4 then Color.GREEN else if bH5 == 5 then Color.BLUE else Color.VIOLET);
Day5Low.AssignValueColor(if bL5 <= 1 then Color.RED else if bL5 == 2 then Color.ORANGE else if bL5 == 3 then Color.YELLOW else if bL5 == 4 then Color.GREEN else if bL5 == 5 then Color.BLUE else Color.VIOLET);

AddLabel(yes, "Pivot Strength Lines | Red = strongest touch count", Color.WHITE);
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
1792 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top