Pass variable to Panel

To add comments, please log in or register
dcagapie
43
dcagapie  

Hello everybody.

I have a very simple piece of code that calculates candle size (current and previous).

Then, based on the simple panel sample, I created a panel with 2 labels.

I searched, but I was not able to find how to get the variables on the panel. I'm sure there is a way...

//+------------------------------------------------------------------+
//| 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[])
  {    
//Previous candle
   int prevbodylength;
   if(Open[1]<Close[1]) prevbodylength=MathRound((Close[1]-Open[1])/myPoint); //Bull candle
   else prevbodylength=MathRound((Open[1]-Close[1])/myPoint); //Bear candle
//Previous candle

//Current candle     
   int currbodylength;
   if(Open[0]<=Close[0]) currbodylength=MathRound((Close[0]-Open[0])/myPoint); //Bull candle
   else currbodylength=MathRound((Open[0]-Close[0])/myPoint); //Bear candle
//Current Candle 
   
   ExtDialog.RefreshValues();
   return(rates_total);
  }
//+------------------------------------------------------------------+

I tried

m_LblPrevious.Text("Previous candle: "+prevbodylength);

...inside the RefreshValues() function of the Panel,but the code doesn't compile.

Marco vd Heijden
Moderator
12735
Marco vd Heijden  

I don't see any panel.

And i don't see any error or error code.

You can assign text values with 

ObjectSetString();

And other values with

ObjectSetInteger();
dcagapie
43
dcagapie  

Thank you for the suggestion.

This is the code that creates the error.

//+------------------------------------------------------------------+ 
//| Refresh Values                                                   | 
//+------------------------------------------------------------------+ 
bool CPanelDialog::RefreshValues()
  {
  m_LblTest1.Text("Prev: "+prevbodylength);
  m_LblTest2.Text("Curr: "+currbodylength);   
//--- succeed 
   return(true);  
  }
//+------------------------------------------------------------------+ 

And this is the panel I'm trying to build:

Panel

The panel interface is in a separate *.mqh file.

Marco vd Heijden
Moderator
12735
Marco vd Heijden  

You have to pass the parameters to the function

//+------------------------------------------------------------------+
//| 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[])
  {    
//Previous candle
   int prevbodylength;
   if(Open[1]<Close[1]) prevbodylength=MathRound((Close[1]-Open[1])/myPoint); //Bull candle
   else prevbodylength=MathRound((Open[1]-Close[1])/myPoint); //Bear candle
//Previous candle

//Current candle     
   int currbodylength;
   if(Open[0]<=Close[0]) currbodylength=MathRound((Close[0]-Open[0])/myPoint); //Bull candle
   else currbodylength=MathRound((Open[0]-Close[0])/myPoint); //Bear candle
//Current Candle 
   
   ExtDialog.RefreshValues(prevbodylength,currbodylength);
   return(rates_total);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+ 
//| Refresh Values                                                   | 
//+------------------------------------------------------------------+ 
bool CPanelDialog::RefreshValues(int prevbodylength,int currbodylength)
  {
  m_LblTest1.Text("Prev: "+prevbodylength);
  m_LblTest2.Text("Curr: "+currbodylength);   
//--- succeed 
   return(true);  
  }
//+------------------------------------------------------------------+ 
Or make them into global variables.
dcagapie
43
dcagapie  
Thank you! That did it.
Marco vd Heijden
Moderator
12735
Marco vd Heijden  

Great.

So remember next time post all the relevant code.

To add comments, please log in or register