@MerryDay @halcyonguy . I great appreciate the generous help both of you have given to everyone.
This fold function is one of many examples.
I have a general question to put to you and other experienced thinkscript admins and member coders This is from a beginning, isolated user without background but lots of motivation to learn; either by demo's , threads, examples, videos. Perhaps others would benefit:
Q.Would you be kind enough to share a few suggestions about where to start in a strategic sense to get some basics of thinkscript, with those of us that are really struggling to "put it together". For myself,I have some practical knowledge in hacking some of my favorite indicators and algo's, but I am there are times I...
Here are the "FOLD" threads on this forum sorted by popularity.I feel the need to learn the fold function very well. I have some basic understanding, but the documentation I have found so far does not help me enough. Could someone please point me to the very most complete documentation about the fold function?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
I feel the need to learn the fold function very well. I have some basic understanding, but the documentation I have found so far does not help me enough. Could someone please point me to the very most complete documentation about the fold function?
# fold_test2
# count how many bars in the previous 20 bars have a smaller candle than current bar
# comparing absolute size, not engulfing.
input qty = 20;
def x = fold i = 1 to qty+1
with p
#while ...
do p + (if (high-low) > (getvalue(high, i) - getvalue(low, i)) then 1 else 0);
# test the loop iterations. disable prev do p line.. and enable the following line. it will count to 20 and show 20 in bubbles, verifying how many times the loop runs.
# do p + 1;
# within a fold, getvalue() is used to read from another bar.
# getvalue( high , offset number )
# using a normal offset within a fold, may result in unknown values. high[i]
addchartbubble(1, low,
"count\n" +
x
, (if x > 10 then color.cyan else color.yellow), no);
# fold doesn't process the 'to' number , 20. so if you want a loop to run 1 to 20, it has to be set up as 1 to 21.
#
This is great! Thanks for the resources and the code for experimentation.it can be hard to learn to use fold. best thing is to experiment with some simple loops and create some bubbles to display some values. (that worked for me. i can read something all day and not get it. but if i experiment and try things, it starts to make sense.)
here is a fold study to experiment with. change values and see what happens.
Code:# fold_test2 # count how many bars in the previous 20 bars have a smaller candle than current bar # comparing absolute size, not engulfing. input qty = 20; def x = fold i = 1 to qty+1 with p #while ... do p + (if (high-low) > (getvalue(high, i) - getvalue(low, i)) then 1 else 0); # test the loop iterations. disable prev do p line.. and enable the following line. it will count to 20 and show 20 in bubbles, verifying how many times the loop runs. # do p + 1; # within a fold, getvalue() is used to read from another bar. # getvalue( high , offset number ) # using a normal offset within a fold, may result in unknown values. high[i] addchartbubble(1, low, "count\n" + x , (if x > 10 then color.cyan else color.yellow), no); # fold doesn't process the 'to' number , 20. so if you want a loop to run 1 to 20, it has to be set up as 1 to 21. #
some resources/links
jshingler
https://jshingler.github.io/TOS-and-Thinkscript-Snippet-Collection/TOS & Thinkscript Collection.html#the-fold-function-explained
here are a few links talking about fold
https://usethinkscript.com/threads/simple-explanation-of-fold-trying-to-learn.8044/#post-76663
https://usethinkscript.com/threads/...onfirming-a-thinkscript-line.6662/#post-64430
https://usethinkscript.com/threads/calculating-price-density-index-pdi.12965/#post-72474
https://usethinkscript.com/threads/ask-line-20.14356/#post-119865
@MerryDay @halcyonguy . I great appreciate the generous help both of you have given to everyone.
This fold function is one of many examples.
I have a general question to put to you and other experienced thinkscript admins and member coders This is from a beginning, isolated user without background but lots of motivation to learn; either by demo's , threads, examples, videos. Perhaps others would benefit:
Q.Would you be kind enough to share a few suggestions about where to start in a strategic sense to get some basics of thinkscript, with those of us that are really struggling to "put it together". For myself,I have some practical knowledge in hacking some of my favorite indicators and algo's, but I am there are times I get lost in the forest, so to speak, for lack of fundamentals. The map is definitely not the territory, as I find the official documentation manual incomprehensible much of the time, since I have no coding background. With much appreciation to the compassionate Bodhisattvas that hang around to assist those of us that struggle to "see the light and delight of learning". Best to all MagicQuotes.
# ex. \n forces text after it to start on the next line
# Uses a formula in the color parameter to display different colors.
addchartbubble(1, low,
open + " opn\n" +
close + " cls"
, (if close > close[1] then color.green else color.red), no);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
S | Nested Fold Function Debugging | Questions | 4 | |
S | Fold Function Counter | Questions | 3 | |
A | Calculating Triangular Moving Average with Fold function | Questions | 1 | |
S | Conditional Triggers Using the Fold Function | Questions | 17 | |
J | Fold Statement help | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.