0

I have come across some scripts that use ":=" instead of "=" for assignments, what is the difference. I have tried looking it V5 reference but it does not seem to be there

Thanks

Adam B
  • 93
  • 1
  • 3
  • 13
  • ':=' is a re assignment, not an assignment, it presumes the variable already has history, and it may have history if you use var my_variable=0. for example. var is executed once on the first bar of the data set. So my_variable:= my_variable+some_number means add some_number to the last known value of my_variable (which is like my_variable[1]). Shorthand same thing is my_variable+=some_number. – John Baron Sep 16 '22 at 11:40
  • If you don't use a var call, then you can also do my_variable=0.0 in some prior line and then re-assign with my_variable:=xxx in a line later in your script. The difference here is that for each bar, my_variable will be set to 0.0 first before re-assignment. whereas with var it is only set to 0.0 once. self referencing will be different. In the second example, my_variable := my_variable + some_number will use the value of my_variable=0.0 in the prior script line, not the historical reference. – John Baron Sep 16 '22 at 11:40
  • 1
    These are fantastic explanations, Thank you! – Adam B Sep 16 '22 at 16:17

0 Answers0