Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has classes?
SteG73
11
SteG73 2015.12.16 16:12 

Hello everyone!

this my discovery today.

I want to draw directly  on my chart, and i use CCanvas class and its method.

BUT...

This is my code

 //--- START conversion precision TEST

   ChartHeight=ChartPixelsGet('H'); // ChartGetInteger inside

   ChartWidth=ChartPixelsGet('W'); // ChartGetInteger inside

   Tela.Resize(ChartWidth,ChartHeight);

...

   int xTest[2], yTest[2];

   ChartTimePriceToXY(0,0,Main_Rates[1].time,Main_Rates[1].open,xTest[0],yTest[0]);  Err+=GetLastError();

   ChartTimePriceToXY(0,0,Main_Rates[1].time,Main_Rates[1].close,xTest[1],yTest[1]);  Err+=GetLastError();

   Tela.Rectangle(xTest[0]-3,yTest[0],xTest[1]+3,yTest[1],ColorToARGB(clrYellow,255));

   

   Tela.Update();

//--- END conversion precision TEST

NOTE: Tela is an object of CCanvas class; Main_Rates is an array of Mqlrate type; xTest, yTest are int variable.

and this is the result:

 

 I can't belive! my yellow rectangle is different from the candelstick, but the Time and Price data in mqlrate array are right !

In my opinion, it is the conversion method to be wrong.

Infact with this correction, before drawing:

   yTest[0]-=3;

   yTest[1]-=3; 

it seems works...

but it is a very bad solution. 

Can someone give me a feedback to this problem? 

 

thank you so mutch!

bye 

Alain Verleyen
Moderator
30295
Alain Verleyen 2015.12.16 17:59  

You will need to provide all the relevant code, otherwise there is no way to check if the problem comes from your code or from MT4/mql4 (Canvas).

 I can't belive! my yellow rectangle is different from the candelstick, but the Time and Price data in mqlrate array are right !

You think they are right or you checked they are right ? We can't guess.

SteG73
11
SteG73 2015.12.28 16:18  
Alain Verleyen:

You will need to provide all the relevant code, otherwise there is no way to check if the problem comes from your code or from MT4/mql4 (Canvas).

You think they are right or you checked they are right ? We can't guess.

Hi Alain, thank you for your answer. Sorry for my delay, but the "official job" has all my time.

I'm new here and I'm learning to use the forum tools...

I insert the code that i have run on a chart EURUSD and if you zoom to the maximum scale you can see the "error".

Thank you for all your help!!!

Stefano

PS. I have verified  that the data are correct comparing the pop up on the chart and the printing data from MqlRates.

 

//+------------------------------------------------------------------+
//|                                                  BananaChart.mq4 |
//|                                                  Stefano Gallone |
//|                                                                  |
//+------------------------------------------------------------------+
#include <Canvas\Canvas.mqh>
//---
#property copyright "Stefano Gallone"
#property link      ""
#property version   "1.00"
#property strict
//---
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- 
#property indicator_label1  "BANANA"
//--- Costanti
// Costanti del periodo espresso in minuti!
const int Std_Period[10]={ PERIOD_CURRENT, //0
                              PERIOD_M1, //1
                              PERIOD_M5, //5
                              PERIOD_M15, //15
                              PERIOD_M30, //30
                              PERIOD_H1, //60
                              PERIOD_H4, //240
                              PERIOD_D1, //1440
                              PERIOD_W1, //10080
                              PERIOD_MN1}; //43200
//--- layer di disegno
CCanvas Tela;


//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int OnInit() 
  { 

//--- settaggio dal layer di disegno
   int ChartWidth=0, ChartHeight=0;
  
   ChartHeight=ChartPixelsGet('H');
   ChartWidth=ChartPixelsGet('W');
   
   ResetLastError();
      if (!Tela.CreateBitmapLabel("Tela",0,0,ChartWidth-10,ChartHeight-10,COLOR_FORMAT_ARGB_NORMALIZE))
      Print("ERRORE CREAZIONE TELA: ",GetLastError());
   Tela.Erase(ColorToARGB(clrBlack,0)); //reset dell'area di disegno.

   return(INIT_SUCCEEDED);
  }


//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
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[]) 
  { 
//---
   MqlRates Main_Rates[], Sub_Rates[], M1_Rates[]; 
   int copied, Current_Period=0, Sub_Period=0;
   int i=0;
   int x[5],y[5];
   int ChartWidth=0, ChartHeight=0;
   int Err=0;
   
//--- 
   ArraySetAsSeries(Main_Rates,true); 
   ArraySetAsSeries(Sub_Rates,true); 
   ArraySetAsSeries(M1_Rates,true); 

//--- setting del periodo corrente e del sottoperiodo da usare per l'analisi.
   Current_Period=Period();
   for (i=1; i<10 && Std_Period[i]!=Current_Period;i++);
   if (i>1) Sub_Period=Std_Period[i-1];
   else Sub_Period=Current_Period;
   
//--- ultima candela completa per il periodo corrente
   CopyRates(Symbol(),Current_Period,0,2,Main_Rates);

//--- ultime candele per M1 corrispondente al periodo precedente a quello corrente.
//--- calcolo della media interna alla candela.


   ChartHeight=ChartPixelsGet('H');
   ChartWidth=ChartPixelsGet('W');
   Tela.Resize(ChartWidth,ChartHeight);

   ResetLastError();
   
         
//--- START convertion precision TEST
   int xTest[2], yTest[2];
   ChartTimePriceToXY(0,0,Main_Rates[1].time,Main_Rates[1].open,xTest[0],yTest[0]);  Err+=GetLastError();
   ChartTimePriceToXY(0,0,Main_Rates[1].time,Main_Rates[1].close,xTest[1],yTest[1]);  Err+=GetLastError();

   
   Tela.Rectangle(xTest[0]-3,yTest[0],xTest[1]+3,yTest[1],ColorToARGB(clrYellow,255));

   Tela.Update();
//--- END convertion precision TEST
   
//--- return value of prev_calculated for next call 
   return(rates_total); 
  } 



//+------------------------------------------------------------------+
//| Chart property width end height                                  |
//+------------------------------------------------------------------+
int ChartPixelsGet(char Dim,const long chart_ID=0,const int sub_window=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
   int DimentionToGet=CHART_WIDTH_IN_PIXELS;
   switch (Dim)
   {
      case 'W': DimentionToGet=CHART_WIDTH_IN_PIXELS; break;
      case 'H': DimentionToGet=CHART_HEIGHT_IN_PIXELS; break;
      default: DimentionToGet=CHART_WIDTH_IN_PIXELS; break;
   }
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,DimentionToGet,sub_window,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }

/
To add comments, please log in or register