NexusFi: Find Your Edge


Home Menu

 





saving values from a multi-dimensional array


Discussion in MultiCharts

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




 
Search this Thread

saving values from a multi-dimensional array

  #1 (permalink)
infe2015
stockholm Sweden
 
Posts: 5 since Mar 2016
Thanks Given: 2
Thanks Received: 1

Hi i need too saving some values in a multi-dimensional array
i have done it i a singel array like this
Upp1 = CUpp[1];
Upp2 = CUpp[2];
Upp3 = CUpp[3];
Upp4 = CUpp[4];
Upp5 = CUpp[5];
CuppSum = Summationarray(CUpp,5);
but i cant find the solution for multi-dimensional.
Thanks Infe

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
What broker to use for trading palladium futures
Commodities
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Cheap historycal L1 data for stocks
Stocks and ETFs
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
24 thanks
ApexTraderFunding.com experience and review
13 thanks
Trading with Intuition
12 thanks
GFIs1 1 DAX trade per day journal
9 thanks
EG Indicators
8 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

infe2015,

what exactly seems to be the problem?

When storing values in a multidimensional array the only difference is that you have to specify all dimensions.

For your summation you will likely have to build your own function/code that cycles through all the array elements that you want to sum using a for loop.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #3 (permalink)
zaruski
Salt Lake City, UT
 
Posts: 11 since Jun 2017
Thanks Given: 0
Thanks Received: 1


You can certainly achieve this using a recursive method.

BE AWARE, RECURSION CAN BE VERY SLOW AND MEMORY INTENSIVE!

Here is some C# code where I create an array with the following elements:
Element 0: Value 1
Element 1: Array with values 2 and 3
Element 2: Value 4
Element 3: Array with 2 elements:
Element 0: Array with two values: 5 and 6
Element 1: Value 7

The sum should be 28.

static void Main(string[] args)
{
object[] o = new object[4];
int value1 = 1;
object[] array1 = new object[2] {2, 3};
int value2 = 4;

object[] array_2_element_0 = new object[]{5,6};
object[] array2 = new object[2]{array_2_element_0, 7};

o[0] = value1;
o[1] = array1;
o[2] = value2;
o[3] = array2;

int sum = Sum(o);
Console.WriteLine(sum);
}

private static int Sum(object obj)
{
int result = 0;

if (obj is object[])
{
object[] arr = (object[]) obj;
foreach (object o in arr)
{
result += Sum(o);
}
}
if (obj is int)
{
result = (int) obj;
}

return result;
}

Reply With Quote
  #4 (permalink)
zaruski
Salt Lake City, UT
 
Posts: 11 since Jun 2017
Thanks Given: 0
Thanks Received: 1

Also, it just occurred to me, that you might be asking how to access array elements beyond the first dimension. It is done like this:

int x = array[0][0];

However, if you don't know how many dimensions you will have, then you must iterate through every element, rather than access elements by index.

Reply With Quote




Last Updated on August 17, 2017


© 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