Help with script - can't understand how it works

Endorian

New member
Hi,
I'm new to this language and I'm trying to understand what actually this code is doing:

Code:
[... code here ...]

input rollingPeriodMinutes = 60;
 
def factor = (SecondsFromTime(Market_Open_Time) / (60 * rollingPeriodMinutes) / 100);
def rolloverTime = if factor == Round(factor) then 1 else 0;

rec H1 = compoundValue(1, if !rolloverTime then if high > H1[1] then high else H1[1] else high, high);
rec H = compoundValue(1, if rolloverTime then H1[1] else H[1], high);

[... code here ...]

Can any of you understand what actually at the end "H" is?
Please, any help is really appraciated🙏
Thanks a lot,

Julian

Here is the complete code:
https://pastebin.com/a9svkFpv
Code:
input showOnlyToday = YES;
 
 
def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0));
 
input Market_Open_Time = 0730;
input Market_Close_Time = 1600;
input rollingPeriodMinutes = 60;
 
def factor = (SecondsFromTime(Market_Open_Time) / (60 * rollingPeriodMinutes) / 100);
def rolloverTime = if factor == Round(factor) then 1 else 0;
 
rec H1 = compoundValue(1, if !rolloverTime then if high > H1[1] then high else H1[1] else high, high);
rec H = compoundValue(1, if rolloverTime then H1[1] else H[1], high);
rec L1 = compoundValue(1, if !rolloverTime then if low < L1[1] then low else L1[1] else low, low);
rec L = compoundValue(1, if rolloverTime then L1[1] else L[1], low);
rec C = compoundValue(1, if rolloverTime then close[1] else C[1], close);
rec O = compoundValue(1, if rolloverTime then open else O[1], open);
rec X_VAR = if C < O then (H + 2 * L + C) else if C > O then (2 * H + L + C) else (H + L + 2 * C);
 
rec PP_VAR;
rec R1_VAR;
rec R2_VAR;
rec R3_VAR;
rec R4_VAR;
rec S1_VAR;
rec S2_VAR;
rec S3_VAR;
rec S4_VAR;
 
 
 
 
 
 
 
    PP_VAR = if shouldPlot then (H + L + C) / 3 else Double.NaN;
    R1_VAR = if shouldPlot then PP_VAR + (H - L) / 2 else Double.NaN;
    R2_VAR = if shouldPlot then PP_VAR + (H - L) * 1.272 else Double.NaN;
    R3_VAR = if shouldPlot then PP_VAR + (H - L) else Double.NaN;
    R4_VAR = Double.NaN;
    S1_VAR = if shouldPlot then PP_VAR - (H - L) / 2 else Double.NaN;
    S2_VAR = if shouldPlot then PP_VAR - (H - L) * 1.272 else Double.NaN;
    S3_VAR = if shouldPlot then PP_VAR - (H - L) else Double.NaN;
    S4_VAR = Double.NaN;
 
 
 
plot PP = PP_VAR;
plot R1 = R1_VAR;
plot R2 = R2_VAR;
plot R3 = R3_VAR;
plot R4 = R4_VAR;
plot S1 = S1_VAR;
plot S2 = S2_VAR;
plot S3 = S3_VAR;
plot S4 = S4_VAR;
 
PP.SetDefaultColor(Color.WHITE);
 
R1.SetDefaultColor(Color.RED);
R2.SetDefaultColor(Color.RED);
R3.SetDefaultColor(Color.RED);
R4.SetDefaultColor(Color.RED);
 
S1.SetDefaultColor(Color.GREEN);
S2.SetDefaultColor(Color.GREEN);
S3.SetDefaultColor(Color.GREEN);
S4.SetDefaultColor(Color.GREEN);
 
PP.SetStyle(Curve.POINTS);
R1.SetStyle(Curve.POINTS);
R2.SetStyle(Curve.POINTS);
R3.SetStyle(Curve.POINTS);
R4.SetStyle(Curve.POINTS);
S1.SetStyle(Curve.POINTS);
S2.SetStyle(Curve.POINTS);
S3.SetStyle(Curve.POINTS);
S4.SetStyle(Curve.POINTS);
 
Last edited by a moderator:
Solution
Hi,
I'm new to this language and I'm trying to understand what actually this code is doing:

Code:
[... code here ...]

input rollingPeriodMinutes = 60;
 
def factor = (SecondsFromTime(Market_Open_Time) / (60 * rollingPeriodMinutes) / 100);
def rolloverTime = if factor == Round(factor) then 1 else 0;

rec H1 = compoundValue(1, if !rolloverTime then if high > H1[1] then high else H1[1] else high, high);
rec H = compoundValue(1, if rolloverTime then H1[1] else H[1], high);

[... code here ...]

Can any of you understand what actually at the end "H" is?
Please, any help is really appraciated🙏
Thanks a lot,

Julian

Here is the complete code:
https://pastebin.com/a9svkFpv
Code:
input showOnlyToday = YES;
 
 
def day = GetDay();
def...
Hi,
I'm new to this language and I'm trying to understand what actually this code is doing:

Code:
[... code here ...]

input rollingPeriodMinutes = 60;
 
def factor = (SecondsFromTime(Market_Open_Time) / (60 * rollingPeriodMinutes) / 100);
def rolloverTime = if factor == Round(factor) then 1 else 0;

rec H1 = compoundValue(1, if !rolloverTime then if high > H1[1] then high else H1[1] else high, high);
rec H = compoundValue(1, if rolloverTime then H1[1] else H[1], high);

