## Function Collection (MQ4)

### Function Collection (MQ4)

Here i will, u can post the functions that you can use as part of your own implementation.

Apprentice
FXCodeBase: Confirmed User

Posts: 20850
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### MathTanh

Code: Select all
`double MathTanh(double x){    double exp;   double returnNum;   if(x>0)     {       exp=MathExp(-2*x);       returnNum= (1-exp)/(1+exp);       return (returnNum);     }   else     {       exp=MathExp(2*x);       returnNum=(exp-1)/(1+exp);       return (returnNum);     }}`

Apprentice
FXCodeBase: Confirmed User

Posts: 20850
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

### Moving all elements up one place in an array

Moving array elements up one value to insert a new value at the beginning of the array can be a bit tedious to code. If the array has been switched around so that element 0 is the right most element then an extra degree of frustration is added to the issue.

This is how I solved the problem for my current project.

Let’s assume we have a dynamic array of 100 structures elements and the rightmost element is 0.
Code: Select all
`struct TestStruct{   int     value1;   double value2;   string value3;};TestStruct Test[]ArrayResize(Test, 100);      // Give it a size of 100ArraySetAsSeries(Test, true); // Turn the array around so the element 0 is the far right one`

Now, your program has been working as you intended but the array is now full of data and you want to add the new element to the beginning of the array at element 0 (farthest right element) and move all of the other element values up one and drop the old 100th element off.

The easiest way to do this that I have found is as follows.

Code: Select all
`    // Set the array to read from left to right as a normal array does    ArraySetAsSeries(Test, false);     // Add a new empty element to the end     ArrayResize(Test, 101);    // Set the array to read from right to left similar to the bars on a chart    ArraySetAsSeries(Test, true);    // Now the array has been turned around delete the last element        ArrayResize(Test, 100);`

Done

Cheers,

John
skinner36

Posts: 1
Joined: Thu Sep 20, 2018 10:10 pm