• Get $40 off VIP by signing up for a free account! Sign Up

Math operation with close function


New member
Hi everyone, sorry if this question is too basic. I am totally new to thinkscript. I have searched online for an answer to my question and have also analyzed many studies inside TOS, but could not find a solution to my problem. I am just writing some nonsensical code to practice, but found that when I add a value to the close price, the script fails. thinkscript editor doesn't throw an error, it doesn't highlight the code in red, but the script doesn't behave like it should. I have attached a screenshot of my script, and two output screenshots, one with a blue line that goes up for 1 and then down for 0. And one screenshot where the blue line is constantly at 0. The screenshot with the constant 0 is what happens when I add a 1 to close function. My question is, how can I perform math operations on the close price?




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

Thanks inthefutures. I looked at the manual pages for ticks and ticksize, it's way over my head. IMHO they are not written for noobs like me. What I am really trying to do, and didn't mention before because I was embarrassed to, is to set a flag when the current price is higher than ANY 40 previous bars by $10. I wrote a script and it's too simple, and I was embarrassed to post it. But here goes...how can I get this accomplished? Please help. Thank you in advance.

input price = close;

plot Flag = if price < price[1] +  10
     or price < price[2] +  10
     or price < price[3] +  10
     or price < price[4] +  10
     or price < price[5] +  10
     or price < price[6] +  10
     or price < price[7] +  10
     or price < price[8] +  10
     or price < price[9] +  10
     or price < price[10] +  10
     or price < price[11] +  10
     or price < price[12] +  10
     or price < price[13] +  10
     or price < price[14] +  10
     or price < price[15] +  10
     or price < price[16] +  10
     or price < price[17] +  10
     or price < price[18] +  10
     or price < price[19] +  10
     or price < price[20] +  10
     or price < price[21] +  10
     or price < price[22] +  10
     or price < price[23] +  10
     or price < price[24] +  10
     or price < price[25] +  10
     or price < price[26] +  10
     or price < price[27] +  10
     or price < price[28] +  10
     or price < price[29] +  10
     or price < price[30] +  10
     or price < price[31] +  10
     or price < price[32] +  10
     or price < price[33] +  10
     or price < price[34] +  10
     or price < price[35] +  10
     or price < price[36] +  10
     or price < price[37] +  10
     or price < price[38] +  10
     or price < price[39] +  10
     or price < price[40] +  10
     then 0 else 1;
see if this does what you want

declare lower;

def price = close;
input offset = 10;

def top = highest(high,40);
plot trigger = price > top[1] +(offset * ticksize());
Hi again. Just a bit of bad news, the script is throwing a lot of false positives, so I am not sure if it's working correctly. For example, in the image below, the price never goes below 150, but it throws a false positive. Any thoughts? What I need is to get a flag when the price has gone up $10 in the past 40 bars. Thanks again!

if you added
input lookback = 40;
and then change
def top = highest(high,40);
to def top = highest(high,lookback);

then you can easily adjust how far yo look back

and your welcome

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
282 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.