horizontal line between 2 points, based on 2 variables

Matt_S

New member
I've looked at a few different threads and tried some things but I'm struggling to get the output that I desire.

I want to have up a chart for Today and 30 minutes with extended hours on.

I want to plot the Highest(High) between the bar at 18:00 and 19:59. Plot High1 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 19:59. Plot Low1 = ????

I want to plot the Highest(High) between the bar at 18:00 and 0:59. Plot High2 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 0:59. Plot Low2 = ????

I want to plot the Highest(High) between the bar at 18:00 and 4:59. Plot High3 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 4:59. Plot Low3 = ????

I want to plot the Highest(High) between the bar at 18:00 and 9:29. Plot High4 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 9:29. Plot Low4 = ????


Basically I want to plot the High and Low for the first 2 hours and have them plotted from 8pm to 1am
Then I want the High and Low for the first 7 hours and and have them plotted from 1am to 5am
The High and Low from the first 11 hours and and have them plotted from 5am to 930am
The High and Low of the entire overnight range (6pm to 9:30AM) and have them plotted from 9:30am until 5pm.

I want the fib extensions of each range also plotted the same time
So the 1.13%, 1.272%, 1.414%, 1.618%, 2%, and 2.618% extensions up/down for each range.



I do this manually everyday, but figured it's time to have it done automactically for me, but I am really struggling to figure it out.

Looks something like this everyday
 
Last edited by a moderator:

halcyonguy

Well-known member
VIP
Lifetime
I've looked at a few different threads and tried some things but I'm struggling to get the output that I desire.

I want to have up a chart for Today and 30 minutes with extended hours on.

I want to plot the Highest(High) between the bar at 18:00 and 19:59. Plot High1 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 19:59. Plot Low1 = ????

I want to plot the Highest(High) between the bar at 18:00 and 0:59. Plot High2 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 0:59. Plot Low2 = ????

I want to plot the Highest(High) between the bar at 18:00 and 4:59. Plot High3 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 4:59. Plot Low3 = ????

I want to plot the Highest(High) between the bar at 18:00 and 9:29. Plot High4 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 9:29. Plot Low4 = ????


Basically I want to plot the High and Low for the first 2 hours and have them plotted from 8pm to 1am
Then I want the High and Low for the first 7 hours and and have them plotted from 1am to 5am
The High and Low from the first 11 hours and and have them plotted from 5am to 930am
The High and Low of the entire overnight range (6pm to 9:30AM) and have them plotted from 9:30am until 5pm.

I want the fib extensions of each range also plotted the same time
So the 1.13%, 1.272%, 1.414%, 1.618%, 2%, and 2.618% extensions up/down for each range.



I do this manually everyday, but figured it's time to have it done automactically for me, but I am really struggling to figure it out.

Looks something like this everyday

this might help, to show high and low levels , over several time periods
https://usethinkscript.com/threads/average-daily-range-indicator-for-thinkorswim.244/#post-66296
 
Last edited by a moderator:

Matt_S

New member
this might help, to show high and low levels , over several time periods
https://usethinkscript.com/threads/average-daily-range-indicator-for-thinkorswim.244/#post-66296

So I tried to use what I could from that script. I was able to get the Highest High and Lowest Low from 6-8pm, but I can't figure out how to plot it so the line is from 6pm to 1am.


This is what I did with the code so far and added my own desired output.

def SetOneStart = 1800;
def SetOneEnd = 2000;
def na = Double.NaN;
def SetOnehi = high;
def SetOnelo = low;
def bn = BarNumber();
def SetOnelastbar = !isnan(close[0]) and isnan(close[-1]);
def SetOnestart1hr = Floor(SetOneStart / 100);
def SetOnestart1min = SetOneStart - (SetOnestart1hr * 100);
def SetOnestart1minttl = (SetOnestart1hr * 60) + SetOnestart1min;
def SetOneEnd1hr = Floor(SetOneEnd / 100);
def SetOneEnd1min = SetOneEnd - (SetOneend1hr * 100);
def SetOneEnd1minttl = (SetOneEnd1hr * 60) + SetOneEnd1min;
def SetOnestmin2 = SecondsFromTime(SetOneStart);
def SetOnestmin = SetOnestmin2 / (60);
def daymin = 1440;
def endz = 2359;
def startz = 0000;
def SetOnefirst1 = if SecondsTillTime(SetOneStart) == 0 then 1 else 0;
def SetOnelast1 = if SecondsFromTime(SetOneEnd) == 0 then 1 else 0;


