Download MetaTrader 5

CopyBuffer and CopyTime Problem

To add comments, please log in or register
Somsri Sarkar
3689
Somsri Sarkar  

Hello Members,

I have following problem with CopyTime & CopyBuffer with mql5

CopyTime(Symbol(),tf,0,1,iTime);

when I am printing data for iTime[0] its showing 0:00 1970 date means no value.

Also with fractal

    handle_fractal = iFractals(_Symbol, PERIOD_CURRENT);
      ArraySetAsSeries (fractal_down, true);
                //--- get the data
                CopyBuffer(handle_fractal,LOWER_LINE, 1, 1, fractal_down);     

when printing

printf(DoubleToString(fractal_down[0]));

it shows a long string of numbers.

Where I am mistaking, could you please help?

Thank you in advance.

Regards

Vladimir Karputov
Moderator
73679
Vladimir Karputov  
Somsri Sarkar:

Hello Members,

I have following problem with CopyTime & CopyBuffer with mql5

when I am printing data for iTime[0] its showing 0:00 1970 date means no value.

Also with fractal

when printing

it shows a long string of numbers.

Where I am mistaking, could you please help?

Thank you in advance.

Regards


Please show the code that can be played. How do we know what is in your variables? How do we know which type of your variables are?

Example of the code being reproduced:

//+------------------------------------------------------------------+
//|                                                      Test_en.mq5 |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property script_show_inputs
input int            count=1;                // data count to copy 
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
void OnStart()
  {
   string            symbol_name=Symbol();   // symbol name 
   ENUM_TIMEFRAMES   timeframe=Period();     // period 
   int               start_pos=0;            // start position 
   datetime          time_array[];           // target array to copy open times 

   ResetLastError();
   int result=CopyTime(symbol_name,timeframe,start_pos,count,time_array);
   if(result==-1)
     {
      Print("CopyTime error# ",GetLastError());
      return;
     }
   if(result<count)
     {
      Print("Ordered ",IntegerToString(count),", received ",IntegerToString(result));
      return;
     }
   ArrayPrint(time_array);
  }
//+------------------------------------------------------------------+

if input parameter "data count to copy"==9, Result from the "Experts" tab:

[0] 2017.05.04 08:05:00 2017.05.04 08:06:00 2017.05.04 08:07:00 2017.05.04 08:08:00 2017.05.04 08:09:00
[5] 2017.05.04 08:10:00 2017.05.04 08:11:00 2017.05.04 08:12:00 2017.05.04 08:13:00
Files:
Test_en.mq5 3 kb
Somsri Sarkar
3689
Somsri Sarkar  
Vladimir Karputov:


Please show the code that can be played. How do we know what is in your variables? How do we know which type of your variables are?

Example of the code being reproduced:

if input parameter "data count to copy"==9, Result from the "Experts" tab:


Hello Vladimir, Pardon I solve the copytime problem, I was allocating it inside a loop thats why it was not working.

But Copybuffer with fractal indicator is still showing a long string. Here is the details with variable allocation & its type:

int handle_fractal,FractalBar = 5;
double fractal_up[],fractal_down[];

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[])
  {

handle_fractal = iFractals(_Symbol, PERIOD_CURRENT);
ArraySetAsSeries (fractal_down, true);
ArraySetAsSeries (fractal_up, true);

 for(int f = 0; f<=FractalBar; f++)
               {
               //--- get the data
                CopyBuffer(handle_fractal, LOWER_LINE, f, 1, fractal_down);               
               if(fractal_down[f]!= 0) // Current chart Dwn
               Do something          
               }

//--- return value of prev_calculated for next call
   return(rates_total);
  }

Even if I don't use the loop, use the plain code as following:

      //--- get the data
                CopyBuffer(handle_fractal,LOWER_LINE, 1, 1, fractal_down);      
printf(DoubleToString(fractal_down[0],_Digits));

it still prints a long string of data:

