How to draw a part of cirlce/ellispe

 

For example,I want to keep right part of ellispe which in the rectangle,hide the left part.

If i use canvas to draw this,when i move the chart, the ellipse dont move. i want to the object i darw move with the chart.

so I hope draw this use price and time ,not the x and y coordinate.

thank you


 
Jianyuan Huang:

For example,I want to keep right part of ellispe which in the rectangle,hide the left part.

If i use canvas to draw this,when i move the chart, the ellipse dont move. i want to the object i darw move with the chart.

so I hope draw this use price and time ,not the x and y coordinate.

thank you



#property indicator_chart_window
#include <Canvas\iCanvas.mqh> //https://www.mql5.com/ru/code/22164

bool click = false;
datetime _time=0;
double _price=0;
//+------------------------------------------------------------------+
int OnInit() {
   delete Canvas;
   Canvas= new iCanvas(0,300,300,"iCanvas",50,150);
   Canvas.Erase();
   Canvas.Circle(-50,75,90,0xFF00FFFF);
   Canvas.Update();
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total, const int prev_calculated,const int begin,const double& price[]) {
   return(rates_total);
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
   if (sparam=="1" && !click) {click=true; _time=Canvas.TimePos(_MouseX); _price=Canvas.Price(_MouseY);}
   if (!click ){if(id==CHARTEVENT_MOUSE_MOVE) {Canvas.MoveCanvas(_MouseX,_MouseY); Canvas.Update();}} 
   else if (id==CHARTEVENT_CHART_CHANGE) {Canvas.MoveCanvas(int(_X(_time)),int(_Y(_price))); Canvas.Update();} 
}
//+------------------------------------------------------------------+
Files:
iCanvas.mqh  45 kb
 
Nikolai Semko:


thanks

 
Jianyuan Huang:

thanks

It will be more correct:


#property indicator_chart_window
#define protected public
#include <Canvas\Canvas.mqh>
#undef protected

bool click = false;
int sub;
double _p;
datetime _t;

CCanvas Canvas;
int OnInit() {
   ChartXYToTimePrice(0,300,300,sub,_t,_p);
   Canvas.CreateBitmap(0,0,"Canvas",_t,_p,50,150,COLOR_FORMAT_ARGB_NORMALIZE);
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
   Canvas.Erase();
   Canvas.Circle(-50,75,90,0xFF00FFFF);
   Canvas.Update();
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total, const int prev_calculated,const int begin,const double& price[]) {
   return(rates_total);
}
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
   if (sparam=="1" && !click) {click=true; ChartXYToTimePrice(0,(int)lparam,(int)dparam,sub,_t,_p);}
   if (!click )if(id==CHARTEVENT_MOUSE_MOVE) 
   {ChartXYToTimePrice(0,(int)lparam,(int)dparam,sub,_t,_p); MoveCanvas(); Canvas.Update();}
   
}
//+------------------------------------------------------------------+
bool MoveCanvas()
{
 if(ObjectSetInteger(Canvas.m_chart_id,Canvas.m_objname,OBJPROP_TIME,_t) && ObjectSetDouble(Canvas.m_chart_id,Canvas.m_objname,OBJPROP_PRICE,_p))  return(true);
 else return(false);
}
 
Nikolai Semko:

It will be more correct:


can we realize this by ObjectCreat only?
 
Jianyuan Huang:
can we realize this by ObjectCreat only?

This code uses ObjectCreate in the CCanvas.mqh library

Reason: