need help to convert code to mt5 - page 2

 

ok you said i got help, but where's the code help?

.
 
mrluck012:

ok you said i got help, but where's the code help?

.

 
mrluck012:

I can code for mql4 but no mql5, because THERE IS NO BOOK OUT THERE, and it's easy if you study programming in college, but i didn't, i just need 1 example of Close [ 1 ] code, simple, i don't want you to code for me, but show me some examples, that's the purpose of this forum

Here is your 'Book' about mql5 in pdf format.  Regards.
 

I don't want to learn mql5, because i like only to work with mt4, but i need this to work

while (i<=10)

{

Close [ i ]; // what's the equivalent to that on mql5???? just the code, no reference

// then i'll copy this value to csv...

i= i+1;
}
 
mrluck012:

I don't want to learn mql5, because i like only to work with mt4, but i need this to work

If you do not want to learn mql5, ok, but do not say there is no mql5 Book. 

I had answered in your other post with the code explained step by step, but that post has been deleted (I guess a moderator has deleted it in duplicate), so seeing that you have no intention of learning anything, I will not repeat here the code that I showed there.


Regards.

 
Jose Francisco Casado Fernandez:

If you do not want to learn mql5, ok, but do not say there is no mql5 Book. 

I had answered in your other post with the code explained step by step, but that post has been deleted (I guess a moderator has deleted it in duplicate), so seeing that you have no intention of learning anything, I will not repeat here the code that I showed there.


Regards.


i tried your way, but it didn't work, i think your style of coding is a bit difficult to understand, no offense, but thanks a lot for helping anyway, i think it's too complicated, they should make it way more simple, why not a simple array like mql4? 5000 pages? no way, and that's not a book, it's only a compilation that works once you already grasp the concepts. 

 
mrluck012:

i tried your way, but it didn't work, i think your style of coding is a bit difficult to understand, no offense, but thanks a lot for helping anyway, i think it's too complicated, they should make it way more simple, why not a simple array like mql4? 5000 pages? no way, and that's not a book, it's only a compilation that works once you already grasp the concepts. 

My code works perfectly to get the closing data. Another thing is that the way you were saving it in the file was right or not. If something fails, it would be that, or something else from the rest of your code, but not my code.

If it is an indicator, you can use the predefined array (close [i]) inside the OnCalculate () function. That way, you do not need to use the CopyClose () function. You just have to sort the data as Series and make your loop:


int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

   if(!ArraySetAsSeries(close, true))  return;
   
// ---------------   the rest of your code about opening the file, etc.

   for(i=limit;i>=0;i--)
      {
            
        // You can use here:   close[i]  where you want.
      }
   
//--- the rest of your code

   return(rates_total);
  }


My code is not complicated, it's how things are done in mql5. If you want to use CopyClose(), you have to know that the first time you call that function it is possible that the data are not synchronized (especially if you request the data of another symbol or another timeframe different from the current chart)  and therefore you do not get all the data you need. Therefore, the developers recommend checking this, and if all the data has not been copied, then return and wait for the next call.

In mql4, it happens in a similar way if you request the data of another symbol or another timeframe different from the current chart. In that case you would have to use either CopyClose() (yes, it can be used in mql4, too) or iClose(), and you would have to handle errors 4066 and 4073:


4066

ERR_HISTORY_WILL_UPDATED

Requested history data is in updating state

4073

ERR_NO_HISTORY_DATA

No history data



Another thing is that you do not know anything about all this and call those functions without checking anything or checking any errors , which means that you risk that your code has numerous bugs. If you do not do it this way, or do not know how to do it, does not mean that you would not have to do it.


As for the function of opening the file, you should always check if it has been opened correctly (otherwise the function will return INVALID_HANDLE), before trying to save anything in such file. This you should do the same in mql4. The bad thing is that it seems that you still have a lot to learn (also about mql4 and not just about mql5). I hope you have the will for it.

Regards.

CopyClose - Timeseries and Indicators Access - MQL4 Reference
CopyClose - Timeseries and Indicators Access - MQL4 Reference
  • docs.mql4.com
The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. If you know the amount of data you need to copy, it should better be done to a statically...
 

Here add as a new function below your code so that you can use the classic way.

//+------------------------------------------------------------------+
//| iClose function                                                  |
//+------------------------------------------------------------------+
double iClose(string symbol,ENUM_TIMEFRAMES timeframe,int shift)
  {
   double close_array[];
   ArrayResize(close_array,shift,1);
   ArraySetAsSeries(close_array,1);
   int copy=CopyClose(symbol,timeframe,shift,1,close_array);
   double result=close_array[shift];
   return (result);
  }
//+------------------------------------------------------------------+

You can find also on my git https://github.com/Thecreator1/MQL4-TO-MQL5/blob/master/iFunctions.mq5