Methods using panel

 

Hi everyone
I'm creating a panel for an indicator, the problem is the methods I can use. Until now when

I make indi i use:

- OnInit to initialize;

- OnCalculate to catch the tick movement;

- OnChartEvent to catch the mouse interactions;

- OnDeinit to destroy all at the end;


For Ea  OnTick instead OnCalculate,

For Script OnStart instead OnCalculate.


Everything works like a charm... the problem now using Panel, is that OnCalculate dont work

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   r++;
   ObjectSetString(0,"testo",OBJPROP_TEXT," - r: "+r);
   return(rates_total);
  }

So now I'm a little bit confused.... what method I can use instead OnCalculate????

OnStart??

Star???

OnTick???


Here the complite code, it's only the simple panel inside MT4 library

#property copyright "Copyright 2009-2014, MetaQuotes Software Corp."
#property link      "http://www.mql4.com"
#property version   "1.00"
#property strict

#property indicator_separate_window

#property indicator_minimum             0.0
#property indicator_maximum             0.0

#property indicator_buffers 1
#property indicator_color1 clrBlue
#property indicator_type1 DRAW_ARROW
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
#include "PanelDialog.mqh"
//+------------------------------------------------------------------+
//| Global Variables                                                 |
//+------------------------------------------------------------------+
CPanelDialog ExtDialog;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+


int r;

int OnInit(void)
  {
  
     ObjectCreate("testo",OBJ_LABEL,0,0,0,0,0);
   ObjectSetInteger(0,"testo",OBJPROP_CORNER,2);
   ObjectSetInteger(0,"testo",OBJPROP_XDISTANCE,20);
   ObjectSetInteger(0,"testo",OBJPROP_YDISTANCE,50);
   ObjectSetString(0,"testo",OBJPROP_TEXT,"prova");
   ObjectSetInteger(0,"testo",OBJPROP_FONTSIZE,20);
//--- create application dialog
   if(!ExtDialog.Create(0,"Simple Panel",0,50,50,390,200))
     return(INIT_FAILED);
//--- run application
   if(!ExtDialog.Run())
     return(INIT_FAILED);
//--- ok


   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy application dialog
   ExtDialog.Destroy(reason);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   r++;
   ObjectSetString(0,"testo",OBJPROP_TEXT," - r: "+r);
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   
       
   ExtDialog.ChartEvent(id,lparam,dparam,sparam);
  }
 
What should your code doing? Thatis nothing, follow the sample
 

This simple code is just to understand how work methods with panel... the "r" not increment if it's stay inside OnCalculate() method... If you put the OnCalculate code inside 

OnStart()

OnTick()

Start()

But inside OnCalculate it doesnt increase his value...this is the problem...I hope I have been clearer now

 
Andrea Pasquini:

This simple code is just to understand how work methods with panel... the "r" not increment if it's stay inside OnCalculate() method... If you put the OnCalculate code inside 

OnStart()

OnTick()

Start()

But inside OnCalculate it doesnt increase his value...this is the problem...I hope I have been clearer now

How should r increment? Bcs its nice weather outside?

you can only increment in a loop

 
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])

I have never used this form of OnCalculate().

As far as I am aware, it is not even available for MQL4, only MQL5.

Try using the standard OnCalculate().

 

Amando... what you mean how should r increment????...the line

r++;

inside OnCalculate....




Thanks Keith your answer is the cure... I wrong the OnCalculate call, changing this:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])

with this:

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

Everything works fine.

The weird stuff is that I simple modified an example inside MT4 standard... and the OnCalculate function is in this way...

Thanks a lot