Trying to understand LOG function

nerdytrader

New member
This is a scanner code I found on the thinkscript cloud for a flag scan. I was tinkering with it and noticed something strange so I kept tinkering with it. No matter what values I enter for the input = n and input =s , I got the same results. I put the code directly in the scanner under the study filter, I made a study for the code and made a scan using the condition wizard, still same results. Then I deleted the input = n and ran the scan. Same results as if it was not deleted. Then I deleted the input = s value and no change. Still getting the same results.

Then I deleted a big chunk of the code, same results. I'm baffeled.

Heres the original code from the thinkscript_cloud:
Code:
# Bull Flag on Pole - SCAN
# Mobius
# V01.02.2014
# Price trend - Upward leading to the pattern. The price should rise by at least 90% in less than 2 months.
# Shape - A consolidation pattern forms after price doubles. It usually doesn't look like a flag or pennant, just a pause in the price rise.
# Volume - Recedes for best performance
# Confirmation - The pattern confirms as valid when price closes above the highest peak in the pattern.

input n = 21;
input s = 55;
def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def o = open;
def h = high;
def l = low;
def c = close;
def HH = if h < highest(h, 51) * .75
then 0
else if h > HH[1]
then h
else HH[1];
def CIB = Inertia(((Log(Sum(TrueRange(h, c, l), n) /
(Highest(if h >= c[1] then h else c[1], n) -
Lowest(if l <= c[1] then l else c[1], n))) /
Log(10)) / (Log(n) / Log(10))) * 100, s);
def CI = if CIB > CIB[1]
then 1 else Double.NaN;
plot Flag = if upward and p
then 1
else Double.NaN;
##############################

Here are the different ways I edited and messed with the code, only to recieve the same exact results as the original code. Which makes zero sense.
##########################################

Flag code with input n and it's counterparts ommited:

#input n = 0;
input s = 0;

def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def o = open;
def h = high;
def l = low;
def c = close;

def HH = if h < highest(h, 51) * .75
then 0
else if h > HH[1]
then h
else HH[1];

def CIB = Inertia(((Log(Sum(TrueRange(h, c, l)) /
(Highest(if h >= c[1] then h else c[1])-
Lowest(if l <= c[1] then l else c[1]))) /
Log(10)) / (Log(10))) * 100, s);

def CI = if CIB > CIB[1]
then 1 else Double.NaN;

plot Flag = if upward and p
then 1
else Double.NaN;

####################
flag scan with both s and n edited out along with CIB deleted
#######################

#input n = 0;
#input s = 0;

def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def o = open;
def h = high;
def l = low;
def c = close;

def HH = if h < highest(h, 51) * .75
then 0
else if h > HH[1]
then h
else HH[1];

plot Flag = if upward and p
then 1
else Double.NaN;

#########################

No matter what, when you scan using the same time frames, all of the results will be the same. That makes no sense to me. What are the inputs for if they don't change the results at all? And or, what is the rest of the code for if it has no impact at all on the scan/ Are the results that the scan displays even related to the scan critera itself? Furthermore, what's strange is oddly enough, the results that are displayed are more so actual flag patterns. So I'm very confused about this.

Does anyone have any idea what is going on? I've always wondered how accurately the scanner tool actually utilized the custom filters to give results that match the filters used, so this makes me wonder
 
Last edited by a moderator:
This is a scanner code I found on the thinkscript cloud for a flag scan. I was tinkering with it and noticed something strange so I kept tinkering with it. No matter what values I enter for the input = n and input =s , I got the same results. I put the code directly in the scanner under the study filter, I made a study for the code and made a scan using the condition wizard, still same results. Then I deleted the input = n and ran the scan. Same results as if it was not deleted. Then I deleted the input = s value and no change. Still getting the same results.

Then I deleted a big chunk of the code, same results. I'm baffeled.

Heres the original code from the thinkscript_cloud:
Code:
# Bull Flag on Pole - SCAN
# Mobius
# V01.02.2014
# Price trend - Upward leading to the pattern. The price should rise by at least 90% in less than 2 months.
# Shape - A consolidation pattern forms after price doubles. It usually doesn't look like a flag or pennant, just a pause in the price rise.
# Volume - Recedes for best performance
# Confirmation - The pattern confirms as valid when price closes above the highest peak in the pattern.

input n = 21;
input s = 55;
def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def o = open;
def h = high;
def l = low;
def c = close;
def HH = if h < highest(h, 51) * .75
then 0
else if h > HH[1]
then h
else HH[1];
def CIB = Inertia(((Log(Sum(TrueRange(h, c, l), n) /
(Highest(if h >= c[1] then h else c[1], n) -
Lowest(if l <= c[1] then l else c[1], n))) /
Log(10)) / (Log(n) / Log(10))) * 100, s);
def CI = if CIB > CIB[1]
then 1 else Double.NaN;
plot Flag = if upward and p
then 1
else Double.NaN;
##############################

Here are the different ways I edited and messed with the code, only to recieve the same exact results as the original code. Which makes zero sense.
##########################################

Flag code with input n and it's counterparts ommited:

#input n = 0;
input s = 0;

def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def o = open;
def h = high;
def l = low;
def c = close;

def HH = if h < highest(h, 51) * .75
then 0
else if h > HH[1]
then h
else HH[1];

def CIB = Inertia(((Log(Sum(TrueRange(h, c, l)) /
(Highest(if h >= c[1] then h else c[1])-
Lowest(if l <= c[1] then l else c[1]))) /
Log(10)) / (Log(10))) * 100, s);

def CI = if CIB > CIB[1]
then 1 else Double.NaN;

plot Flag = if upward and p
then 1
else Double.NaN;

####################
flag scan with both s and n edited out along with CIB deleted
#######################

#input n = 0;
#input s = 0;

def upward = IsAscending(HL2, 65);
def p = (highest(high, 21) / close[65]) > 1.1;
def o = open;
def h = high;
def l = low;
def c = close;

def HH = if h < highest(h, 51) * .75
then 0
else if h > HH[1]
then h
else HH[1];

plot Flag = if upward and p
then 1
else Double.NaN;

#########################

No matter what, when you scan using the same time frames, all of the results will be the same. That makes no sense to me. What are the inputs for if they don't change the results at all? And or, what is the rest of the code for if it has no impact at all on the scan/ Are the results that the scan displays even related to the scan critera itself? Furthermore, what's strange is oddly enough, the results that are displayed are more so actual flag patterns. So I'm very confused about this.

Does anyone have any idea what is going on? I've always wondered how accurately the scanner tool actually utilized the custom filters to give results that match the filters used, so this makes me wonder

you don't see any changes , because most of the code goes nowhere, the last variable, CI is not used in any output functions.
flag just looks at upward and p , and is either 1 or na.
my guess is you deleted something that connected CI to a plot formula.
for scans , i have always thought the plot should be 1 or 0. not sure what happens when one value is nan?

here is the 1st code, modified
the first thing i do when debugging is set the code as a chart study,
then add bubbles to display some variables, to see what is going on.
flag was rarely 1 , so i disabled the formula.

change ci formula , from else nan , to else 0
add a plot command to plot the ci variable

if you load this on a chart, you see a pulse signal that is either 1 or 0


Ruby:
# logscan_a00

input n = 21;
input s = 55;
def upward = IsAscending(HL2, 65);
def p = (Highest(high, 21) / close[65]) > 1.1;
#def o = open;
def h = high;
def l = low;
def c = close;

#def HH = if h < Highest(h, 51) * .75 then 0   else if h > HH[1] then h  else HH[1];

def CIB = Inertia(((Log(Sum(TrueRange(h, c, l), n) /
(Highest(if h >= c[1] then h else c[1], n) -
Lowest(if l <= c[1] then l else c[1], n))) /
Log(10)) / (Log(n) / Log(10))) * 100, s);

# chg from  else nan to  else 0
def CI = if CIB > CIB[1] then 1 else 0;

#plot Flag = if upward and p then 1 else Double.NaN;

plot z = ci;


addchartbubble(0, low,
 "u " + upward
 + "\nP " + p
 + "\ncib " + cib
 + "\nci " + ci
# + "\nF " + flag
,color.yellow, no);
# ci is sometimes na
# flag is always na


addchartbubble(0, low,
 "u " + upward
 + "\nP " + p
 # + "\nF " + flag
, (if p then color.yellow else color.gray), no);

#
 

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
149 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