Login Page - Create Account

Support Board


Date/Time: Thu, 16 May 2024 04:36:10 +0000



[Programming Help] - How to Subtract 2 arrays

View Count: 860

[2020-08-10 22:36:12]
User681150 - Posts: 62
i keep getting errors when trying to subtract 2 arrays 'error no match for operator-' i get errors on both


sc.GetStudyArraysFromChartUsingID(1, 2, StudyArray);
  
SCFloatArrayRef array1 = StudyArray[0];
SCFloatArrayRef array2 = StudyArray[1];

SCFloatArrayRef array3 = (StudyArray[0] - StudyArray[1]) ;
// OR
SCFloatArrayRef array3 =( array1 - array2);

  

[2020-08-11 20:17:51]
Hammerhead - Posts: 14
Hi,

Wouldn't the "Index" be needed, then again I'm not overly certain about that.

Such as: SCFloatArrayRef array3 = (StudyArray[0][sc.Index] - StudyArray [1][sc.Index])

Regards,
[2020-08-13 15:36:50]
User681150 - Posts: 62
thanks Hammer

"I think" i figured it out. (documentation is all over the place with explaining this stuff, reads like random streams of thought everywhere i look)

i dont think you can do calculations when declaring/initializing a variable. So first is, declare the variable, then do the calculation...

1. declare variable (only use SCFloatArray since your not going to point the variable to any data array right now) (its going to be empty)
SCFloatArray array3;

2. now you can do a calculation using the variable. Because it is a calculation between these 3 data arrays (1 empty, 2 with data), you need to line up the values so everything falls into place, so need to use the [sc.Index] for each part involved.
array3[sc.Index] = array1[sc.Index] - array2[sc.Index]


// or plot it directly to a Subgraph
sc.Subgraph[0][sc.Index] = array1[sc.Index] - array2[sc.Index]

again, i think this is the logic. even the error messages are so garbled and useless that it is hard to decipher why something went wrong. if this platform wasn't so inexpensive with data included, i wouldnt be using it, so I drudge along. thanks for the response.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account