Hello guys,
I am very confused. Why does this code not work if I press 'Q' but it works when I draw any object manually?
Instead of:
if (lparam=='Q') {
have this:
if (TranslateKey((int)lparam)=='Q') {
Instead of:
have this:
Unfortunately, that doesn't work. Now the vertical line is only printed when I press SHIFT and Q. But there is still no reaction from CHARTEVENT_OBJECT_CREATE.
Unfortunately, that doesn't work. Now the vertical line is only printed when I press SHIFT and Q. But there is still no reaction from CHARTEVENT_OBJECT_CREATE.
I tested, it worked perfectly.
Check your code, especially the { and }. Post your latest version here if you still can't figure out.
I tested, it worked perfectly.
Check your code, especially the { and }. Post your latest version here if you still can't figure out.
I don't think that the problem is the TranslateKey()-issue because the key press itself works fine. The vertical line is printed every time. But the problem is that the ObjectCreate() doesn't send a message and the CHARTEVENT_OBJECT_CREATE is not triggered. But when I draw an object manually it works. It must have something to do with ObjectCreate(). But I have no idea why CHARTEVENT_OBJECT_CREATE does not react although a line is printed.
This is my code:
#property strict #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, true); //--- 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[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if (id==CHARTEVENT_KEYDOWN) { if (lparam=='Q') { ObjectCreate(0, "test", OBJ_VLINE, 0, Time[1], 0); } } else if (id==CHARTEVENT_OBJECT_CREATE) { Alert(sparam); } } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello guys,
I am very confused. Why does this code not work if I press 'Q' but it works when I draw any object manually?