NexusFi: Find Your Edge


Home Menu

 





Does a variable in a function hold value between bars?


Discussion in MultiCharts

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




 
Search this Thread

Does a variable in a function hold value between bars?

  #1 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 66 since May 2019
Thanks Given: 7
Thanks Received: 9

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?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

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 Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 Pickles1774 
Pembroke Pines
 
Experience: Beginner
Platform: NinjaTrader
Broker: Ninjatrader
Trading: Futures
Frequency: Daily
Duration: Minutes
Posts: 23 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 Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on January 20, 2024


© 2024 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 - Privacy Policy - Downloads - Top
no new posts