Hello developers,
Hope you all doing safe.
I know that we can define CHARTEVENT_OBJECT_DRAG that works when we drop an object in the chart,
but how can we define a chartevent that works when we drag and object before dropping it?
you probably want to receive the price of a line while it moves ?
//+------------------------------------------------------------------+ //| LineDragInfo.mq4 | //| Copyright 2020, Republic Of Mars | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ string monitored_name=""; string system_tag="Test_"; bool is_object_being_dragged=false; double new_drag_price=0; int OnInit() { ObjectsDeleteAll(0,system_tag); monitored_name=system_tag+"_a_line"; is_object_being_dragged=false; new_drag_price=0; //create a test line bool obj=ObjectCreate(ChartID(),monitored_name,OBJ_HLINE,0,0,Close[0]); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- destroy timer // EventKillTimer(); ObjectsDeleteAll(0,system_tag); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_OBJECT_CLICK&&sparam==monitored_name&&monitored_name!=""&&!is_object_being_dragged) { if(ObjectGetInteger(0,monitored_name,OBJPROP_SELECTED)) { is_object_being_dragged=true; new_drag_price=ObjectGetDouble(0,monitored_name,OBJPROP_PRICE); } if(!ObjectGetInteger(0,monitored_name,OBJPROP_SELECTED)) is_object_being_dragged=false; } if(id==CHARTEVENT_MOUSE_MOVE&&is_object_being_dragged) { double nprice=ObjectGetDouble(0,monitored_name,OBJPROP_PRICE); if(nprice!=new_drag_price) { new_drag_price=nprice; Print("New Drag Price : "+DoubleToString(new_drag_price,Digits())); } } if(id==CHARTEVENT_OBJECT_DRAG&&is_object_being_dragged) { double nprice=ObjectGetDouble(0,monitored_name,OBJPROP_PRICE); new_drag_price=nprice; Print("Final Price : "+DoubleToString(new_drag_price,Digits())); is_object_being_dragged=false; } } //+------------------------------------------------------------------+
you probably want to receive the price of a line while it moves ?
Actually I wanted exactly sth like this, Thank you very much. It works well.
How to make this code to work on mql5.
I modified ObjectCreate and created the H Line. Code compiled with no errors. But it doesnt print the price while it moves, as it works on mql4.
Tried also to modify
DoubleToString(new_drag_price,Digits())
to
DoubleToString(new_drag_price,_Digits)
Same result.
How to make this code to work on mql5.
I modified ObjectCreate and created the H Line. Code compiled with no errors. But it doesnt print the price while it moves, as it works on mql4.
Tried also to modify
to
Same result.
Try this :
//+------------------------------------------------------------------+ //| dragLine.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" string monitored_name=""; string system_tag="Test_"; bool is_object_being_dragged=false; double new_drag_price=0; int OnInit() { ObjectsDeleteAll(0,system_tag); monitored_name=system_tag+"_a_line"; is_object_being_dragged=false; new_drag_price=0; //create a test line bool obj=ObjectCreate(ChartID(),monitored_name,OBJ_HLINE,0,0,SymbolInfoDouble(_Symbol,SYMBOL_ASK)); ObjectSetInteger(ChartID(),monitored_name,OBJPROP_SELECTABLE,true); ChartSetInteger(ChartID(),CHART_EVENT_MOUSE_MOVE,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectsDeleteAll(0,system_tag); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- if(id==CHARTEVENT_OBJECT_CLICK&&sparam==monitored_name&&monitored_name!=""&&!is_object_being_dragged) { if(ObjectGetInteger(0,monitored_name,OBJPROP_SELECTED)) { is_object_being_dragged=true; new_drag_price=ObjectGetDouble(0,monitored_name,OBJPROP_PRICE); } if(!ObjectGetInteger(0,monitored_name,OBJPROP_SELECTED)) is_object_being_dragged=false; } if(id==CHARTEVENT_MOUSE_MOVE&&is_object_being_dragged) { double nprice=ObjectGetDouble(0,monitored_name,OBJPROP_PRICE); if(nprice!=new_drag_price) { new_drag_price=nprice; Print("New Drag Price : "+DoubleToString(new_drag_price,Digits())); } } if(id==CHARTEVENT_OBJECT_DRAG&&is_object_being_dragged) { double nprice=ObjectGetDouble(0,monitored_name,OBJPROP_PRICE); new_drag_price=nprice; Print("Final Price : "+DoubleToString(new_drag_price,Digits())); is_object_being_dragged=false; } } //+------------------------------------------------------------------+
- 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 developers,
Hope you all doing safe.
I know that we can define CHARTEVENT_OBJECT_DRAG that works when we drop an object in the chart,
but how can we define a chartevent that works when we drag and object before dropping it?