MBZ13: I notice that sometimes it doesn't work for some instrument and sometime it take long times.
|
|
Marco vd Heijden: you call deinit() function directly after start, why?
| Just to delete the three lines, so they move at start of a new week. |
Hi,
I added it because when a new candle start the lines previously drawn remain into the chart and in addition the new ones are drawn.
However I just tried to remove deinit line, but I have the same problem... sometimes lines are drawn sometimes not...
many thanks
| |
Just to delete the three lines, so they move at start of a new week. |
Hi,
1. I thought to it ad I waited for today new weekly candle, but it is the same story. I tried also with Refresh.
2. not clear for me this point: the three objects have three different name (OPEN;CLOSE;MID)... maybe I'm interpreting wrongly what you wrote..
many thanks
MBZ13: 2. not clear for me this point: the three objects have three different name (OPEN;CLOSE;MID)... maybe I'm interpreting wrongly what you wrote..
| If you add a second copy to the same chart, they will both be deleting and creating the same three objects. |
IMO it's better to create them once and move afterwards.
//+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- if(ObjectCreate(CLOSE, OBJ_HLINE , 0, 0, 0)) { ObjectSet(CLOSE, OBJPROP_STYLE, STYLE_DOT); ObjectSet(CLOSE, OBJPROP_COLOR, Black); ObjectSet(CLOSE, OBJPROP_WIDTH, 1); } else return(INIT_FAILED); //--- if(ObjectCreate(OPEN, OBJ_HLINE , 0, 0, 0)) { ObjectSet(OPEN, OBJPROP_STYLE, STYLE_DOT); ObjectSet(OPEN, OBJPROP_COLOR, Black); ObjectSet(OPEN, OBJPROP_WIDTH, 1); } else return(INIT_FAILED); //--- if(ObjectCreate(MID, OBJ_HLINE , 0, 0, 0)) { ObjectSet(MID, OBJPROP_STYLE, STYLE_DOT); ObjectSet(MID, OBJPROP_COLOR, Blue); ObjectSet(MID, OBJPROP_WIDTH, 1); } else return(INIT_FAILED); //---- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete(CLOSE); ObjectDelete(OPEN); ObjectDelete(MID); //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { static datetime prevTime; if(prevTime!=iTime(NULL,PERIOD_W1,0)) { double OpenW = iOpen(NULL,PERIOD_W1,1); double CloseW = iClose(NULL,PERIOD_W1,1); double Delta=fabs(CloseW-OpenW); double mid_price=fmin(CloseW,OpenW)+ Delta/2; if(!ObjectSetDouble(ChartID(),CLOSE,OBJPROP_PRICE,CloseW) || !ObjectSetDouble(ChartID(),OPEN,OBJPROP_PRICE,OpenW) || !ObjectSetDouble(ChartID(),MID,OBJPROP_PRICE,mid_price)) return(0); prevTime=iTime(NULL,PERIOD_W1,0); } //--- return(0); } //+------------------------------------------------------------------+
IMO it's better to create them once and move afterwards.
Hi,
I tried to run your code but the result is the same, sometimes it works sometime not (I tried with GBP/USD and it works while nothing for USDOLLAR and XAU/USD)... also opening a new chart or refreshing...
the code seems to be correct... really I do not know.
many tanks for your suggestion.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I started to study mql4 and I'm trying to draw some lines into the chart.
Using some examples, I developed the following (it simply draws horizontal lines on open,close and mid of the previous weekly candle), but I notice that sometimes it doesn't work for some instrument and sometime it take long times.
Is there something wrong in the code? or is it something related to initialization/refresh...
Many thanks if someone will help me!