Question about scripts references

pcex.antiuno

New member
Hi Everyone, I'm learning to use ThinkScript and I have a question.

Here is the thing, I made a script in a study with many variables like this (is just an example):

Code:
script TestScript{
          input num = 5;
          def Var1 = num + 1;
          def Var2 = num + 2;
          plot Var3 = Var1 + Var2;
}


and I use It forward like this:

Code:
def testNumber1 = 20;
def testNumber2 = 30;

def test11 = TestScript(testNumber1).Var1;
def test12 = TestScript(testNumber1).Var2;
plot test13 = TestScript(testNumber1).Var3;

def test21 = TestScript(testNumber2).Var1;
def test22 = TestScript(testNumber2).Var2;
plot test23 = TestScript(testNumber2).Var3;

My question is: Every time I call TestScript(something).someVariable; script calculations are made them again?

Is there a way to call the script just once ? Someway like this (I try it and doesnt work):

Code:
def testScript1 = TestScript(testNumber1);

def test11 = testScript1.Var1;
def test12 = testScript1.Var2;
plot test13 = testScript1.Var3;

def testScript2 = TestScript(testNumber2);

def test21 = testScript2.Var1;
def test22 = testScript2.Var2;
plot test23 = testScript2.Var3;

I hope someone can help me.

EDIT: I wrote wrong the tittle. Is "Question about scripts references"
 

rad14733

Well-known member
VIP
@pcex.antiuno

The easiest way to run only once would be to define and check with a counter variable... Increment the counter the first time the script runs and then check for the result on subsequent iterations... Subsequent iterations would read the "1" from the first iteration and store it again... There are examples of counter code here in the forums... If you need further help let us know...
 

rad14733

Well-known member
VIP
I gave advice on how to make it only calculate one time as you asked... If you know of a better way then go for it... As I see it, you want the script to run until it meets your criteria just once... How else would you propose that...???

Storm knocked out the power so I'm on my phone which is the wrong tool for the job, other than a bit of reading... I'll check back once power is restored...
 

pcex.antiuno

New member
I just wanna do something like this example (obviously doesn't work):

Code:
def testScript1 = TestScript(testNumber1);

def test11 = testScript1.Var1;
def test12 = testScript1.Var2;
plot test13 = testScript1.Var3;

def testScript2 = TestScript(testNumber2);

def test21 = testScript2.Var1;
def test22 = testScript2.Var2;
plot test23 = testScript2.Var3;

Like other programming languages, like this was an object or something like that.
I'd like recalculate if It's necesary but keep the script in one variable and call scripts variables with that. Sorry, I dont know if I'm explain myself.
 

rad14733

Well-known member
VIP
Not really grasping what it is you really want to do but based on the vast array of programming and scripting languages I've worked with it sounds like you want to do something beyond the scope of capabilities of Thinkscript... Therein lies the difference, there are programming languages and then there are scripting languages... Thinkscript is a scripting language that calls functions that take parameters... It also quazi works with stock data, perhaps data objects but not really, to provide information we want... As such, Thinkscript is fairly limited...
 
Thread starter Similar threads Forum Replies Date
W Plot question. Questions 1
maverickmitch Scripting Question . . . Questions 1
T Question about use if block set text symbals Questions 2
maverickmitch Backtesting question Questions 1
mbarcala Question about AssignPriceColor ? Questions 10

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.
Top