arithmetical coding related question

 

Hello MQL4 community,

Currently, I'm saving prices to a single dimension vector (array) and wish to determine if these prices show upward/downward direction. I am able to complete this task arithmetically but wish to read other coder inputs for simpler methods of going about coding this.

Task requirements:

1. Save prices to a vector.

2. Arithmetically calculate vector prices to determine price direction.


The 'Math & Trig' section in the MQL4 dictionary offers a limited number of functions for completing this task but I'm still scouring it for possible code to implicate into an EA. The most applicable functions appear to be MathMin() and MathMax() functions. If there's a possibility to write custom mathematical functions which could be incorporated into a .dll library then read by the EA, this would put a smile on my face ;) I am unaware of this as an alternative presently.


A method I'm following involves saving prices (contained within groups segregated by sections of time) to a vector then separating these prices into pairs. Once in pairs, I'll write code to check if the first price is greater than the second price... If it is, I'll code the EA to subtract the second price from the first price and save the result to a separate vector. This process is continued until all prices have been calculated. Once calculated the EA can distinguish price direction. I seek a simpler method to accomplish this specific task. If any coders have been down this road before and wish to offer a suggestion and/or advice, I would be grateful.


Thank you

 
Moving average will give you a direction.
 
WhooDoo22:

Hello MQL4 community,

Currently, I'm saving prices to a single dimension vector

Do you really mean "Vector" ?
 
Thank you both for your responses Andrew and Simon.
 
RaptorUK:
Do you really mean "Vector" ?
And the answer ?
 
RaptorUK:
And the answer ?

Arrays store certain data-type and a vector stores certain (other type) data-type.


Thank you

 

The word "vector" is used in various slightly different ways in different contexts. In mathematics, a vector is an object which transforms in a certain way under geometrical transformations. But informally, it's a fixed size sequence of numbers, same as a fixed size array.

Do I understand correctly, that what you are storing are tick by tick prices?  One handy trick for storing such information is to use modulo arithmetic with array indices. Suppose you are never going to be interested in more than the last 1000 price ticks. Then create an array of 1000 doubles, and a index pointer that says where you are in the array. Then increment this index each time you add a new price, but reset it to zero each time it reaches 1000. This way you reuse the old parts of the array. You just have to remember to use modulo arithmetic for all operations that deal with indices (eg if you want the price 100 back from the current one, subtract 100 from the index, but if it is then below 0 add 1000.

 

Liam,

Do I understand correctly, that what you are storing are tick by tick prices?

Yes.


"create an array of 1000 doubles..."

Don't you mean to declare the array with double data-type, then I could use ArrayResize() to initialize the array with a thousand indexes right?

Once the array's last index becomes full, use ArrayInitialze() to initialize all values of array to zero.


", and a index pointer that says where you are in the array...."

I'm not quite sure I understand what you mean by a "pointer". Could you explain this please?


"You just have to remember to use modulo arithmetic for all operations that deal with indices (eg if you want the price 100 back from the current one, subtract 100 from the index, but if it is then below 0 add 1000."

Yeah, I believe I can do this. I just wished to hear other coder inputs to broaden my options.


Thank you much Liam

 
WhooDoo22:

Arrays store certain data-type and a vector stores certain (other type) data-type.

What data type ?
 
WhooDoo22:


"create an array of 1000 doubles..."

Don't you mean to declare the array with double data-type, then I could use ArrayResize() to initialize the array with a thousand indexes right?

Nope,  why not just declare the array ?

double ArrayName[1000];   //  declare an array of 1000 elements

 

WhooDoo22:


", and a index pointer that says where you are in the array...."

I'm not quite sure I understand what you mean by a "pointer". Could you explain this please?

Pointer is a bit of an unfortunate word to use as mql4 does not use pointers . . . .  index is a much better word IMO and it is the cell or place in the array where yo want to read a value from or write a value to,  just like you do with the Order pool.  So if you want the 5th value in the array you use ArrayName[4]   and 4 is the index
 
RaptorUK:
What data type ?

A vector has quantity, direction and mass. Arrays store vectors. I guess when it all boils down, a vector can have any data-type, assuming the quantity has direction and mass.

A vector typically has a usual data-type of double or integer. It's all just more ways to crunch numbers.


Thank you

Reason: