Download MetaTrader 5
To add comments, please log in or register
Do you have idle PCs? Connect them to MQL5 Cloud Network and earn money!
Ndumiso Mavuso
4305
Ndumiso Mavuso 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 copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#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?

Carl Schreiber
5966
Carl Schreiber 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?

Read the docs about arrays with al ot of examples!
Ndumiso Mavuso
4305
Ndumiso Mavuso 2016.01.07 16:02  
calli:
Read the docs about arrays with al ot of examples!
Care to share a link to the docs with examples I could learn from?
Marco vd Heijden
Moderator
4084
Marco vd Heijden 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 ?

https://www.mql5.com/en/docs/array

Documentation on MQL5: Array Functions
Documentation on MQL5: Array Functions
  • www.mql5.com
Array Functions - Reference on algorithmic/automated trading language for MetaTrader 5
Ndumiso Mavuso
4305
Ndumiso Mavuso 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.

Marco vd Heijden
Moderator
4084
Marco vd Heijden 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....

Ndumiso Mavuso
4305
Ndumiso Mavuso 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 copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#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);
  }

Your effort is much appreciated.

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

Alain Verleyen
Moderator
28701
Alain Verleyen 2016.01.08 12:23  

Please read this article

MQL5 Programming Basics: Arrays
MQL5 Programming Basics: Arrays
  • 2013.03.11
  • Dmitry Fedoseev
  • www.mql5.com
Arrays are an integral part of almost any programming language along with variables and functions. The article should be of interest primarily to novice MQL5 programmers, while experienced programmers will have a good opportunity to summarize and systematize their knowledge.
/
To add comments, please log in or register