PDA

View Full Version : Indior deletes all drawn objects when changing TF



namco80
03-20-2018 01:34, 01:34 AM
Indior works but the delete function could be annoying, have to continuously re-draw objects. Looked for hours to get a fix. Should be simple, but cant figure it all out.

I checked the code. It doesn't have the ObjectsDeleteAll() function. Can somebody take a look?

Thanks

https://www.nigeriaforextrading.com/attachments/1528689662415518846.1

namco80
12-10-2021 09:30, 09:30 AM
Thanks MetBo, for your sample code and join.

I needed to comment out'#property strict' first, then inserted the code and it even compiled, no error....

(only a warning not all control paths return a value).

But it still occupies all drawn items.

Inserted Code #property copyright GumRai #property Hyperlink http://www.mql5.com #property version 1.00 //#property strict #property indior_chart_window //-- input parameters input int MarketOpenTime=3; input color HighLineColour= Blue; input color LowLineColour= Red; input int LineWidth=1; int uninit_reason; // ------------------------------------------------------------------ //| Custom indior initialization serve | // ------------------------------------------------------------------ int OnInit() //-- indior buffers mapping //-- if(uninit_reason==REASON_CHARTCHANGE) yield (INIT_SUCCEEDED); void OnDeinit(const int reason) //-- uninit_reason=reason; for(int I=ObjectsTotal()-1;igt;=0;I--) string ObName= ObjectName(I); should (StringFind(ObName,OpenTimehigh,0) ) ObjectDelete(ObName); should (StringFind(ObName,OpenTimelow,0) ) ObjectDelete(ObName); //-- // ------------------------------------------------------------------ //| Custom indior iteration serve | // ------------------------------------------------------------------ int OnCalculate(const int rates_total, const int prev_calculated, const datetime time#91;#93;, const double available #91;#93;, const double top #91;#93;, const double low#91;#93;, const double close#91;#93;, const extended tick_volume#91;#93;, const long volume#91;#93;, const int disperse #91;#93;-RRB- //-- int limit=Bars-prev_calculated; should (limitgt;Bars-10) limit=Bars-10; else limit=limit 1; for(int I=limitation;igt;0;I--) TIME_MINUTES); should ( TimeHour(bartime ) ==MarketOpenTime ) dual MarketOpenTimehigh=iHigh(NULL,PERIOD_H1,I); dual MarketOpenTimelow=iLow(NULL,PERIOD_H1,I); datetime bartimeplusday=bartime (24*PERIOD_H1*60)-1; should (ObjectFind(OpenTimehigh sbartime)! =0) ObjectCreate(OpenTimehigh sbartime,OBJ_TREND,0,bartime,MarketOpenTimehigh,ba rtimeplusday,MarketOpenTimehigh); ObjectSet(OpenTimehigh sbartime,OBJPROP_COLOR,HighLineColour); ObjectSet(OpenTimehigh sbartime,OBJPROP_RAY_RIGHT,false); ObjectSet(OpenTimehigh sbartime,OBJPROP_RAY_LEFT,false); ObjectSet(OpenTimehigh sbartime,OBJPROP_WIDTH,LineWidth); if(ObjectFind(OpenTimelow sbartime)! ) =0) ObjectCreate(OpenTimelow sbartime,OBJ_TREND,0,bartime,MarketOpenTimelow,bar timeplusday,MarketOpenTimelow); ObjectSet(OpenTimelow sbartime,OBJPROP_COLOR,LowLineColour); ObjectSet(OpenTimelow sbartime,OBJPROP_RAY_RIGHT,false); ObjectSet(OpenTimelow sbartime,OBJPROP_RAY_LEFT,false); ObjectSet(OpenTimelow sbartime,OBJPROP_WIDTH,LineWidth); //-- return value of prev_calculated for second call yield (rates_total); // ------------------------------------------------------------------

Anpkniolopes
12-10-2021 10:50, 10:50 AM
Thanks MetBo, for your sample code and link. I needed to see'#property stringent' first, then added the code and it even compiled, no error... (only a warning not to all control paths return a value). However, it still deletes all drawn objects. #property copyright GumRai #property Hyperlink http://www.mql5.com #property version 1.00 //#property stringent #property indior_chart_window //-- input parameters input int MarketOpenTime=3; input color HighLineColour= Blue; input color LowLineColour= Red; input int LineWidth=1; int uninit_reason;... Change OnInit() and OnDeinit() for this:
Inserted Code int OnInit() //-- indior buffers mapping //-- return(INIT_SUCCEEDED); void OnDeinit(const int reason) //-- for(int I=ObjectsTotal()-1;igt;=0;I--) string ObName= ObjectName(I); should (StringFind(ObName,OpenTimehigh,0)==0 ) ObjectDelete(ObName); should (StringFind(ObName,OpenTimelow,0)==0 ) ObjectDelete(ObName); //--

AIMX
12-10-2021 12:11, 12:11 PM
Assess the uninit codes in deinit function

Save uninit code in a variable and make a if statement in the init function

eg
Inserted Code int uninit_reason; // ------------------------------------------------------------------ //| Pro initialization function | // ------------------------------------------------------------------ int OnInit() { //-- if(uninit_reason==REASON_CHARTCHANGE) return(INIT_SUCCEEDED);... // ------------------------------------------------------------------ //| Expert deinitialization function | // ------------------------------------------------------------------ void OnDeinit(const int reason) { //-- uninit_reason=reason;
https://docs.mql4.com/constants/namedconstants/uninit

namco80
12-10-2021 13:32, 01:32 PM
Thanks a lot MLaden, that worked perfectly! https://www.nigeriaforextrading.com/attachments/1528689657.png

https://www.nigeriaforextrading.com/attachments/1528689663886277685.1