Last active
January 15, 2025 19:25
-
-
Save rajvermacas/f1700f9112656948ec0598f48a5bfe5c to your computer and use it in GitHub Desktop.
Pinescript var behaviour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
// © mrinalrajubereats1 | |
//@version=6 | |
indicator("My script") | |
log.info("\n########### Day starts ###########") | |
func1() => | |
var a = 0 | |
a += 1 | |
log.info("Value of a in func1: {0}", str.tostring(a)) | |
a | |
func1Result = func1() // [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 3477 | |
func2Result = func1() // [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 3477 | |
log.info("--------- Loop starts ---------") | |
for i = 0 to 1 | |
x = func1() | |
log.info("\n########### Day ends ###########") | |
// Output: | |
// [2025-01-09T09:15:00.000+05:30]: | |
// ########### Day starts ########### | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 3476 | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 3476 | |
// [2025-01-09T09:15:00.000+05:30]: --------- Loop starts --------- | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 6951 | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 6952 | |
// [2025-01-09T09:15:00.000+05:30]: | |
// ########### Day ends ########### | |
// [2025-01-10T09:15:00.000+05:30]: | |
// ########### Day starts ########### | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 3477 | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 3477 | |
// [2025-01-10T09:15:00.000+05:30]: --------- Loop starts --------- | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 6953 | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 6954 | |
// [2025-01-10T09:15:00.000+05:30]: | |
// ########### Day ends ###########[2025-01-09T09:15:00.000+05:30]: | |
// ########### Day starts ########### | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 3476 | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 3476 | |
// [2025-01-09T09:15:00.000+05:30]: --------- Loop starts --------- | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 6951 | |
// [2025-01-09T09:15:00.000+05:30]: Value of a in func1: 6952 | |
// [2025-01-09T09:15:00.000+05:30]: | |
// ########### Day ends ########### | |
// [2025-01-10T09:15:00.000+05:30]: | |
// ########### Day starts ########### | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 3477 | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 3477 | |
// [2025-01-10T09:15:00.000+05:30]: --------- Loop starts --------- | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 6953 | |
// [2025-01-10T09:15:00.000+05:30]: Value of a in func1: 6954 | |
// [2025-01-10T09:15:00.000+05:30]: | |
// ########### Day ends ########### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@version=5 | |
indicator(title='UT Bot Stochastic RSI', overlay=true) | |
fun(num) => | |
var counter = 1 | |
counter := counter + num | |
log.info("num=" + str.tostring(num) + " counter=" + str.tostring(counter)) | |
fun(1) | |
fun(10) | |
// [2011-09-26T03:45:00.000-00:00]: num=1 counter=2 | |
// [2011-09-26T03:45:00.000-00:00]: num=10 counter=11 | |
// [2011-09-27T03:45:00.000-00:00]: num=1 counter=3 | |
// [2011-09-27T03:45:00.000-00:00]: num=10 counter=21 | |
// [2011-09-28T03:45:00.000-00:00]: num=1 counter=4 | |
// [2011-09-28T03:45:00.000-00:00]: num=10 counter=31 | |
// [2011-09-29T03:45:00.000-00:00]: num=1 counter=5 | |
// [2011-09-29T03:45:00.000-00:00]: num=10 counter=41 | |
// This shows that the var variable is not shared between the functions. Each function call has var in its own scope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment