ONH-ONL

Gmoyano81

New member
I just got this code for ONH_ONL but this just for a HIGH values. I've tried to add the code for ONL but I cannot make it =( . Please help!




script onh_ {
input daysback = 1;

def ymd = SecondsFromTime(1600) >= 0 or SecondsTillTime(0930) > 0;
def candles = !IsNaN(close);
def capture = ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;

input PlotOverNightExtremes = yes;
input DisplayPriceBubbleOnHiLowBar = yes;
input DisplayPriceBubbleOnRightEdge = yes;

def o = open; def h = high; def l = low; def c = close;

def Post = thisday==daysback and secondsFromTime(1600);
def Pre = thisday==daysback and secondsTillTime(930);
def Closed = thisday==daysback and (Post >=0 or Pre>=0);

def bar = BarNumber();
def GlobeX = thisday==daysback and Closed;# GetTime() < RegularTradingStart(GetYYYYMMDD());

def ONhigh = if thisday==daysback and GlobeX and !GlobeX[1] then h else
if thisday==daysback and GlobeX and h > ONhigh[1] then h else ONhigh[1];

def ONhighBar = if thisday==daysback and GlobeX and h == ONhigh then bar else Double.NaN;

def OverNightHigh = if thisday==daysback and BarNumber() == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];

plot ONH = if thisday <= daysback and OverNightHigh > 1 then OverNightHigh else Double.NaN;
###
def ONlow = if thisday==daysback and GlobeX and !GlobeX[1] then l else
if thisday==daysback and GlobeX and l < ONlow[1] then l else ONlow[1];

def ONlowBar = if thisday==daysback and GlobeX and l == ONlow then bar else Double.NaN;

def OverNightLOW = if thisday==daysback and BarNumber() == LOWestAll(ONLOWBar) then ONlow else OverNightlow[1];
plot ONL = if thisday >= daysback and OverNightLOW > 1 then OverNightLOW else Double.NaN;

ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.LINE);
ONL.SetDefaultColor(Color.DARK_RED);
ONL.HideBubble();
ONL.HideTitle();

ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.LINE);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle(); }

plot onh0 = onh_(daysback = 0);
plot onh1 = onh_(daysback = 2);
plot onh2 = onh_(daysback = 4);
plot onh3 = onh_(daysback = 6);

onh0.setdefaultColor(color.blue);
onh1.setdefaultColor(color.blue);
onh2.setdefaultColor(color.blue);
onh3.setdefaultColor(color.blue);

input lineweight = 2;
onh0.setlineweight(lineweight);
onh1.setlineweight(lineweight);
onh2.setlineweight(lineweight);
onh3.setlineweight(lineweight);

addchartbubble(isnan(onh0[1]) and !isnan(onh0),onh0,onh0,createColor(204,204,255));
addchartbubble(isnan(onh1[1]) and !isnan(onh1),onh1,onh1,createColor(204,204,255));
addchartbubble(isnan(onh2[1]) and !isnan(onh2),onh2,onh2,createColor(204,204,255));
addchartbubble(isnan(onh3[1]) and !isnan(onh3),onh3,onh3,createColor(204,204,255));
 
Solution
I just got this code for ONH_ONL but this just for a HIGH values. I've tried to add the code for ONL but I cannot make it =( . Please help!