def SetOneperiod1min;
def SetOneperiod1;
if SetOnestart1minttl >SetOneend1minttl
then {

SetOneperiod1min = (daymin - SetOnestart1minttl) + SetOneend1minttl;
SetOneperiod1 = if ((SecondsFromTime(SetOneStart) >= 0 and SecondsTillTime(endz) > 0) or ( SecondsFromTime(startz) >= 0 and SecondsTillTime(SetOneEnd) > 0)) then 1 else 0;
} else {

SetOneperiod1min = (SetOneend1minttl - SetOnestart1minttl);
SetOneperiod1 = if SecondsFromTime(SetOneStart) >= 0 and SecondsTillTime(SetOneEnd) > 0 then 1 else 0;
}


def SetOnechagg = GetAggregationPeriod();
def SetOneaggmin = SetOnechagg / (1000 * 60);

def SetOneperiod1bars = SetOneperiod1min / SetOneaggmin;

def SetOnecurrentperiodbars = if (SetOneperiod1 and SetOnelastbar) then (SetOnestmin / SetOneaggmin) else 0;

def SetOnelen = SetOneperiod1bars - 1;
def SetOneHigh = if SetOneFirst1 then Highest(SetOnehi[-SetOnelen], SetOnelen + 1)
else if SetOneLast1 then na
else if SetOneperiod1 then SetOneHigh[1]
else na;

def SetOneLow = if SetOnefirst1 then Lowest(SetOnelo[-SetOnelen], SetOnelen + 1)
else if SetOnelast1 then na
else if SetOneperiod1 then SetOneLow[1]
else na;


def range = SetOneHigh - SetOneLow;
def mid = range / 2;
def Ext1 = range * 1.13;
def Ext2 = range * 1.272;
def Ext3 = range * 1.414;
def Ext4 = range * 1.50;
def Ext5 = range * 1.618;
def Ext6 = range * 2.00;
def Ext7 = range * 2.13;
def Ext8 = range * 2.618;

plot SetOneFib0 = SetOneLow;
SetOneFib0.SetDefaultColor(Color.YELLOW);
SetOneFib0.SetLineWeight(2);
SetOneFib0.HideBubble();

plot SetOneFib50 = RoundDown(SetOneLow + mid, 0) - ((Round(((RoundDown(SetOneLow + mid, 0) - SetOneLow - mid) / 0.25), 0)) * 0.25);
SetOneFib50.SetDefaultColor(Color.YELLOW);
SetOneFib50.SetLineWeight(3);
SetOneFib50.HideBubble();

plot SetOneFib100 = SetOneHigh;
SetOneFib100.SetDefaultColor(Color.Yellow);
#hiline.SetStyle(Curve.MEDIUM_DASH);
SetOneFib100.SetLineWeight(2);
SetOneFib100.HideBubble();

plot SetOneUpExt113 = RoundDown(SetOneLow + Ext1, 0) - ((Round(((RoundDown(SetOneLow + Ext1, 0) - SetOneLow - Ext1) / 0.25), 0)) * 0.25);
SetOneUpExt113.SetDefaultColor(Color.YELLOW);
SetOneUpExt113.SetLineWeight(2);
SetOneUpExt113.HideBubble();

plot SetOneUpExt127 = RoundDown(SetOneLow + Ext2, 0) - ((Round(((RoundDown(SetOneLow+ Ext2, 0) - SetOneLow - Ext2) / 0.25), 0)) * 0.25);
SetOneUpExt127.SetDefaultColor(Color.YELLOW);
SetOneUpExt127.SetLineWeight(2);
SetOneUpExt127.HideBubble();

plot SetOneUpExt141 = RoundDown(SetOneLow+ Ext3, 0) - ((Round(((RoundDown(SetOneLow + Ext3, 0) - SetOneLow - Ext3) / 0.25), 0)) * 0.25);
SetOneUpExt141.SetDefaultColor(Color.YELLOW);
SetOneUpExt141.SetLineWeight(2);
SetOneUpExt141.HideBubble();

plot SetOneUpExt150 = RoundDown(SetOneLow + Ext4, 0) - ((Round(((RoundDown(SetOneLow+ Ext4, 0) - SetOneLow- Ext4) / 0.25), 0)) * 0.25);
SetOneUpExt150.SetDefaultColor(Color.YELLOW);
SetOneUpExt150.SetLineWeight(2);
SetOneUpExt150.HideBubble();

plot SetOneUpExt161 = RoundDown(SetOneLow+ Ext5, 0) - ((Round(((RoundDown(SetOneLow+ Ext5, 0) - SetOneLow - Ext5) / 0.25), 0)) * 0.25);
SetOneUpExt161.SetDefaultColor(Color.YELLOW);
SetOneUpExt161.SetLineWeight(2);
SetOneUpExt161.HideBubble();

