NexusFi: Find Your Edge


Home Menu

 





Does a variable in a function hold value between bars?


Discussion in MultiCharts

Updated
    1. trending_up 1,020 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 101 since May 2019
Thanks Given: 8
Thanks Received: 12

So I'm looking at the code for the Parabolic SAR that is included with MC. Here's my question...

I've been typically carrying values from the main strat to the functions, but here, this is the function that is within the indicator. And they declared VARIABLES for High and Low points. My original thinking was that the function gets called every bar and that the value would default again to zero in this case. But I'm starting to question this?

Does the function hold values after it runs through it's code until it's called again? Thanks for the help.

 
Code
inputs: 
	AfStep(numericsimple),     AfLimit(numericsimple),    
        oParCl(numericref),           oParOp(numericref), 
        oPosition(numericref);                                                      

variables: 
	var0( 0 ),   var1( 0 );

if High > var0 then var0 = High ;
				                                        
if Low  < var1 then var1 = Low ;


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
CFTC Requests Tag 50 Trader Identity Data From CME and I …
Traders Hideout
CFTC Rewrites the Rulebook -- Kalshi Cracks $1B Non-Spor …
Prediction Markets & Event Contracts
Energy Futures Shatter All-Time Daily Volume: 8.3 Millio …
Commodities
More Than Capable: Hegseths War Warning Validates $114M …
Prediction Markets & Event Contracts
One Wallet Made $200K in Hours: AP Probes Polymarket Cea …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Lady Vols Primer: Trading Volatility Journal
6 thanks
Trying to learn Volume and price action correlation
5 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639

Sinatra Fan,

the easiest way to find out for sure is likely to add a few print statements to the code and find out exactly what is going on with the variables within the code.

Regards,

ABCTG


Follow me on X Reply With Quote
Thanked by:
  #3 (permalink)
 Pickles1774 
Pembroke Pines
 
Experience: Beginner
Platform: NinjaTrader
Broker: Ninjatrader
Trading: Futures
Frequency: Daily
Duration: Minutes
Posts: 27 since Nov 2022
Thanks Given: 0
Thanks Received: 2


Hello ABCTG
In the code you provided, the variables var0 and var1 are declared as local variables within the scope of the function. Local variables are created and initialized each time the function is called, and their values are not retained between function calls.

In this specific code snippet, var0 is used to track the highest value of High encountered so far, and var1 is used to track the lowest value of Low encountered so far. As the function is called on each bar, these variables are updated based on the current High and Low values.

When the function is called again on the next bar, the variables var0 and var1 will be reinitialized to zero, and the process of tracking the highest High and lowest Low values will start anew.

So, in summary, the values of var0 and var1 do not persist between function calls. They are local variables that are reinitialized each time the function is executed.Hope this answers you question. Take Care!


Follow me on X Visit my NexusFi Trade Journal Reply With Quote




Last Updated on January 20, 2024


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts