NexusFi: Find Your Edge


Home Menu

 





how do I use arrays in functions


Discussion in MultiCharts

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




 
Search this Thread

how do I use arrays in functions

  #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

I can't find anywhere how to properly declare an array in a function. I'm hoping someone can help.

Lets say my function is called LAYERFUNCTION

If I have the following array in my strategy code:

Array: Layer[7](0);

How would I declare it:

a) when I code my function?

b) when I call up the function? (value1 = layerfunction(layer????);

Thanks for the help

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
What broker to use for trading palladium futures
Commodities
MC PL editor upgrade
MultiCharts
How to apply profiles
Traders Hideout
About a successful futures trader who didn´t know anyth …
Psychology and Money Management
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Sinatra Fan,

it depends whether or not you need the array outside the function, too. If you do, you would declare it within the calling code and pass the array to the function.
If you only need the array within the function you would declare it within the function.

Regards,

ABCTG


Sinatra Fan View Post
I can't find anywhere how to properly declare an array in a function. I'm hoping someone can help.

Lets say my function is called LAYERFUNCTION

If I have the following array in my strategy code:

Array: Layer[7](0);

How would I declare it:

a) when I code my function?

b) when I call up the function? (value1 = layerfunction(layer????);

Thanks for the help


Follow me on Twitter Reply With Quote
  #3 (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, if I want the values to be used in the array, it would be something like this...

FUNCTION (Name: LAYERFUNCTION):
Input: Layer[x](NumericArrayRef);

Blah blah blah

..........................


STRATEGY:
Array: Layer[7](0);

Value1 = LAYERFUNCTION(Layer);

Is this right? Do I need a [x] next to the array variable in the call statement?

Started this thread Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

Sinatra Fan,

from your pseudo code it is not clear to me what you are trying to do. Take a look at the array section and the part about "Function Array Parameter Declaration" in the free EasyLanguage Essentials PDF. This should clarify your questions. Apart from that you can also try your ideas with a simple code example.

Regards,

ABCTG



Sinatra Fan View Post
so, if I want the values to be used in the array, it would be something like this...

FUNCTION (Name: LAYERFUNCTION):
Input: Layer[x](NumericArrayRef);

Blah blah blah

..........................


STRATEGY:
Array: Layer[7](0);

Value1 = LAYERFUNCTION(Layer);

Is this right? Do I need a [x] next to the array variable in the call statement?


Follow me on Twitter Reply With Quote
Thanked by:
  #5 (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

Here's my intent. I created an array in the strat code that I'll be using within it as well as related functions that I'll be calling. In more than one of the functions, it will be changing the values of the array variables as well as will the strat. So I want the values to be moving around so to speak. So it seems that a) I will need to define the variable as "NumericArrayRef" since the values will go back and forth. My question is...

When calling up the function from within the strategy code, do I simply state it like this...

Value1 = LAYERFUNCTION(Layer);

and will that save all the values of the array variable "Layer" which is 7 items in that array, or do I need the [ ] like this...

Value1 = LAYERFUNCTION(Layer[1], Layer[2], etc);

Please let me know. I can't seem to find it anywhere. Thanks

Started this thread Reply With Quote
  #6 (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

Alright,

after some experimentation, I did figure it out.

It seems that the simplest way is this. I read that I am desiring to us an array in an "Input/Output Parameter" so I need to use the input declarations "NumericArrayRef" or "TrueFalseArrayRef" and use [x] to include all elements of the array in declaration even if I only need a few. Also, when calling the function from the strategy, I simply need the name of the array with nothing after it.

Thanks ABC.

Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
soacm
Bucharest, Romania
 
Posts: 71 since Mar 2022
Thanks Given: 38
Thanks Received: 22


Sinatra Fan View Post
Alright,

after some experimentation, I did figure it out.

It seems that the simplest way is this. I read that I am desiring to us an array in an "Input/Output Parameter" so I need to use the input declarations "NumericArrayRef" or "TrueFalseArrayRef" and use [x] to include all elements of the array in declaration even if I only need a few. Also, when calling the function from the strategy, I simply need the name of the array with nothing after it.

Thanks ABC.

Can you post an example of the solution?

Reply With Quote
  #8 (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


soacm View Post
Can you post an example of the solution?

Hi,

So I assume you know how to declare your array in the main strategy - Array: Sample[50](0); I am declaring an array called "Sample" with the size of the array being 50 and the array being numeric with the starting value for each of the 50 items set to zero.


So when I have a function and am writing the function, in the Inputs, I would include Sample[X](NumericArrayRef). Even if I only need the first 5 elements of the array Sample, I still call the whole array. I then write code in that function applicable to that array.

Last, when I'm calling the array in the strategy or anywhere for that matter, you just call the name of the array withing the parameters. For example, for Value1 = FunctionExample(Sample), I am calling on the function called "FunctionExample" that has one input that just happens to be my array called "Sample".

Let me know if this helps. Thanks

Started this thread Reply With Quote
Thanked by:
  #9 (permalink)
soacm
Bucharest, Romania
 
Posts: 71 since Mar 2022
Thanks Given: 38
Thanks Received: 22


Sinatra Fan View Post
Hi,

So I assume you know how to declare your array in the main strategy - Array: Sample[50](0); I am declaring an array called "Sample" with the size of the array being 50 and the array being numeric with the starting value for each of the 50 items set to zero.


So when I have a function and am writing the function, in the Inputs, I would include Sample[X](NumericArrayRef). Even if I only need the first 5 elements of the array Sample, I still call the whole array. I then write code in that function applicable to that array.

Last, when I'm calling the array in the strategy or anywhere for that matter, you just call the name of the array withing the parameters. For example, for Value1 = FunctionExample(Sample), I am calling on the function called "FunctionExample" that has one input that just happens to be my array called "Sample".

Let me know if this helps. Thanks

Definitely, thank you.

Reply With Quote




Last Updated on August 30, 2022


© 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