plot SetOneUpExt200 = RoundDown(SetOneLow + Ext6, 0) - ((Round(((RoundDown(SetOneLow + Ext6, 0) - SetOneLow - Ext6) / 0.25), 0)) * 0.25);
SetOneUpExt200.SetDefaultColor(Color.YELLOW);
SetOneUpExt200.SetLineWeight(2);
SetOneUpExt200.HideBubble();

plot SetOneUpExt213 = RoundDown(SetOneLow + Ext7, 0) - ((Round(((RoundDown(SetOneLow + Ext7, 0) - SetOneLow - Ext7) / 0.25), 0)) * 0.25);
SetOneUpExt213.SetDefaultColor(Color.YELLOW);
SetOneUpExt213.SetLineWeight(2);
SetOneUpExt213.HideBubble();

plot SetOneUpExt261 = RoundDown(SetOneLow + Ext8, 0) - ((Round(((RoundDown(SetOneLow+ Ext8, 0) - SetOneLow- Ext8) / 0.25), 0)) * 0.25);
SetOneUpExt261.SetDefaultColor(Color.YELLOW);
SetOneUpExt261.SetLineWeight(2);
SetOneUpExt261.HideBubble();

plot SetOneDownExt113 = RoundDown(SetOneHigh - Ext1, 0) - ((Round(((RoundDown(SetOneHigh - Ext1, 0) - SetOneHigh + Ext1) / 0.25), 0)) * 0.25);
SetOneDownExt113.SetDefaultColor(Color.YELLOW);
SetOneDownExt113.SetLineWeight(2);
SetOneDownExt113.HideBubble();

plot SetOneDownExt127 = RoundDown(SetOneHigh - Ext2, 0) - ((Round(((RoundDown(SetOneHigh - Ext2, 0) - SetOneHigh + Ext2) / 0.25), 0)) * 0.25);
SetOneDownExt127.SetDefaultColor(Color.YELLOW);
SetOneDownExt127.SetLineWeight(2);
SetOneDownExt127.HideBubble();

plot SetOneDownExt141 = RoundDown(SetOneHigh - Ext3, 0) - ((Round(((RoundDown(SetOneHigh- Ext3, 0) - SetOneHigh + Ext3) / 0.25), 0)) * 0.25);
SetOneDownExt141.SetDefaultColor(Color.YELLOW);
SetOneDownExt141.SetLineWeight(2);
SetOneDownExt141.HideBubble();

plot SetOneDownExt150 = RoundDown(SetOneHigh - Ext4, 0) - ((Round(((RoundDown(SetOneHigh - Ext4, 0) - SetOneHigh + Ext4) / 0.25), 0)) * 0.25);
SetOneDownExt150.SetDefaultColor(Color.YELLOW);
SetOneDownExt150.SetLineWeight(2);
SetOneDownExt150.HideBubble();

plot SetOneDownExt161 = RoundDown(SetOneHigh - Ext5, 0) - ((Round(((RoundDown(SetOneHigh - Ext5, 0) - SetOneHigh + Ext5) / 0.25), 0)) * 0.25);
SetOneDownExt161.SetDefaultColor(Color.YELLOW);
SetOneDownExt161.SetLineWeight(2);
SetOneDownExt161.HideBubble();

plot SetOneDownExt200 = RoundDown(SetOneHigh - Ext6, 0) - ((Round(((RoundDown(SetOneHigh - Ext6, 0) - SetOneHigh + Ext6) / 0.25), 0)) * 0.25);
SetOneDownExt200.SetDefaultColor(Color.YELLOW);
SetOneDownExt200.SetLineWeight(2);
SetOneDownExt200.HideBubble();

plot SetOneDownExt213 = RoundDown(SetOneHigh - Ext7, 0) - ((Round(((RoundDown(SetOneHigh - Ext7, 0) - SetOneHigh + Ext7) / 0.25), 0)) * 0.25);
SetOneDownExt213.SetDefaultColor(Color.YELLOW);
SetOneDownExt213.SetLineWeight(2);
SetOneDownExt213.HideBubble();

plot SetOneDownExt261 = RoundDown(SetOneHigh - Ext8, 0) - ((Round(((RoundDown(SetOneHigh- Ext8, 0) - SetOneHigh + Ext8) / 0.25), 0)) * 0.25);
SetOneDownExt261.SetDefaultColor(Color.YELLOW);
SetOneDownExt261.SetLineWeight(2);
SetOneDownExt261.HideBubble();


What it looks like at the moment

What I want it to look like
 
Last edited:

halcyonguy

Well-known member
VIP
Lifetime
I've looked at a few different threads and tried some things but I'm struggling to get the output that I desire.

I want to have up a chart for Today and 30 minutes with extended hours on.

I want to plot the Highest(High) between the bar at 18:00 and 19:59. Plot High1 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 19:59. Plot Low1 = ????

