Questions from a "dummy" - page 7

 
kPVT:

I have an expert with which I try to deal with events.

I get events that do not correspond to actions.

Exactly corresponding to a click on the chart and a click of a button

A controversial event id=9(CHARTEVENT_CUSTOM), that is generated when e.g. the chart is shifted and there are about 10 similar events.

TheCHARTEVENT_OBJECT_ENDEDIT event was not checked.

Everything is not clear with all the rest. Either the description does not match the event number or the event of creating an object is generated incorrectly when creating an object manually.

All in all, please help.

You'd better go like this:

//+------------------------------------------------------------------+
//| Expert chart event function                                      |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // идентификатор события  
                  const long& lparam,   // параметр события типа long
                  const double& dparam, // параметр события типа double
                  const string& sparam) // параметр события типа string
  {
   string str_id="";
   switch(id)
     {
      case CHARTEVENT_KEYDOWN:          str_id="KEYDOWN";        break;
      case CHARTEVENT_OBJECT_CREATE:  str_id="OBJECT_CREATE";  break;
      case CHARTEVENT_OBJECT_CHANGE:  str_id="OBJECT_CHANGE";  break;
      case CHARTEVENT_OBJECT_DELETE:  str_id="OBJECT_DELETE";  break;
      case CHARTEVENT_CLICK:            str_id="CLICK";          break;
      case CHARTEVENT_OBJECT_CLICK:      str_id="OBJECT_CLICK";   break;
      case CHARTEVENT_OBJECT_DRAG:       str_id="OBJECT_DRAG";    break;
      case CHARTEVENT_OBJECT_ENDEDIT:    str_id="OBJECT_ENDEDIT"; break;
      case CHARTEVENT_CHART_CHANGE:      str_id="CHART_CHANGE";   break;
      default:
         if(id>CHARTEVENT_CUSTOM)       str_id="CUSTOM+"+IntegerToString(id-CHARTEVENT_CUSTOM);
         else                         str_id="UNKNOWN";
     }
//--- для отладки
   printf("ChartEvent :id=%s, l=%d d=%f s=%s",str_id,lparam,dparam,sparam);
//---
   ExtExpertPrg.ChartEvent(id,lparam,dparam,sparam);
  }
 

I am probably doing something wrong, but I will try to describe in more detail why I am having a misunderstanding.

AlexSTAL:

You initially assign numerical correspondences to already assigned numerical constants CHARTEVENT_XXXXXXXXXXX...

Where can I see what numerical value the CHARTEVENT_XXXXXXXXXXX constants have?

I couldn't find it, so I experimented and found out thatCHARTEVENT_KEYDOWN = 0 and CHARTEVENT_CLICK = 4, which corresponds to the order of description of these constants in the help.

I've assigned numbers to other events accordingly, so there's an array event[10].

Rosh:

Unfortunately, I don't understand your question. What exactly is going wrong?

Based on my numbering of events and using the Expert Advisor from my previous post:

For example I draw a trend line -> eventCHARTEVENT_OBJECT_CHANGE,

move this line -> the eventCHARTEVENT_OBJECT_CHANGE,

change properties via menu -> 2 eventsCHARTEVENT_CHART_CHANGE and CHARTEVENT_CUSTOM,

remove it by pressing Del -> event only CHARTEVENT_KEYDOWN, (if the event numbering is wrong there should still be 2 events, removal and button press).

All this is based on my numbering.

Next...

I am using an Expert Advisor:

Drawing a trend line -> ChartEvent :id=OBJECT_DRAG, l=0 d=0.000000 s=H1 Trendline 40716

move this line -> ChartEvent :id=OBJECT_DRAG, l=0 d=0.000000 s=H1 Trendline 40716

I change properties via menu -> ChartEvent :id=OBJECT_CHANGE, l=0 d=0.000000 s=H1 Trendline 40716 and ChartEvent :id=CHART_CHANGE, l=0 d=0.000000 s=

I delete it by pressing Del -> ChartEvent :id=KEYDOWN, l=46 d=0.000000 s=

The situation has not cleared up.

Just in case:

MT5 64x - build 458.

System is W7 64x Home Extended.