script onh_ {
input daysback = 1;

def ymd = SecondsFromTime(1600) >= 0 or SecondsTillTime(0930) > 0;
def candles = !IsNaN(close);
def capture = ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;

input PlotOverNightExtremes = yes;
input DisplayPriceBubbleOnHiLowBar = yes;
input DisplayPriceBubbleOnRightEdge = yes;

def o = open; def h = high; def l = low; def c = close;

def Post = thisday==daysback and secondsFromTime(1600);
def Pre = thisday==daysback and secondsTillTime(930)...

halcyonguy

Well-known member
VIP
I just got this code for ONH_ONL but this just for a HIGH values. I've tried to add the code for ONL but I cannot make it =( . Please help!




script onh_ {
input daysback = 1;

def ymd = SecondsFromTime(1600) >= 0 or SecondsTillTime(0930) > 0;
def candles = !IsNaN(close);
def capture = ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) ;

input PlotOverNightExtremes = yes;
input DisplayPriceBubbleOnHiLowBar = yes;
input DisplayPriceBubbleOnRightEdge = yes;

def o = open; def h = high; def l = low; def c = close;

def Post = thisday==daysback and secondsFromTime(1600);
def Pre = thisday==daysback and secondsTillTime(930);
def Closed = thisday==daysback and (Post >=0 or Pre>=0);

def bar = BarNumber();
def GlobeX = thisday==daysback and Closed;# GetTime() < RegularTradingStart(GetYYYYMMDD());

def ONhigh = if thisday==daysback and GlobeX and !GlobeX[1] then h else
if thisday==daysback and GlobeX and h > ONhigh[1] then h else ONhigh[1];

def ONhighBar = if thisday==daysback and GlobeX and h == ONhigh then bar else Double.NaN;

def OverNightHigh = if thisday==daysback and BarNumber() == HighestAll(ONhighBar) then ONhigh else OverNightHigh[1];

plot ONH = if thisday <= daysback and OverNightHigh > 1 then OverNightHigh else Double.NaN;
###
def ONlow = if thisday==daysback and GlobeX and !GlobeX[1] then l else
if thisday==daysback and GlobeX and l < ONlow[1] then l else ONlow[1];

def ONlowBar = if thisday==daysback and GlobeX and l == ONlow then bar else Double.NaN;

def OverNightLOW = if thisday==daysback and BarNumber() == LOWestAll(ONLOWBar) then ONlow else OverNightlow[1];
plot ONL = if thisday >= daysback and OverNightLOW > 1 then OverNightLOW else Double.NaN;

ONL.SetHiding(!PlotOverNightExtremes);
ONL.SetPaintingStrategy(PaintingStrategy.LINE);
ONL.SetDefaultColor(Color.DARK_RED);
ONL.HideBubble();
ONL.HideTitle();

ONH.SetHiding(!PlotOverNightExtremes);
ONH.SetPaintingStrategy(PaintingStrategy.LINE);
ONH.SetDefaultColor(Color.BLUE);
ONH.HideBubble();
ONH.HideTitle(); }

plot onh0 = onh_(daysback = 0);
plot onh1 = onh_(daysback = 2);
plot onh2 = onh_(daysback = 4);
plot onh3 = onh_(daysback = 6);

onh0.setdefaultColor(color.blue);
onh1.setdefaultColor(color.blue);
onh2.setdefaultColor(color.blue);
onh3.setdefaultColor(color.blue);

input lineweight = 2;
onh0.setlineweight(lineweight);
onh1.setlineweight(lineweight);
onh2.setlineweight(lineweight);
onh3.setlineweight(lineweight);

addchartbubble(isnan(onh0[1]) and !isnan(onh0),onh0,onh0,createColor(204,204,255));
addchartbubble(isnan(onh1[1]) and !isnan(onh1),onh1,onh1,createColor(204,204,255));
addchartbubble(isnan(onh2[1]) and !isnan(onh2),onh2,onh2,createColor(204,204,255));
addchartbubble(isnan(onh3[1]) and !isnan(onh3),onh3,onh3,createColor(204,204,255));

append the plot name , .onl , to the end of the statement.

if a plot name is not specified, it is defaulted to be the first plot in the script.

when plot is used within a script { } subroutine, it generates a number, that is sent back to the statement that called it.
it doesn't plot anything on a chart. using paintstrategy and color commands in a script are ignored.


i didn't check the formulas, but this is how to read another plot value from a script.

plot onh0 = onh_(daysback = 0).ONH;
plot onh1 = onh_(daysback = 2).ONH;
plot onh2 = onh_(daysback = 4).ONH;
plot onh3 = onh_(daysback = 6).ONH;

plot onl0 = onh_(daysback = 0).ONL;
plot onl1 = onh_(daysback = 2).ONL;
plot onl2 = onh_(daysback = 4).ONL;
plot onl3 = onh_(daysback = 6).ONL;

i am not sure if the plot name needs to be wrapped in quotes, like this.
plot onl0 = onh_(daysback = 0)."ONL";


an example code, that reads different plot variables.
https://usethinkscript.com/threads/...ts-indicator-for-thinkorswim.4860/#post-62411

plot R3 = pivotpoints().r3;
plot R2 = pivotpoints().r2;
plot R1 = pivotpoints().r1;
.....
 
Solution
Top