Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 645

 

Taras, is it possible to make such graph normalization for frame change by mouse click?

Sometimes out of habit I click when the cursor is near the button, but I don't like the result.

I haven't found anything suitable in list of event handling, there is onlyCHARTEVENT_CHART_CHANGE without any specific description. I can try to bind a mouse click, but as far as I understand the user can't work with the system menu, only if he creates his own buttons. Is there any simple solution?

 
psyman:

Taras, is it possible to make such graph normalization for frame change by mouse click?

Sometimes out of habit I click when the cursor is near the button, but I don't like the result.

I haven't found anything suitable in the list of event handling, there is onlyCHARTEVENT_CHART_CHANGE without any specific description. I can try to bind mouse button click, but as far as I understand the user can't work with system menu, only if he creates his own buttons. Is there any simple solution?

That is, to click on some "tap zones" on the chart?
You can, you need to keep track of cursor coordinates and mouse button clicks.

CHARTEVENT_MOUSE_MOVE

 

Forum on trading, automated trading systems & strategy testing

Any questions for beginners on MQL4, help and discussion on algorithms and codes

Taras Slobodyanik, 2018.10.04 09:37

You mean to click on some "tap zones" on the chart with your mouse?
You can, you need to keep track of cursor coordinates and mouse button clicks.



The thing is, it's a click on the chart, not on a button from the system menu. How to process such an event I do not know.
 
psyman:

The thing is, it's a click on a chart, not a button from the system menu. I don't know how to process such an event.

remember the current character-period and at"CHARTEVENT_CHART_CHANGE" check the changes and do what you need to do

 
OK, thanks again.
 

Please tell me why the same function from the EA body OnTick() does not work (or rather, it works, but fails on all charts correctly)

But from the procedure OnInit() it works fine and from an ordinary script too. The Expert Advisor is installed on 80 charts at once (20 currencies, each 4 windows W1 D1 H4 H1) can just my computer can not cope? Please advise. The purpose of the robot is to output the MessageBox messages on the screen, if a signal is detected on one of the charts. Maybe the computer is slow at the moment of start of these messages?
 

I'm having trouble remembering the period before an event is handled, where do I do this?

Decided to track by message, turns out that CHARTEVENT_CHART_CHANGE is processed 2 times in one click, the ctime variable is reset.


#property strict

#property indicator_chart_window

int ctime;


void OnInit()

{

Print(" OnInit------------1 ", ChartPeriod(0));

Print("OnInit ctime = ", ctime);

// ctime=ChartPeriod(0);

}


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

{

ctime=ChartPeriod(0);

return(rates_total);

}

void OnChartEvent(const int id,

const long &lparam,

const double &dparam,

const string &sparam)


{


if(id==CHARTEVENT_CHART_CHANGE)

{

Print("CHARTEVENT_CHART_CHANGE is started ctime=", ctime);

if(ctime!=ChartPeriod(0))

{

Print(ChartPeriod(0), " CHANGED!!!!!!!!!!!!!!! ", ctime);

}

}

}



Adding indicator on hourly, then switching to daily

2018.10.05 01:04:45.171 _t1 CADJPY,Daily: CHARTEVENT_CHART_CHANGE is started ctime=1440

2018.10.05 01:04:45.156 _t1 CADJPY,Daily: 1440 CHANGED!!!!!!!!!!!!!!! 0

2018.10.05 01:04:45.156 _t1 CADJPY,Daily: CHARTEVENT_CHART_CHANGE is started ctime=0

2018.10.05 01:04:45.156 _t1 CADJPY,Daily: initialized

2018.10.05 01:04:45.156 _t1 CADJPY,Daily: OnInit ctime=0

2018.10.05 01:04:45.156 _t1 CADJPY,Daily: OnInit------------1 1440

2018.10.05 01:04:45.156 _t1 CADJPY,H1: uninit reason 3

2018.10.05 01:02:02.000 _t1 CADJPY,H1: CHARTEVENT_CHART_CHANGE is started ctime=60

2018.10.05 01:02:02.000 _t1 CADJPY,H1: 60 CHANGED!!!!!!!!!!!!!!! 0

2018.10.05 01:02:02.000 _t1 CADJPY,H1: CHARTEVENT_CHART_CHANGE is started ctime=0

2018.10.05 01:02:02.000 _t1 CADJPY,H1: initialized

2018.10.05 01:02:02.000 _t1 CADJPY,H1: OnInit ctime=0

2018.10.05 01:02:02.000 _t1 CADJPY,H1: OnInit------------1 60

2018.10.05 01:02:01.078 Custom indicator _t1 CADJPY,H1: loaded successfully





 
psyman:

I'm having trouble remembering the period before the event is processed, where does this need to be done?

Decided to track by message, turns out that CHARTEVENT_CHART_CHANGE is processed 2 times in one click, the ctime variable is reset.

Put the code in the message correctly! It's very hard to read in this form. It must look like this.

#property strict
#property indicator_chart_window
int ctime;
void OnInit()
   {
     Print("  OnInit------------1  ", ChartPeriod(0));
     Print("OnInit ctime = ", ctime);
   //  ctime=ChartPeriod(0);   
   }
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[])
  {
   ctime=ChartPeriod(0);         
   return(rates_total);
  }
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   if(id==CHARTEVENT_CHART_CHANGE)
      {
      Print("CHARTEVENT_CHART_CHANGE     is started  ctime=", ctime);
      if(ctime!=ChartPeriod(0))
      {
      Print(ChartPeriod(0), "  CHANGED!!!!!!!!!!!!!!!   ", ctime);
      }
      } 
}

When you change parameters of a chart, the indicator is forcedly reloaded, read the doc for the reason of deinitialization and its reason variable.

You can use global terminal variables to save the required parameters.

 
Vitaly Gorbunov:

Insert the code correctly in the message! It's very difficult to read it like this. It should be like this.

The indicator will forcibly restart when you change the chart parameters read the doc for the reason of deinitialisation and its reason variable.

You can use global variables of the terminal to save the required parameters.

Yes, you need to store the values in GlobalVariable, and then, at startup, check their existence.

That is, the chart number, symbol, period should be saved.
And then delete unnecessary variables, or make them initially as temporary global variables.

ps. you can also store information in objects on the chart - as long as the chart exists, the objects exist

 

I thought it would be much easier :-)

Then quite a childish question - my code doesn't involve any trading or graphics, what type of program should I use?

The scripts are one-off, but can they be run in a loop? I declared a custom indicator purely out of inertia, because I've never used Expert Advisors. I have never used them before, but they restart automatically which I do not need. i will need your advise.

ps

Objects can be zero size, so that visually they do not get in the way?

Reason: