Math operation with close function

shahgols

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?





 

shahgols

New member
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.

Code:
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;
 

inthefutures

Active member
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());
 

shahgols

New member
It works like a charm!!! Thank you so much! I owe you, no idea how to pay you back, but if you are ever in the Dallas area, all drinks are on me! Thank you!
 

shahgols

New member
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!

 

inthefutures

Active member
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

Top