I want to plot the Highest(High) between the bar at 18:00 and 0:59. Plot High2 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 0:59. Plot Low2 = ????

I want to plot the Highest(High) between the bar at 18:00 and 4:59. Plot High3 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 4:59. Plot Low3 = ????

I want to plot the Highest(High) between the bar at 18:00 and 9:29. Plot High4 = ????
I want to plot the Lowest(Low) between the bar at 18:00 and 9:29. Plot Low4 = ????


Basically I want to plot the High and Low for the first 2 hours and have them plotted from 8pm to 1am
Then I want the High and Low for the first 7 hours and and have them plotted from 1am to 5am
The High and Low from the first 11 hours and and have them plotted from 5am to 930am
The High and Low of the entire overnight range (6pm to 9:30AM) and have them plotted from 9:30am until 5pm.

I want the fib extensions of each range also plotted the same time
So the 1.13%, 1.272%, 1.414%, 1.618%, 2%, and 2.618% extensions up/down for each range.



I do this manually everyday, but figured it's time to have it done automactically for me, but I am really struggling to figure it out.

Looks something like this everyday

i just reread your post again, several times, and i'm still confused.

i don't know what these are refering to?
first 2 hours, first 7, first 12,...

all you have to say is, specific start and stop times,
for reading data,
and for plotting data.

-----------

copy this part and fill in with your desired start and stop times, for each time period.

find the high and low during this time period,
x:xx to y:yy
and plot lines during this time period,
k:kk to m:mm
 

halcyonguy

Well-known member
VIP
Lifetime
So I tried to use what I could from that script. I was able to get the Highest High and Lowest Low from 6-8pm, but I can't figure out how to plot it so the line is from 6pm to 1am.


This is what I did with the code so far and added my own desired output.

def SetOneStart = 1800;
def SetOneEnd = 2000;
def na = Double.NaN;
def SetOnehi = high;
def SetOnelo = low;
def bn = BarNumber();
def SetOnelastbar = !isnan(close[0]) and isnan(close[-1]);
def SetOnestart1hr = Floor(SetOneStart / 100);
def SetOnestart1min = SetOneStart - (SetOnestart1hr * 100);
def SetOnestart1minttl = (SetOnestart1hr * 60) + SetOnestart1min;
def SetOneEnd1hr = Floor(SetOneEnd / 100);
def SetOneEnd1min = SetOneEnd - (SetOneend1hr * 100);
def SetOneEnd1minttl = (SetOneEnd1hr * 60) + SetOneEnd1min;
def SetOnestmin2 = SecondsFromTime(SetOneStart);
def SetOnestmin = SetOnestmin2 / (60);
def daymin = 1440;
def endz = 2359;
def startz = 0000;
def SetOnefirst1 = if SecondsTillTime(SetOneStart) == 0 then 1 else 0;
def SetOnelast1 = if SecondsFromTime(SetOneEnd) == 0 then 1 else 0;


def SetOneperiod1min;
def SetOneperiod1;
if SetOnestart1minttl >SetOneend1minttl
then {

SetOneperiod1min = (daymin - SetOnestart1minttl) + SetOneend1minttl;
SetOneperiod1 = if ((SecondsFromTime(SetOneStart) >= 0 and SecondsTillTime(endz) > 0) or ( SecondsFromTime(startz) >= 0 and SecondsTillTime(SetOneEnd) > 0)) then 1 else 0;
} else {

SetOneperiod1min = (SetOneend1minttl - SetOnestart1minttl);
SetOneperiod1 = if SecondsFromTime(SetOneStart) >= 0 and SecondsTillTime(SetOneEnd) > 0 then 1 else 0;
}


def SetOnechagg = GetAggregationPeriod();
def SetOneaggmin = SetOnechagg / (1000 * 60);

def SetOneperiod1bars = SetOneperiod1min / SetOneaggmin;

def SetOnecurrentperiodbars = if (SetOneperiod1 and SetOnelastbar) then (SetOnestmin / SetOneaggmin) else 0;

def SetOnelen = SetOneperiod1bars - 1;
def SetOneHigh = if SetOneFirst1 then Highest(SetOnehi[-SetOnelen], SetOnelen + 1)
else if SetOneLast1 then na
else if SetOneperiod1 then SetOneHigh[1]
else na;

def SetOneLow = if SetOnefirst1 then Lowest(SetOnelo[-SetOnelen], SetOnelen + 1)
else if SetOnelast1 then na
else if SetOneperiod1 then SetOneLow[1]
else na;


