get specific candle from past

joker12

New member
Hi guys, anybody who could advice how to work with specific candle from past, pls?

I am able to find it with loop(first 3 lines of code below), but after I want work more with it, but its not possible use neither t nor h in those brackets [] as those are variables and just constats are permited..any solution??

def t= fold y= 2 to 7 with p=1 while((open[y]>lov && close[y]>lov) or (open[y]<lov && close[y]<lov) or (open[y]>up && close[y]>up) or (open[y]<up && close[y]<up) ) do P+1;
def h= if(t==7) then 0 else t;
#check more details of found candle/error here : just constants permited
def kandle= if(open[h]>close[h] && close[h]<lov) then -1 else 1;

Hi guys, anybody who could advice how to work with specific candle from past, pls?

I am able to find it with loop(first 3 lines of code below), but after I want work more with it, but its not possible use neither t nor h in those brackets [] as those are variables and just constats are permited..any solution??

def t= fold y= 2 to 7 with p=1 while((open[y]>lov && close[y]>lov) or (open[y]<lov && close[y]<lov) or (open[y]>up && close[y]>up) or (open[y]<up && close[y]<up) ) do P+1;
def h= if(t==7) then 0 else t;
#check more details of found candle/error here : just constants permited
def kandle= if(open[h]>close[h] && close[h]<lov) then -1 else 1;
can you post all of the code? it is missing variables lov and up.

usually , getvalue() is used in a fold to read data.
using getvalue() , might do what you want in the last code line.

def kandle = if( getvalue(open, h) > getvalue(close, h) and getvalue(close, h) < lov) then -1 else 1;

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue

can you post all of the code? it is missing variables lov and up.

usually , getvalue() is used in a fold to read data.
using getvalue() , might do what you want in the last code line.

def kandle = if( getvalue(open, h) > getvalue(close, h) and getvalue(close, h) < lov) then -1 else 1;

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue

lov is just previous day low and up previous day high..never mind, since meanwhile I found out, that I cant use various timeframes in watchlist column..(I am basicaly checking for specific entry signals around previous days low and high)

In any case would be usefull for me to know way how to get this data what I wanted: with code above I am able find candle from past which break through previous day low or high - but in next code I want to work with this candle=I need get this specific number of candle= lets say it was 3rd candle backward= so I need stored somehow 3...(in my code above it should be value of p and so also t at the end (if i understand fold correctly), but I cant use those two in form : close[p], or close [t], since they are variables not constats and so throwing me error..

Not the exact question you're looking for?

87k+ Posts
314 Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?