- www.mql5.com
- How to get the bar number/time from OnChartEvent()?
- Chart Event not working when the indicator using Chart Event is called from EA using iCustom function
- How to make bitmap object to behave like button
When the user event is fired it contain some infos inside OnChartEvent().
void OnChartEvent(const int id, // Event ID const long& lparam, // Parameter of type long event const double& dparam, // Parameter of type double event const string& sparam // Parameter of type string events );
you can tell the event source by these params,it is quite easy.
try to write a demo,just an Print inside OnChartEvent,which print id,lparm,dparam,sparam。
you will learn that click on the chart(not click on any object),and click on a object ,they are different.
more info please read manual
|
When the user event is fired it contain some infos inside OnChartEvent().
you can tell the event source by these params,it is quite easy.
try to write a demo,just an Print inside OnChartEvent,which print id,lparm,dparam,sparam。
you will learn that click on the chart(not click on any object),and click on a object ,they are different.
more info please read manual
|
hi Guo Zheng Feng, thank you for your answer
i know I must used OnChartEvent and have used it.
My problem is that my two events are not concurrent
I will click on the object first, if the object is clicked, then I will click if the chart is clicked.
I have written a test sample for clicking on the chart and clicking on the object and it works fine
But I can't write it back to back
If the object is clicked first and then the chart
hi Guo Zheng Feng, thank you for your answer
i know I must used OnChartEvent and have used it.
My problem is that my two events are not concurrent
I will click on the object first, if the object is clicked, then I will click if the chart is clicked.
I have written a test sample for clicking on the chart and clicking on the object and it works fine
But I can't write it back to back
If the object is clicked first and then the chart
void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_OBJECT_CLICK && sparam =="Button1" ) { if(ObjectGetString(0,"Button1",OBJPROP_TEXT)=="Stop") { ObjectSetString(0,"Button1",OBJPROP_TEXT,"Start"); } } if(id == CHARTEVENT_CLICK && ObjectGetString(0,"Button1",OBJPROP_TEXT)=="Start") { int x = (int)lparam; int y = (int)dparam; ask=MarketInfo(Symbol(),MODE_ASK); bid=MarketInfo(Symbol(),MODE_BID); Print("Mouse clicked on: ",DoubleToString(clickprice,Digits)," Ask: ",ask," Bid: ",bid, " X: ",x," Y: ",y, ); ObjectSetString(0,"Button1",OBJPROP_TEXT,"Stop"); } }
when i click on button , it show me ask," Bid: ",bid, " X: ",x," Y: ",y,
but it must show them me when i click on chart
can say me where i was wrong?
when i click on button , it show me ask," Bid: ",bid, " X: ",x," Y: ",y,
but it must show them me when i click on chart
can say me where i was wrong?
double ask,bid,clickprice; void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { Print("Event Fired:id=",id," lparam=",lparam," dparam=",dparam," sparam=",sparam); if(id==CHARTEVENT_OBJECT_CLICK && sparam =="Button1" ) { if(ObjectGetString(0,"Button1",OBJPROP_TEXT)=="Stop") { ObjectSetString(0,"Button1",OBJPROP_TEXT,"Start"); } } if(id == CHARTEVENT_CLICK && ObjectGetString(0,"Button1",OBJPROP_TEXT)=="Start") { int x = (int)lparam; int y = (int)dparam; ask=MarketInfo(Symbol(),MODE_ASK); bid=MarketInfo(Symbol(),MODE_BID); Print("Mouse clicked on: ",DoubleToString(clickprice,Digits)," Ask: ",ask," Bid: ",bid, " X: ",x," Y: ",y); ObjectSetString(0,"Button1",OBJPROP_TEXT,"Stop"); } }
2023.11.13 00:37:33.775 test EURUSD,H1: Event Fired:id=4 lparam=230 dparam=57.0 sparam=
2023.11.13 00:37:33.775 test EURUSD,H1: Event Fired:id=1 lparam=230 dparam=57.0 sparam=Button1
it fired 2 event at the same time,both object and chart,even i just click 1 time on the button.
so, it needs to block another event in a short time.
//+------------------------------------------------------------------+ //| test.mq4 | //| Copyright 2022, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- ObjectCreate(ChartID(),"Button1",OBJ_BUTTON,0,Time[0],Close[0]); ObjectSetString(0,"Button1",OBJPROP_TEXT,"Start"); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ double ask,bid,clickprice; #define SHAKE_TIME 50 //ms long bt_tm; void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { Print("Event Fired:id=",id," lparam=",lparam," dparam=",dparam," sparam=",sparam); if(id==CHARTEVENT_OBJECT_CLICK && sparam =="Button1" ) { if(ObjectGetString(0,"Button1",OBJPROP_TEXT)=="Stop") { ObjectSetString(0,"Button1",OBJPROP_TEXT,"Start"); } bt_tm=GetMicrosecondCount(); } if(id == CHARTEVENT_CLICK && ObjectGetString(0,"Button1",OBJPROP_TEXT)=="Start" && GetMicrosecondCount()-bt_tm>=SHAKE_TIME) { int x = (int)lparam; int y = (int)dparam; ask=MarketInfo(Symbol(),MODE_ASK); bid=MarketInfo(Symbol(),MODE_BID); Print("Mouse clicked on: ",DoubleToString(clickprice,Digits)," Ask: ",ask," Bid: ",bid, " X: ",x," Y: ",y); ObjectSetString(0,"Button1",OBJPROP_TEXT,"Stop"); } }
2023.11.13 01:25:54.279 test EURUSD,H1: Mouse clicked on: 0.00000 Ask: 1.06857 Bid: 1.06828 X: 237 Y: 164
2023.11.13 01:25:54.279 test EURUSD,H1: Event Fired:id=4 lparam=237 dparam=164.0 sparam=
2023.11.13 01:25:52.437 test EURUSD,H1: Event Fired:id=4 lparam=237 dparam=52.0 sparam=
2023.11.13 01:25:52.437 test EURUSD,H1: Event Fired:id=1 lparam=237 dparam=52.0 sparam=Button1
2023.11.13 01:25:49.851 test EURUSD,H1: Mouse clicked on: 0.00000 Ask: 1.06857 Bid: 1.06828 X: 198 Y: 178
2023.11.13 01:25:49.851 test EURUSD,H1: Event Fired:id=4 lparam=198 dparam=178.0 sparam=
it is working now.
the anime state when the button click need to be fixed.
2023.11.13 00:37:33.775 test EURUSD,H1: Event Fired:id=4 lparam=230 dparam=57.0 sparam=
2023.11.13 00:37:33.775 test EURUSD,H1: Event Fired:id=1 lparam=230 dparam=57.0 sparam=Button1
it fired 2 event at the same time,both object and chart,even i just click 1 time on the button.
so, it needs to block another event in a short time.
2023.11.13 01:25:54.279 test EURUSD,H1: Mouse clicked on: 0.00000 Ask: 1.06857 Bid: 1.06828 X: 237 Y: 164
2023.11.13 01:25:54.279 test EURUSD,H1: Event Fired:id=4 lparam=237 dparam=164.0 sparam=
2023.11.13 01:25:52.437 test EURUSD,H1: Event Fired:id=4 lparam=237 dparam=52.0 sparam=
2023.11.13 01:25:52.437 test EURUSD,H1: Event Fired:id=1 lparam=237 dparam=52.0 sparam=Button1
2023.11.13 01:25:49.851 test EURUSD,H1: Mouse clicked on: 0.00000 Ask: 1.06857 Bid: 1.06828 X: 198 Y: 178
2023.11.13 01:25:49.851 test EURUSD,H1: Event Fired:id=4 lparam=198 dparam=178.0 sparam=
it is working now.
the anime state when the button click need to be fixed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use