def range = SetOneHigh - SetOneLow;
def mid = range / 2;
def Ext1 = range * 1.13;
def Ext2 = range * 1.272;
def Ext3 = range * 1.414;
def Ext4 = range * 1.50;
def Ext5 = range * 1.618;
def Ext6 = range * 2.00;
def Ext7 = range * 2.13;
def Ext8 = range * 2.618;

plot SetOneFib0 = SetOneLow;
SetOneFib0.SetDefaultColor(Color.YELLOW);
SetOneFib0.SetLineWeight(2);
SetOneFib0.HideBubble();

plot SetOneFib50 = RoundDown(SetOneLow + mid, 0) - ((Round(((RoundDown(SetOneLow + mid, 0) - SetOneLow - mid) / 0.25), 0)) * 0.25);
SetOneFib50.SetDefaultColor(Color.YELLOW);
SetOneFib50.SetLineWeight(3);
SetOneFib50.HideBubble();

plot SetOneFib100 = SetOneHigh;
SetOneFib100.SetDefaultColor(Color.Yellow);
#hiline.SetStyle(Curve.MEDIUM_DASH);
SetOneFib100.SetLineWeight(2);
SetOneFib100.HideBubble();

plot SetOneUpExt113 = RoundDown(SetOneLow + Ext1, 0) - ((Round(((RoundDown(SetOneLow + Ext1, 0) - SetOneLow - Ext1) / 0.25), 0)) * 0.25);
SetOneUpExt113.SetDefaultColor(Color.YELLOW);
SetOneUpExt113.SetLineWeight(2);
SetOneUpExt113.HideBubble();

plot SetOneUpExt127 = RoundDown(SetOneLow + Ext2, 0) - ((Round(((RoundDown(SetOneLow+ Ext2, 0) - SetOneLow - Ext2) / 0.25), 0)) * 0.25);
SetOneUpExt127.SetDefaultColor(Color.YELLOW);
SetOneUpExt127.SetLineWeight(2);
SetOneUpExt127.HideBubble();

plot SetOneUpExt141 = RoundDown(SetOneLow+ Ext3, 0) - ((Round(((RoundDown(SetOneLow + Ext3, 0) - SetOneLow - Ext3) / 0.25), 0)) * 0.25);
SetOneUpExt141.SetDefaultColor(Color.YELLOW);
SetOneUpExt141.SetLineWeight(2);
SetOneUpExt141.HideBubble();

plot SetOneUpExt150 = RoundDown(SetOneLow + Ext4, 0) - ((Round(((RoundDown(SetOneLow+ Ext4, 0) - SetOneLow- Ext4) / 0.25), 0)) * 0.25);
SetOneUpExt150.SetDefaultColor(Color.YELLOW);
SetOneUpExt150.SetLineWeight(2);
SetOneUpExt150.HideBubble();

plot SetOneUpExt161 = RoundDown(SetOneLow+ Ext5, 0) - ((Round(((RoundDown(SetOneLow+ Ext5, 0) - SetOneLow - Ext5) / 0.25), 0)) * 0.25);
SetOneUpExt161.SetDefaultColor(Color.YELLOW);
SetOneUpExt161.SetLineWeight(2);
SetOneUpExt161.HideBubble();

plot SetOneUpExt200 = RoundDown(SetOneLow + Ext6, 0) - ((Round(((RoundDown(SetOneLow + Ext6, 0) - SetOneLow - Ext6) / 0.25), 0)) * 0.25);
SetOneUpExt200.SetDefaultColor(Color.YELLOW);
SetOneUpExt200.SetLineWeight(2);
SetOneUpExt200.HideBubble();

plot SetOneUpExt213 = RoundDown(SetOneLow + Ext7, 0) - ((Round(((RoundDown(SetOneLow + Ext7, 0) - SetOneLow - Ext7) / 0.25), 0)) * 0.25);
SetOneUpExt213.SetDefaultColor(Color.YELLOW);
SetOneUpExt213.SetLineWeight(2);
SetOneUpExt213.HideBubble();

plot SetOneUpExt261 = RoundDown(SetOneLow + Ext8, 0) - ((Round(((RoundDown(SetOneLow+ Ext8, 0) - SetOneLow- Ext8) / 0.25), 0)) * 0.25);
SetOneUpExt261.SetDefaultColor(Color.YELLOW);
SetOneUpExt261.SetLineWeight(2);
SetOneUpExt261.HideBubble();

plot SetOneDownExt113 = RoundDown(SetOneHigh - Ext1, 0) - ((Round(((RoundDown(SetOneHigh - Ext1, 0) - SetOneHigh + Ext1) / 0.25), 0)) * 0.25);
SetOneDownExt113.SetDefaultColor(Color.YELLOW);
SetOneDownExt113.SetLineWeight(2);
SetOneDownExt113.HideBubble();

