Local variables are declared in a script section this way:
' ---------------------------------------------
' Declare Local Variables in a manner similar
' to these three declaration, but you should
' consider using more meaningful names if it
' is important
Variables: AnyNum1, AnyNum2, AnyNum3 TYPE: INTEGER
Variables: AnyFloat1, AnyFloat2, AnyFloat3 TYPE: FLOATING
Variables: AnyText1, AnyText2, AnyText3 TYPE: STRING
Variables: pAnyPrice TYPE: PRICE
Local variables are not cleared to zero or any other value when they are declared. Clearing a local variable is the responsibility of the script section in which they are declared and used. Assigning a value to a local variable is no different than assigning a value to a Blox Permanent variable, a Instrument Permanent Variable.
For example, consider these value assignments for the first local variable in the three different local variable declaration types:
' ---------------------------------------------
' Assign Some Value to these three variable types
AnyNum1 = 100
AnyFloat1 = 10.01563
AnyText1 = "Order Placed"
Local variables are not accessible to other scripts unless they are contained within a Custom Function. When contained in a Custom Function, all the variables contained within the script section are accessible to script section from which the Custom Function was called.
' MKT is a BPV Instrument TYPE
' Local declared variables
VARIABLES: iAvgLen, iCount, iLoadOK, x, y Type: Integer
VARIABLES: iCount, instrumentCount Type: Integer
VARIABLES: fAvgClose Type: Price
' Initialize Variables
iAvgLen = 5
iCount = 0
' Get the large Stock Portfolio instrument count.
instrumentCount = system.totalInstruments
' Loop printing the symbol for each instrument.
For x = 1 TO instrumentCount STEP 1
' Load this portfolio instrument into context.
iLoadOK = Mkt.LoadSymbol( x )
' Print out the file name.
If iLoadOK = TRUE THEN
' Initialize Variables
iCount = 0
fAvgClose = 0
' Sum the Close Prices
For y = 0 TO iAvgLen - 1
' Add Close Prices
fAvgClose = fAvgClose + Mkt.close
Next
' Calculate the Average Close Price
fAvgClose = (fAvgClose / iAvgLen)
' Display the Symbol Information Results
PRINT x, Mkt.symbol, fAvgClose
ENDIF
Next ' x
Edit Time: 10/29/2020 11:52:35 AM |
Topic ID#: 408 |