Coding Help: Fold vs CompoundValue

pupu

Member
I am always very confused with the iteration functions provided by thinkscript.

If possible, I wish to use a common programming language to let me understand how Fold and CompoundValue works, and their differences (which seems very similar, if not the same).

From my understanding, the following computes the same?

CompoundValue:

Code:
def length = 2;
def x = CompoundValue(
        length,
        x[1] + x[2],
        1
);

Fold:

Code:
def length = 2;

def x =
  fold i = 1 to length
  with x
  do x[1] + x[2];

Generic Language:

Code:
chart_bar_number = 100;
length = 2;
output = 0;

For (index = 1; index <= chart_bar_number; index++)
{
    if(index > length){
        output[index] = output[index - 1] + output[index - 2];
    }else{
        output[index] = 1;
    }
}

Please give me some help on the above! Thank you!
 
Solution
compoundvalue() info
https://usethinkscript.com/threads/quarterly-value-area-tpo.9390/#post-85195
post10

compoundvalue is like an if then.


---------------------
fold

https://usethinkscript.com/threads/simple-explanation-of-fold-trying-to-learn.8044/
Simple explanation of Fold? Trying to learn....
greco26
Sep 21, 2021
post1

post5 includes the following 2 links

-----------------

explain the code in a couple of fold loops
https://usethinkscript.com/threads/...onfirming-a-thinkscript-line.6662/#post-64430
Intraday Flag Indicator to Python - Need Help Confirming a ThinkScript Line
windowshopr
May 20, 2021
post2

--------------------

an example using fold...
compoundvalue() info
https://usethinkscript.com/threads/quarterly-value-area-tpo.9390/#post-85195
post10

compoundvalue is like an if then.


---------------------
fold

https://usethinkscript.com/threads/simple-explanation-of-fold-trying-to-learn.8044/
Simple explanation of Fold? Trying to learn....
greco26
Sep 21, 2021
post1

post5 includes the following 2 links

-----------------

explain the code in a couple of fold loops
https://usethinkscript.com/threads/...onfirming-a-thinkscript-line.6662/#post-64430
Intraday Flag Indicator to Python - Need Help Confirming a ThinkScript Line
windowshopr
May 20, 2021
post2

--------------------

an example using fold
https://usethinkscript.com/threads/...st-65-most-recent-days.7483/page-2#post-72474
post22
here is another fold example. this one uses while.
...while the condition is true, it processes the do formula.

-----------------
fold info
https://usethinkscript.com/threads/loops-while.9558/#post-86805

mvp ants, a study with a nested fold loop
https://usethinkscript.com/threads/ants-—-momentum-volume-and-price-mvp.7497/#post-74080
post18

------------

a good source of info
https://jshingler.github.io/TOS-and...t Collection.html#the-fold-function-explained
hal_foldx
 
Last edited:
Solution

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
226 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.
Back
Top