Thank you for your responsiveness ))




Документация по MQL5: Стандартные константы, перечисления и структуры / Константы графиков / Типы событий графика
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы графиков / Типы событий графика
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы графиков / Типы событий графика - Документация по MQL5
 
kPVT:

I'm probably doing something wrong, but I'll try to describe in more detail why I'm having a misunderstanding.

Where can I find the numerical value of CHARTEVENT_XXXXXXXXX constants?

I couldn't find it, so I experimented and found out thatCHARTEVENT_KEYDOWN = 0 and CHARTEVENT_CLICK = 4, which corresponds to the order of description of these constants in help.

I gave the rest of the events numbers accordingly, that's how the array event[10] turned out.

This must not be done in any way!

Numerical values are assigned by the developer and can be changed at any time.

Only character constants can be used

--------------

uncleVic gave you an example of correct usage (or my help snippet)

--------------

What are you doing? Why would you need a numeric representation?

 
AlexSTAL:

This must not be done under any circumstances!

Numerical values are assigned by the developer and can be changed at any time.

Only character constants can be used

OK. I agree that you must not do so.

Forget about my handy work).

Moving on...

AlexSTAL:

uncleVic gave you an example of proper usage (well, or my piece of help)

As I wrote above, usinguncleVic's example you also get events that don't match the action.

kPVT:

Drawing a trendline -> ChartEvent :id=OBJECT_DRAG, l=0 d=0.000000 s=H1 Trendline 40716 Instead ofCHARTEVENT_OBJECT_CREATE.

.....

remove it by pressing Del -> ChartEvent :id=KEYDOWN, l=46 d=0.000000 s=Instead ofCHARTEVENT_OBJECT_DELETE and then CHARTEVENT_KEYDOWN

AlexSTAL:

What are you doing? Why would you need a numeric representation?

It's a long explanation, and it doesn't matter. Let's forget about my numbering.

The main thing is that I am trying to make sense of the events, but even usinguncleVic's example I don't understand the inconsistency between the events generated and the actions performed.

 
kPVT:

OK. I agree that you can't do that.

Forget about my hand-wringing ).

Moving on...

As I wrote above, usinguncleVic's example you also get events that don't match the action.

kPVT:


Add it to the initialization:

   ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, true);
   ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true);

You'll be all right:

Создание:
DS      0       _err (EURUSD,M30)       17:13:18        ChartEvent :id=OBJECT_CREATE, l=0 d=0.000000 s=M30 Horizontal Line 58241
DG      0       _err (EURUSD,M30)       17:13:18        ChartEvent :id=OBJECT_DRAG, l=0 d=0.000000 s=M30 Horizontal Line 58241
Удаление кл. Del:
EH      0       _err (EURUSD,M30)       17:13:21        ChartEvent :id=OBJECT_DELETE, l=0 d=0.000000 s=M30 Horizontal Line 58241
QD      0       _err (EURUSD,M30)       17:13:21        ChartEvent :id=KEYDOWN, l=46 d=0.000000 s=
 

Alex thank you very much sorted it out.

AlexSTAL:

Add to the initialisation:

....

Added to expert block

void OnInit()
{
 ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, true);
 ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, true);
}

Everything is in its place.

Looked at the help, nowhere is it written that these two events need to be "initialised" to get all the other events correct.

I commented them out and everything works.

It turns out that if Expert Advisor/indicator doesn't have OnInit block, it messes up with the events.

Maybe it's the idea, but mql5 programmers should know about it, just in case.

 
I generated an Expert Advisor in Wizard, but the tester generates a Core 1 tester stopped because OnInit critical error, has anyone encountered this? How is it solved? After all, Wizard, OK, I would have made a mistake there ...
 
Europa:
I generated an Expert Advisor in Wizard, but tester gives error Core 1 tester stopped because OnInit critical error, has anyone encountered this? How is it solved? After all, Wizard, I would have messed up something there...
Please attach source code. And test parameters.
 
uncleVic:
Attach the resulting source code. And test parameters.
Files:
TheFirst.mq5  7 kb
 
Europa:

It didn't reproduce.

I asked for more test parameters. I did:

Both version and bit rate of MT5.