# Learning Arrays Help

Do you have idle PCs? Connect them to MQL5 Cloud Network and earn money!
4305
2016.01.07 13:25

I spent so much time on the Book I do not think I yet get it.

Lets say I want to compare current calculation results with previously taken. I store all results, when new one come in I compare them to the last stored.

My attempt to code arrays

//+------------------------------------------------------------------+
//|                                                        Print.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+-----------------------------------------------------------Ndumiso+
#property version   "1.00"

double array[50],RT,UsePoint,Price=2;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+-----------------------------------------------------------Ndumiso+
int OnInit()
{
//---
UsePoint = PipPoint(Symbol());

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+-----------------------------------------------------------Ndumiso+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+-----------------------------------------------------------Ndumiso+
void OnTick()
{
RT=NormalizeDouble(Bid-Price*UsePoint,Digits);
array[0]=RT;
Print("RT:",DoubleToStr(RT,Digits),"","PreviousRT:",DoubleToStr(array[49],Digits));// array[49] value return zero always why?

}
//+------------------------------------------------------------------+
//| Broker Digits                                                    |
//+-----------------------------------------------------------Ndumiso+

double PipPoint(string Currency)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 3)double CalcPoint = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
return(CalcPoint);
}

What I need to do to find the Last stored results?

5966
2016.01.07 14:47
Ndumiso Mavuso:

I spent so much time on the Book I do not think I yet get it.

Lets say I want to compare current calculation results with previously taken. I store all results, when new one come in I compare them to the last stored.

My attempt to code arrays

What I need to do to find the Last stored results?

4305
2016.01.07 16:02
calli:
Care to share a link to the docs with examples I could learn from?
Moderator
4084
2016.01.07 17:16

Well i don't see any code that writes to the array so it's normal that it's value is zero ?

Documentation on MQL5: Array Functions
• www.mql5.com
4305
2016.01.07 20:15

I have read pretty much on that doc and book, not helping in my view, no examples only two examples on book which are not close.

The code that writes to the array might be just what I need at the moment to continue learning.

Thank You Anyway for helping.

Moderator
4084
2016.01.07 20:35

You reserve 50 empty bottles,

The goal is to pour a liquid in them.

But you don't put anything in them and then ask the question, why is bottle 49 empty ?

you have to put something in to get a reading out of it....

4305
2016.01.07 22:05

Thank you Marco. But as I said I am Learning here. Your Questions are helpful, its what I need so that I go and learn more to answer the question you ask when I am wrong, and that is something one can never find in the Book or Documents.

//+------------------------------------------------------------------+
//|                                                        Print.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+-----------------------------------------------------------Ndumiso+
#property version   "1.00"

double array[5],RT,UsePoint,Price=2;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+-----------------------------------------------------------Ndumiso+
int OnInit()
{
//---
UsePoint = PipPoint(Symbol());

//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+-----------------------------------------------------------Ndumiso+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+-----------------------------------------------------------Ndumiso+
void OnTick()
{
RT=NormalizeDouble(Bid-Price*UsePoint,Digits);

for (int i=4; i>1; i--)
{
array[i]=array[i-1];
array[i-1] = RT;
}

Print("RT:",DoubleToStr(RT,Digits),"","PreviousRT:",DoubleToStr(array[2],Digits));

}
//+------------------------------------------------------------------+
//| Broker Digits                                                    |
//+-----------------------------------------------------------Ndumiso+

double PipPoint(string Currency)
{
int CalcDigits = MarketInfo(Currency,MODE_DIGITS);
if(CalcDigits == 2 || CalcDigits == 3)double CalcPoint = 0.01;
else if(CalcDigits == 4 || CalcDigits == 5) CalcPoint = 0.0001;
return(CalcPoint);
}

I have now filled the array with RT and element 2 seems to be the previous last stored value of RT.

With this Learned I shall move on to the next. Again thank you for taking your time to reply to our stupid calls.

Waiting for other questions if there is any on any wrong on my code that is not making any sense

Moderator
28701
2016.01.08 12:23