plot SetOneDownExt127 = RoundDown(SetOneHigh - Ext2, 0) - ((Round(((RoundDown(SetOneHigh - Ext2, 0) - SetOneHigh + Ext2) / 0.25), 0)) * 0.25);
SetOneDownExt127.SetDefaultColor(Color.YELLOW);
SetOneDownExt127.SetLineWeight(2);
SetOneDownExt127.HideBubble();

plot SetOneDownExt141 = RoundDown(SetOneHigh - Ext3, 0) - ((Round(((RoundDown(SetOneHigh- Ext3, 0) - SetOneHigh + Ext3) / 0.25), 0)) * 0.25);
SetOneDownExt141.SetDefaultColor(Color.YELLOW);
SetOneDownExt141.SetLineWeight(2);
SetOneDownExt141.HideBubble();

plot SetOneDownExt150 = RoundDown(SetOneHigh - Ext4, 0) - ((Round(((RoundDown(SetOneHigh - Ext4, 0) - SetOneHigh + Ext4) / 0.25), 0)) * 0.25);
SetOneDownExt150.SetDefaultColor(Color.YELLOW);
SetOneDownExt150.SetLineWeight(2);
SetOneDownExt150.HideBubble();

plot SetOneDownExt161 = RoundDown(SetOneHigh - Ext5, 0) - ((Round(((RoundDown(SetOneHigh - Ext5, 0) - SetOneHigh + Ext5) / 0.25), 0)) * 0.25);
SetOneDownExt161.SetDefaultColor(Color.YELLOW);
SetOneDownExt161.SetLineWeight(2);
SetOneDownExt161.HideBubble();

plot SetOneDownExt200 = RoundDown(SetOneHigh - Ext6, 0) - ((Round(((RoundDown(SetOneHigh - Ext6, 0) - SetOneHigh + Ext6) / 0.25), 0)) * 0.25);
SetOneDownExt200.SetDefaultColor(Color.YELLOW);
SetOneDownExt200.SetLineWeight(2);
SetOneDownExt200.HideBubble();

plot SetOneDownExt213 = RoundDown(SetOneHigh - Ext7, 0) - ((Round(((RoundDown(SetOneHigh - Ext7, 0) - SetOneHigh + Ext7) / 0.25), 0)) * 0.25);
SetOneDownExt213.SetDefaultColor(Color.YELLOW);
SetOneDownExt213.SetLineWeight(2);
SetOneDownExt213.HideBubble();

plot SetOneDownExt261 = RoundDown(SetOneHigh - Ext8, 0) - ((Round(((RoundDown(SetOneHigh- Ext8, 0) - SetOneHigh + Ext8) / 0.25), 0)) * 0.25);
SetOneDownExt261.SetDefaultColor(Color.YELLOW);
SetOneDownExt261.SetLineWeight(2);
SetOneDownExt261.HideBubble();


What it looks like at the moment

What I want it to look like



this will,
..read highest/lowest price levels from 4 time periods, each day.
..can plot lines at the highest/lowest levels, during a different plot period, or during the hi/lo period
..can span midmight
..labels to show time periods
..can show a vertical line at midnight

tested with /ES and entended hours on


Ruby:
# hilo_in_time_periods_01

#-----------------------
# halcyonguy
# 22-11-24
# plot hi lo lines, from 4 time periods, ea day. can span midmight
# plot lines during different plot periods, or during the hi/lo periods
#-----------------------

# https://usethinkscript.com/threads/horizontal-line-between-2-points-based-on-2-variables.13423/
#I want to have up a chart for Today and 30 minutes with extended hours on.

# period1 , read  hi lo  between 18:00 and 19:59 , 6pm to 8pm
# period2 , read  hi lo  between 18:00 and 0:59  , 6pm to 1am
# period3 , read  hi lo  between 18:00 and 4:59  , 6pm to 5am
# period4 , read  hi lo  between 18:00 and 9:29  , 6pm to 9:30am

# plot period1 at - 8pm to 1am    , 20:00 to 1:00
# plot period2 at - 1am to 5am    , 1:00 to 5:00
# plot period3 at - 5am to 930am  , 5:00 to 9:30
# plot period4 at - 9:30am to 5pm , 9:30 to 17:00


declare hide_on_daily;

def na = Double.NaN;
def hi = high;
def lo = low;
def bn = BarNumber();

input read_start1 = 1800;
input read_stop1 = 2000;
input read_start2 = 1800;
input read_stop2 = 0100;
input read_start3 = 1800;
input read_stop3 = 0500;
input read_start4 = 1800;
input read_stop4 = 0930;

def rfirst1 = if secondstillTime(read_start1)[1] > 0 and secondsfromTime(read_start1) >= 0 then 1 else 0;
def rfirst2 = if secondstillTime(read_start2)[1] > 0 and secondsfromTime(read_start2) >= 0 then 1 else 0;
def rfirst3 = if secondstillTime(read_start3)[1] > 0 and secondsfromTime(read_start3) >= 0 then 1 else 0;
def rfirst4 = if secondstillTime(read_start4)[1] > 0 and secondsfromTime(read_start4) >= 0 then 1 else 0;


input plot_start1 = 2000;
input plot_stop1 = 0100;
input plot_start2 = 0100;
input plot_stop2 = 0500;
input plot_start3 = 0500;
input plot_stop3 = 0930;
input plot_start4 = 0930;
input plot_stop4 = 1700;

def pfirst1 = if secondstillTime(plot_start1)[1] > 0 and secondsfromTime(plot_start1) >= 0 then 1 else 0;
def pfirst2 = if secondstillTime(plot_start2)[1] > 0 and secondsfromTime(plot_start2) >= 0 then 1 else 0;
def pfirst3 = if secondstillTime(plot_start3)[1] > 0 and secondsfromTime(plot_start3) >= 0 then 1 else 0;
def pfirst4 = if secondstillTime(plot_start4)[1] > 0 and secondsfromTime(plot_start4) >= 0 then 1 else 0;

#------------------------------------------------------

# show labels - start / stop times
input labels_read_times = yes;
addlabel(labels_read_times, " " , color.black);
addlabel(labels_read_times, ("Read 1 " + asprice(read_start1) + " to " + asprice(read_stop1)), color.magenta);
addlabel(labels_read_times, ("Read 2 " + asprice(read_start2) + " to " + asprice(read_stop2)), color.magenta);
addlabel(labels_read_times, ("Read 3 " + asprice(read_start3) + " to " + asprice(read_stop3)), color.magenta);
addlabel(labels_read_times, ("Read 4 " + asprice(read_start4) + " to " + asprice(read_stop4)), color.magenta);

addlabel(labels_read_times, " " , color.black);
input labels_plot_times = yes;
addlabel(labels_plot_times, ("plot 1 " + asprice(plot_start1) + " to " + asprice(plot_stop1)), color.yellow);
addlabel(labels_plot_times, ("plot 2 " + asprice(plot_start2) + " to " + asprice(plot_stop2)), color.yellow);
addlabel(labels_plot_times, ("plot 3 " + asprice(plot_start3) + " to " + asprice(plot_stop3)), color.yellow);
addlabel(labels_plot_times, ("plot 4 " + asprice(plot_start4) + " to " + asprice(plot_stop4)), color.yellow);
addlabel(labels_read_times, " " , color.black);


#------------------------------------------------------

# check if current bar is between 2 times of a day
script inperiod {

input start = 0;
input stop = 0;
def daymin = 1440;
def endz = 2359;
def startz = 0000;

def period1;
if start > stop {
  # spans midnight , period=(24-start)+end , end to start
  # period1min = (daymin - start1minttl) + end1minttl;
  period1 = if ((SecondsFromTime(start) >= 0 and SecondsTillTime(endz) > 0) or (SecondsFromTime(startz) >= 0 and SecondsTillTime(stop) > 0)) then 1 else 0;
} else {
  # ok , period=end-start , start to end
  # period1min = (end1minttl - start1minttl);
  period1 = if SecondsFromTime(start) >= 0 and SecondsTillTime(stop) > 0 then 1 else 0;
}

plot inperiod = period1;
}


# is bar within a read period?  read period 1,2,3,4
def rp1 = inperiod(read_start1, read_stop1);
def rp2 = inperiod(read_start2, read_stop2);
def rp3 = inperiod(read_start3, read_stop3);
def rp4 = inperiod(read_start4, read_stop4);


# is bar within a plot period?  plot period 1,2,3,4
def pp1 = inperiod(plot_start1, plot_stop1);
def pp2 = inperiod(plot_start2, plot_stop2);
def pp3 = inperiod(plot_start3, plot_stop3);
def pp4 = inperiod(plot_start4, plot_stop4);

#-----------------------------


# find the highest in a time period, from the 1st bar in a period
script read_hi {
input rfirstx = 0;
input rpx = 0;
def rxhi = if rfirstx then
  fold j = 0 to 1440
  with k
  while getvalue(rpx, -j)
  do (if getvalue(high, -j) > k then getvalue(high, -j) else k)
else rxhi[1];
plot hix = rxhi;
}


# find the lowest in a time period, from the 1st bar in a period
script read_lo {
input rfirstx = 0;
input rpx = 0;
def rxlo = if rfirstx then
  fold j = 0 to 1440
  with k = 99999
  while getvalue(rpx, -j)
  do (if getvalue(low, -j) < k then getvalue(low, -j) else k)
else rxlo[1];
plot lox = rxlo;
}