2017.05.04 14:46:38.647 Indicator MT5 (GBPUSD,M4)       179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.00000000
Vladimir Karputov
Moderator
73679
Vladimir Karputov  

IFractal indicator in the indicator buffer can store:

  • price (in this case, you see the arrow)
  • or a value EMPTY_VALUE

Here is a snippet of the iFractal indicator code:

   if(prev_calculated<7)
     {
      limit=2;
      //--- clean up arrays
      ArrayInitialize(ExtUpperBuffer,EMPTY_VALUE);
      ArrayInitialize(ExtLowerBuffer,EMPTY_VALUE);
     }
   else limit=rates_total-5;

   for(i=limit;i<rates_total-3 && !IsStopped();i++)
     {
      //---- Upper Fractal
      if(high[i]>high[i+1] && high[i]>high[i+2] && high[i]>=high[i-1] && high[i]>=high[i-2])
         ExtUpperBuffer[i]=high[i];
      else ExtUpperBuffer[i]=EMPTY_VALUE;

      //---- Lower Fractal
      if(low[i]<low[i+1] && low[i]<low[i+2] && low[i]<=low[i-1] && low[i]<=low[i-2])
         ExtLowerBuffer[i]=low[i];
      else ExtLowerBuffer[i]=EMPTY_VALUE;
     }

So the indicator buffer iFractal does not have a value of "0.0".

Somsri Sarkar
3689
Somsri Sarkar  
Vladimir Karputov:

IFractal indicator in the indicator buffer can store:

  • price (in this case, you see the arrow)
  • or a value EMPTY_VALUE

Here is a snippet of the iFractal indicator code:

So the indicator buffer iFractal does not have a value of "0.0".


Still not clear. I need price just like it shows up in mql4 with ifractal function. In mql4 for Fractal up it shows double value and if there is no fractal up its shows 0

Where I should use the EMPTY_VALUE on my code structure.

Thank you in advance

whroeder1
16353
whroeder1  
printf(DoubleToString(fractal_down[0],_Digits));
  1. Perhaps you should read the manual. PrintFormat takes a format string and one or more values. You meant Print
  2. There will never be a fractal on the current bar (or bar one.) Try 2.
Somsri Sarkar
3689
Somsri Sarkar  
whroeder1:
  1. Perhaps you should read the manual. PrintFormat takes a format string and one or more values. You meant Print
  2. There will never be a fractal on the current bar (or bar one.) Try 2.


Hello whroeder,

Thank you for the suggestion. I tried it with Print & PrintFormat both. Didn't created any difference with 0 index, long string number.

Plus with fractal_down[2] as you suggested, it shows array out of range error in both cases.

Vladimir Karputov
Moderator
73679
Vladimir Karputov  
Somsri Sarkar :


Hello whroeder,

Thank you for the suggestion. I tried it with Print & PrintFormat both. Didn't created any difference with 0 index, long string number.

Plus with fractal_down[2] as you suggested, it shows array out of range error in both cases.


Check already in the help what is the value of EMPTY_VALUE. 

IFractal indicator in the indicator buffer can store:

  • or price (in this case, you see the arrow)
  • or a value EMPTY_VALUE
So in the indicator buffer iFractal can be either a price or a EMPTY_VALUE.
Somsri Sarkar
3689
Somsri Sarkar  
Vladimir Karputov:


Check already in the help what is the value of EMPTY_VALUE. 

IFractal indicator in the indicator buffer can store:

  • or price (in this case, you see the arrow)
  • or a value EMPTY_VALUE
So in the indicator buffer iFractal can be either a price or a EMPTY_VALUE.


Okay I got it finally, What I did is I manually check the chart on which bar fractal formed, then input that bar index & it print function showing it correctly. 

In this case, EMPTY_VALUE seems a long digit number when I try to print it. That's why the confusion.

I solve it with following line of code:

if(fractal_down[0]!= EMPTY_VALUE) Do something;
To add comments, please log in or register