[... code here ...]

Can any of you understand what actually at the end "H" is?
Please, any help is really appraciated🙏
Thanks a lot,

Julian

Here is the complete code:
https://pastebin.com/a9svkFpv
Code:
input showOnlyToday = YES;
 
 
def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0));
 
input Market_Open_Time = 0730;
input Market_Close_Time = 1600;
input rollingPeriodMinutes = 60;
 
def factor = (SecondsFromTime(Market_Open_Time) / (60 * rollingPeriodMinutes) / 100);
def rolloverTime = if factor == Round(factor) then 1 else 0;
 
rec H1 = compoundValue(1, if !rolloverTime then if high > H1[1] then high else H1[1] else high, high);
rec H = compoundValue(1, if rolloverTime then H1[1] else H[1], high);
rec L1 = compoundValue(1, if !rolloverTime then if low < L1[1] then low else L1[1] else low, low);
rec L = compoundValue(1, if rolloverTime then L1[1] else L[1], low);
rec C = compoundValue(1, if rolloverTime then close[1] else C[1], close);
rec O = compoundValue(1, if rolloverTime then open else O[1], open);
rec X_VAR = if C < O then (H + 2 * L + C) else if C > O then (2 * H + L + C) else (H + L + 2 * C);
 
rec PP_VAR;
rec R1_VAR;
rec R2_VAR;
rec R3_VAR;
rec R4_VAR;
rec S1_VAR;
rec S2_VAR;
rec S3_VAR;
rec S4_VAR;
 
 
 
 
 
 
 
    PP_VAR = if shouldPlot then (H + L + C) / 3 else Double.NaN;
    R1_VAR = if shouldPlot then PP_VAR + (H - L) / 2 else Double.NaN;
    R2_VAR = if shouldPlot then PP_VAR + (H - L) * 1.272 else Double.NaN;
    R3_VAR = if shouldPlot then PP_VAR + (H - L) else Double.NaN;
    R4_VAR = Double.NaN;
    S1_VAR = if shouldPlot then PP_VAR - (H - L) / 2 else Double.NaN;
    S2_VAR = if shouldPlot then PP_VAR - (H - L) * 1.272 else Double.NaN;
    S3_VAR = if shouldPlot then PP_VAR - (H - L) else Double.NaN;
    S4_VAR = Double.NaN;
 
 
 
plot PP = PP_VAR;
plot R1 = R1_VAR;
plot R2 = R2_VAR;
plot R3 = R3_VAR;
plot R4 = R4_VAR;
plot S1 = S1_VAR;
plot S2 = S2_VAR;
plot S3 = S3_VAR;
plot S4 = S4_VAR;
 
PP.SetDefaultColor(Color.WHITE);
 
R1.SetDefaultColor(Color.RED);
R2.SetDefaultColor(Color.RED);
R3.SetDefaultColor(Color.RED);
R4.SetDefaultColor(Color.RED);
 
S1.SetDefaultColor(Color.GREEN);
S2.SetDefaultColor(Color.GREEN);
S3.SetDefaultColor(Color.GREEN);
S4.SetDefaultColor(Color.GREEN);
 
PP.SetStyle(Curve.POINTS);
R1.SetStyle(Curve.POINTS);
R2.SetStyle(Curve.POINTS);
R3.SetStyle(Curve.POINTS);
R4.SetStyle(Curve.POINTS);
S1.SetStyle(Curve.POINTS);
S2.SetStyle(Curve.POINTS);
S3.SetStyle(Curve.POINTS);
S4.SetStyle(Curve.POINTS);

this study draws 7 hourly pivots, on the current day.

compoundValue() is like an if then, they choose to do the middle parameter or the 3rd parameter.
the first parameter is a barnumber.
if the current barnumber <= the first parameter, then process the 3rd parameter.
if the current barnumber > the first parameter, then process the 2nd parameter.

rec H = compoundValue(1, if rolloverTime then H1[1] else H[1], high);

if the current barnumber <= 1 , then h = high
if the current barnumber > 1 , then h = if rolloverTime then H1[1] else H[1]

an equivelent formula
def h = if barnumber() <= 1 then high
else if rolloverTime then H1[1]
else H[1];

rolloverTime is true at the day open , 9:30 , and every 60 minutes after (bottom of the hour).
at the bottom of the hour h = h1[1] , the previous value of h1.
for the next 59 minutes, h = h[1] , the previous value of h.
 
Solution

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

Oh ok! So may u confirm me the following example:

If now is 14:27, inside H C L i have the high close and low of the hour bar starting from 12:30 and finishing in 13:30 . When the time will be 14:31, in the variable there will be the H C L of the bar from 13:30 -> 14:30 ... is this correct?
 
Oh ok! So may u confirm me the following example:

If now is 14:27, inside H C L i have the high close and low of the hour bar starting from 12:30 and finishing in 13:30 . When the time will be 14:31, in the variable there will be the H C L of the bar from 13:30 -> 14:30 ... is this correct?

i don't know. i'm not go to analyze all the lines of code to figure out what the values will be.
I would add a chart bubble to the end of a study to display the values. then zoom in to the time in question and see what is happening. sometimes i add an if then in the color parameter,
(if ... then color.yellow else color.gray)

Code:
addchartbubble(1, low*0.997,
h1 + " H1\n" +
h + " H\n" +
l1 + " L1\n" +
l + " L\n" +
c + " C\n" +
o + " O\n" +
x_var + " x\n"
,color.yellow, no);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
321 Online
Create Post

Similar threads

Similar threads

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