#------------------------------

def r1hi = read_hi(rfirst1, rp1);
def r2hi = read_hi(rfirst2, rp2);
def r3hi = read_hi(rfirst3, rp3);
def r4hi = read_hi(rfirst4, rp4);

def r1lo = read_lo(rfirst1, rp1);
def r2lo = read_lo(rfirst2, rp2);
def r3lo = read_lo(rfirst3, rp3);
def r4lo = read_lo(rfirst4, rp4);

#---------------------------------

input plot_time = { default plot_period , read_hilow_period };

def pt;
switch(plot_time) {
case plot_period:
  pt = 1;
case read_hilow_period:
  pt = 2;
}

#---------------------------------
# color #
def c = 0;

# plot line , with hi lo from read period
def p1hi = if pt == 1 and pfirst1 then r1hi
  else if pt == 1 and pp1 then p1hi[1]
  else if pt == 2 and rfirst1 then r1hi
  else if pt == 2 and rp1 then p1hi[1]
  else na;
plot zp1hi = p1hi;
zp1hi.SetDefaultColor(getcolor(c+0));

def p1lo = if pt == 1 and pfirst1 then r1lo
  else if pt == 1 and pp1 then p1lo[1]
  else if pt == 2 and rfirst1 then r1lo
  else if pt == 2 and rp1 then p1lo[1]
  else na;
plot zp1lo = p1lo;
zp1lo.SetDefaultColor(getcolor(c+0));

def p2hi = if pt == 1 and pfirst2 then r2hi
  else if pt == 1 and pp2 then p2hi[1]
  else if pt == 2 and rfirst2 then r2hi
  else if pt == 2 and rp2 then p2hi[1]
  else na;
plot zp2hi = p2hi;
zp2hi.SetDefaultColor(getcolor(c+1));

def p2lo = if pt == 1 and pfirst2 then r2lo
  else if pt == 1 and pp2 then p2lo[1]
  else if pt == 2 and rfirst2 then r2lo
  else if pt == 2 and rp2 then p2lo[1]
  else na;
plot zp2lo = p2lo;
zp2lo.SetDefaultColor(getcolor(c+1));

def p3hi = if pt == 1 and pfirst3 then r3hi
  else if pt == 1 and pp3 then p3hi[1]
  else if pt == 2 and rfirst3 then r3hi
  else if pt == 2 and rp3 then p3hi[1]
  else na;
plot zp3hi = p3hi;
zp3hi.SetDefaultColor(getcolor(c+2));

def p3lo = if pt == 1 and pfirst3 then r3lo
  else if pt == 1 and pp3 then p3lo[1]
  else if pt == 2 and rfirst3 then r3lo
  else if pt == 2 and rp3 then p3lo[1]
  else na;
plot zp3lo = p3lo;
zp3lo.SetDefaultColor(getcolor(c+2));

def p4hi = if pt == 1 and pfirst4 then r4hi
  else if pt == 1 and pp4 then p4hi[1]
  else if pt == 2 and rfirst4 then r4hi
  else if pt == 2 and rp4 then p4hi[1]
  else na;
plot zp4hi = p4hi;
zp4hi.SetDefaultColor(getcolor(c+3));

def p4lo = if pt == 1 and pfirst4 then r4lo
  else if pt == 1 and pp4 then p4lo[1]
  else if pt == 2 and rfirst4 then r4lo
  else if pt == 2 and rp4 then p4lo[1]
  else na;
plot zp4lo = p4lo;
zp4lo.SetDefaultColor(getcolor(c+3));

#-------------------------

input show_midnight_vertical_line = no;
def smvl = show_midnight_vertical_line;
# midnight
def midn = 0000;
def midnite = if (smvl and SecondsTillTime(midn) == 0) then 1 else 0;
AddVerticalLine(midnite, "midnight" , Color.BLUE, Curve.MEDIUM_DASH);
#

'read' high/low from 4 time periods.
plot lines during plot periods
l7GHeSz.jpg
 
Last edited:

Matt_S

New member
working on something.....
copy this part and fill in with your desired start and stop times, for each time period.


find the high and low during this time period,
x:xx to y:yy
and plot lines during this time period,
k:kk to m:mm

find the high and low during this time period,
18:00 to 19:59
and plot lines during this time period,
18:00 to 00:45


find the high and low during this time period,
18:00 to 00:59
and plot lines during this time period,
01:00 to 04:45

find the high and low during this time period,
18:00 to 04:59
and plot lines during this time period,
05:00 to 09:15

find the high and low during this time period,
18:00 to 09:29
and plot lines during this time period,
9:30 to 17:59
 

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.
Top