EA receives different data than actual chart. Please help!

 

Hey

I've created an EA. But something is wrong with it. EA receives different data than actual chart! I've attached the screeshot. As you can see in log section, it says open price is 1905.4 and close price is 1908.0 for THE LAST FORMED CANDLE. But what is in the chart is different. As you can see I hovered the mouse over last candle which is hammer like. Open price is 1908.21 and close price is 1908. Completely different!


Whats wrong?


Here is the code which I receive candles opens and closes:


CopyClose(my_symbol,my_timeframe,1,10,Close_buf);
CopyOpen(my_symbol,my_timeframe,1,10,Open_buf);
Files:
Untitled.png  108 kb
 
  1. Always post all relevant code (using Code button).
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We have no idea what my_symbol or my_timeframe is.  We have no idea what your print statement is.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  2. I assume you are printing out buff[0] of the M15. The log timestamp shows 03:10 therefor the values would be for the 03:00 candle. The Data Window and the popup shows values for 02:45. Of course, they don't match.

  3. Print your prices with correct accuracy. If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
              question about decima of marketinfo() - MQL4 programming forum 2016.05.18


 
Hi, XAUUSD is hard market to creating EA's I think you should start from majors currency pairs , it will be easiest for you as a start. Regards Greg
 
William Roeder:
  1. Always post all relevant code (using Code button).
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We have no idea what my_symbol or my_timeframe is.  We have no idea what your print statement is.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  2. I assume you are printing out buff[0] of the M15. The log timestamp shows 03:10 therefor the values would be for the 03:00 candle. The Data Window and the popup shows values for 02:45. Of course, they don't match.

  3. Print your prices with correct accuracy. If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
              question about decima of marketinfo() - MQL4 programming forum 2016.05.18


Thanks pal


Here is the code


//+------------------------------------------------------------------+
//|                                           fast-start-example.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
#include <Trade\Trade.mqh>                                         //include the library for execution of trades
#include <Trade\PositionInfo.mqh>                                  //include the library for obtaining information on positions

int               iATR_handle;                              //variable for storing the indicator handle
double            iATR_buf[];                                  //dynamic array for storing indicator values
int               iRSI_handle;                              //variable for storing the indicator handle
double            iRSI_buf[];                                  //dynamic array for storing indicator values
double            Close_buf[];                             //dynamic array for storing the closing price of each bar
double            Open_buf[];                             //dynamic array for storing the opening price of each bar

string            my_symbol;                               //variable for storing the symbol
ENUM_TIMEFRAMES   my_timeframe;                             //variable for storing the time frame

CTrade            m_Trade;                                 //structure for execution of trades
CPositionInfo     m_Position;                              //structure for obtaining information of positions
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
  
   my_symbol=Symbol();
   my_timeframe=PERIOD_CURRENT;
   
   iATR_handle=iATR(my_symbol,my_timeframe,3);
   iRSI_handle=iRSI(my_symbol,my_timeframe,4,PRICE_CLOSE);

   if(iATR_handle==INVALID_HANDLE)
   {
      Print("Failed to get the indicator handle");
      return(-1);
   }
   
   if(iRSI_handle==INVALID_HANDLE)
   {
      Print("Failed to get the indicator handle");
      return(-1);
   }
   
   ChartIndicatorAdd(ChartID(),1,iATR_handle);
   ArraySetAsSeries(iATR_buf,true);
   
   ChartIndicatorAdd(ChartID(),1,iRSI_handle);
   ArraySetAsSeries(iRSI_buf,true);
   
   ArraySetAsSeries(Close_buf,true);
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   IndicatorRelease(iATR_handle);
   ArrayFree(iATR_buf);
   IndicatorRelease(iRSI_handle);
   ArrayFree(iRSI_buf);
   ArrayFree(Close_buf);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   
   CopyBuffer(iATR_handle,0,1,1,iATR_buf);
   CopyBuffer(iRSI_handle,0,1,10,iRSI_buf);
   CopyClose(my_symbol,my_timeframe,1,10,Close_buf);
   CopyOpen(my_symbol,my_timeframe,1,10,Open_buf);


   Print("open");Print(Open_buf[0]);Print("close");Print(Close_buf[0]);
   
   }   
   

  }
//+------------------------------------------------------------------+
 
Grzegorz Pawlak:
Hi, XAUUSD is hard market to creating EA's I think you should start from majors currency pairs , it will be easiest for you as a start. Regards Greg

Yeah I know XAU is wild.

But it's not about the pair. EA doesn't work as it should be.

 
Robert hofer:

Hey

I've created an EA. But something is wrong with it. EA receives different data than actual chart! I've attached the screeshot. As you can see in log section, it says open price is 1905.4 and close price is 1908.0 for THE LAST FORMED CANDLE. But what is in the chart is different. As you can see I hovered the mouse over last candle which is hammer like. Open price is 1908.21 and close price is 1908. Completely different!


Whats wrong?


Here is the code which I receive candles opens and closes:


CopyClose(my_symbol,my_timeframe,1,10,Close_buf);
CopyOpen(my_symbol,my_timeframe,1,10,Open_buf);

Your screenshot is weird. The data shown in the tooltip and data window indicated 2021.06.01 02:45 but the time scale of the chart shows that this time is not even reached yet.

And the values printed in the log are indicating 2021.06.1 03:10

 
Alain Verleyen:

Your screenshot is weird. The data shown in the tooltip and data window indicated 2021.06.01 02:45 but the time scale of the chart shows that this time is not even reached yet.

And the values printed in the log are indicating 2021.06.1 03:10


I posted the code. As you can see I grab open and close of last formed candle and print it. Is it right?
I don't understand where the problem is
Reason: