MQ4 Indicator objects not always appearing.

 

Hi,


im in the process of writing an indicator. the problem i have is that the object do not always appear when its loaded. if i change the period then they will apear, so for example, i load on a M1 period, no objects. then change to M15 get objects, and back to M1 get objects.


i have a function that draws the history in the init function.


i tried adding extra chacks to the start function to draw them if it failed but still not working.


have had this problem with other indicators ... ea's seem to behave normally.


any ideas?

 
Do u use the OjectCreate function or do you use a SetIndexArrow function, using wingdings...?
 
ErrorProgrammer:
Do u use the OjectCreate function or do you use a SetIndexArrow function, using wingdings...?

Hi,


i use ObjectCreate ...

 

I had a little research....have a look at the WindowRedraw() - function....might be missing in your code?

Got it from here:

'MQL4 Language for Newbies. Custom Indicators (Part 2)'

 

With the brief explanation of the problem, If I had to guess I'd say it's a problem somewhere in your code that crashes the application at runtime. Look at your journal to see if you find anything when you boot it up. More info would be needed to diagnose the problem further.

.

Jon

 

My indicator is not stable as well, I have the same problem.

In M1 no correct results, switch between timeframes and results are correct.

Have not found the problem.

 
BillBrian wrote >>

My indicator is not stable as well, I have the same problem.

In M1 no correct results, switch between timeframes and results are correct.

Have not found the problem.

Hi guys,

sorry for the delay in getting back. i did try around with the windowredraw function no luck.

the strange thing is that if it did it all the time then i could agree that maybe its the code, but it seems totally random.

i did a bit more digging and noticed some other strange things. the values that im trying to get out of the marketdata are all zero when it does this .. its almost as if MT4 has not actually fully initilised the chart .... ive raised it as a potential bug, but who knows.

im happy to post the code for another project that it is also happening on.

//+------------------------------------------------------------------+
//| Trend Lines.mq4 |
//| Copyright © 2009, 4xProject. |
//| http://www.4xproject.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, 4xProject."
#property link "http://www.4xproject.com"

#property indicator_chart_window

extern bool DrawPivots = true;

double pivot.low[], pivot.high[];
datetime last.bar;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{

pivot.history.find();
lower.trend.find();
upper.trend.find();

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{

objects.delete();

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{

if (iTime(Symbol(),Period(),0) > last.bar)
{
pivot.history.find();
lower.trend.find();
upper.trend.find();
}

return(0);
}

//+------------------------------------------------------------------+
int pivot.low.detect(int pos)
{

double low = iLow(Symbol(),Period(),pos);
double low1 = iLow(Symbol(),Period(),pos+1);
double low2 = iLow(Symbol(),Period(),pos+2);

if(low2 >= low1 && low1 < low) return(1); //pivot low

return(0); //no pivot
}

//+------------------------------------------------------------------+
int pivot.high.detect(int pos)
{
double high = iHigh(Symbol(),Period(),pos);
double high1 = iHigh(Symbol(),Period(),pos+1);
double high2 = iHigh(Symbol(),Period(),pos+2);

if(high2 <= high1 && high1 > high)return(1); //pivot high

return(0); //no pivot
}

//+------------------------------------------------------------------+
int pivot.history.find()
{

ArrayResize(pivot.low,IndicatorCounted());
ArrayResize(pivot.high,IndicatorCounted());

for (int i = IndicatorCounted()-2; i>=1; i--)
{
int pivot.low.status = pivot.low.detect(i);
int pivot.high.status = pivot.high.detect(i);

if (pivot.low.status == 1)
{
pivot.low.draw(i);
pivot.low[i+1] = iLow(Symbol(),Period(),i+1);
//Print(pivot.low[i+1]);
}
if (pivot.high.status == 1)
{
pivot.high.draw(i);
pivot.high[i+1] = iHigh(Symbol(),Period(),i+1);
//Print(pivot.high[i+1]);
}
}
last.bar = iTime(Symbol(),Period(),0);
}

//+------------------------------------------------------------------+
void pivot.low.draw(datetime location)
{
if (DrawPivots){
ObjectCreate("4xTL_l" + location,OBJ_ARROW,0,iTime(Symbol(),Period(),location+1),iLow(Symbol(),Period(),location+1));
ObjectSet("4xTL_l" + location,14,251);}
}

//+------------------------------------------------------------------+
void pivot.high.draw(datetime location)
{
if (DrawPivots){
ObjectCreate("4xTL_h" + location,OBJ_ARROW,0,iTime(Symbol(),Period(),location+1),iHigh(Symbol(),Period(),location+1));
ObjectSet("4xTL_h" + location,14,251);
ObjectSet("4xTL_h" + location,OBJPROP_COLOR,Blue);}
}

//+------------------------------------------------------------------+
void objects.delete()
{
for(int i=ObjectsTotal()-1;i>=0;i--)if(StringSubstr(ObjectName(i),0,4) == "4xTL")ObjectDelete(ObjectName(i));
}

void lower.trend.find()
{
ObjectDelete("4xTL_tll");

for (int i = 0; i < IndicatorCounted(); i++)if (pivot.low[i] > 0) break;

for (int x = i; x < IndicatorCounted(); x++) if (pivot.low[x] > 0 && pivot.low[x] < pivot.low[i]) break;

ObjectCreate("4xTL_tll",OBJ_TREND,0,iTime(Symbol(),Period(),x),pivot.low[x],iTime(Symbol(),Period(),i),pivot.low[i]);

}

void upper.trend.find()
{
ObjectDelete("4xTL_tlu");

for (int i = 0; i < IndicatorCounted(); i++)if (pivot.high[i] > 0) break;

for (int x = i; x < IndicatorCounted(); x++) if (pivot.high[x] > 0 && pivot.high[x] > pivot.high[i]) break;

ObjectCreate("4xTL_tlu",OBJ_TREND,0,iTime(Symbol(),Period(),x),pivot.high[x],iTime(Symbol(),Period(),i),pivot.high[i]);

}

 

"i did a bit more digging and noticed some other strange things. the values that im trying to get out of the marketdata are all zero when it does this .. its almost as if MT4 has not actually fully initilised the chart "

Well, if you are speaking of the calculations you perform during init(), well, yes...