hi i have create a line chart and i want fill under the line like the attach i think for have this effect i should painted rectangle under the line many rectangle , the question is how is possible find a end of screen ?? when zoom or unzoom the screen change , i never think at this problem anyone can tell me if exist some function for fill just cooked , or exist some trick , because i think also is heavy paint many recangle or i must use triangle ???
Files:
fill_vhart.jpg
133 kb
- how can fill under the line till end of vertical chart ?
- how to create a rectangle alert indicator?
- can anyone help me with this moving average placing setup??????
Check CHARTEVENT_CHART_CHANGE in OnChartEvent, those can notify you of any change (movement, zoom, etc) that happens in the charts. The rest I guess would be accessing data of the screen (like pixel width-height with ChartGetInteger for example) and drawing a rectangle or rectangle label based on that information (and updating it in each change event)
faustf: the question is how is possible find a end of screen ??
Perhaps you should read the manual.
How To Ask Questions The Smart Way. (2004)
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up.
Chart Price Max/Min - MQL4 programming forum (2017)
faustf:
hi i have create a line chart and i want fill under the line like the attach i think for have this effect i should painted rectangle under the line many rectangle , the question is how is possible find a end of screen ?? when zoom or unzoom the screen change , i never think at this problem anyone can tell me if exist some function for fill just cooked , or exist some trick , because i think also is heavy paint many recangle or i must use triangle ???
hi i have create a line chart and i want fill under the line like the attach i think for have this effect i should painted rectangle under the line many rectangle , the question is how is possible find a end of screen ?? when zoom or unzoom the screen change , i never think at this problem anyone can tell me if exist some function for fill just cooked , or exist some trick , because i think also is heavy paint many recangle or i must use triangle ???
Consult this code , its adhering to what @Manuel Alejandro Cercos Perez said
#property copyright "Discussion" #property link "https://www.mql5.com/en/forum/450596" #property version "1.00" #property strict #define SYSTEM_TAG "UC_" #include <Canvas/Canvas.mqh> CCanvas OUTPUT; bool OUTPUTREADY=false; //you need to remember the chart size int screenSizeX,screenSizeY; int OnInit() { ObjectsDeleteAll(ChartID(),SYSTEM_TAG); //kill the output OUTPUT.Destroy(); OUTPUTREADY=false; while(!EventSetMillisecondTimer(44)){ Sleep(44); } return(INIT_SUCCEEDED); } void OnTimer(){ //first setup EventKillTimer(); screenSizeX=(int)ChartGetInteger(ChartID(),CHART_WIDTH_IN_PIXELS,0); screenSizeY=(int)ChartGetInteger(ChartID(),CHART_HEIGHT_IN_PIXELS,0); OUTPUT.CreateBitmapLabel(ChartID(),0,SYSTEM_TAG+"_DRAW",0,0,screenSizeX,screenSizeY,COLOR_FORMAT_ARGB_NORMALIZE); ObjectSetInteger(ChartID(),SYSTEM_TAG+"_DRAW",OBJPROP_BACK,true); OUTPUT.Erase(0); refreshUnderchart(); OUTPUTREADY=true; } void OnDeinit(const int reason) { ObjectsDeleteAll(ChartID(),SYSTEM_TAG); OUTPUT.Destroy(); OUTPUTREADY=false; } void OnTick() { } void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //if ready and chart change if(OUTPUTREADY&&id==CHARTEVENT_CHART_CHANGE){ refreshUnderchart(); } } void refreshUnderchart(){ OUTPUT.Erase(0); uint fill=ColorToARGB(clrBlue,255); int width=(int)ChartGetInteger(ChartID(),CHART_WIDTH_IN_PIXELS,0); int height=(int)ChartGetInteger(ChartID(),CHART_HEIGHT_IN_PIXELS,0); //if chart changed change the canvas too if(width!=screenSizeX||height!=screenSizeY){ OUTPUT.Resize(width,height); } //now find the bar to start drawing from int fvb=(int)ChartGetInteger(ChartID(),CHART_FIRST_VISIBLE_BAR,0); //and the chart width in bars int width_bars=(int)ChartGetInteger(ChartID(),CHART_WIDTH_IN_BARS,0); //but why ? so that we can navegante in the bars left to right and calculate the trinagles //find the last visible bar int lvb=fvb-width_bars; if(lvb<0){lvb=0;} //loop up until the pre-last visible bar and calculate triangles for(int i=fvb;i>lvb;i--){ int x1,y1,x2,y2; //turn price and time of the close and the time of this bar into pixel coordinates ChartTimePriceToXY(ChartID(),0,Time[i],Close[i],x1,y1); //same for next bar , the next bar is i-1 ChartTimePriceToXY(ChartID(),0,Time[i-1],Close[i-1],x2,y2); //the lowest y is the base of the triangle but actually we are looking for the biggest //because the pixels go 0 to max from the top int baseY=y1;if(y2>baseY){baseY=y2;} //then we need the x for the 3rd point int baseX=x1;if(y1==baseY){baseX=x2;} //draw a triangle OUTPUT.FillTriangle(x1,y1,x2,y2,baseX,baseY,fill); //and a rectangle to the bottom OUTPUT.FillRectangle(x1,baseY,x2,height-1,fill); } //and update the display OUTPUT.Update(true); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register