Download MetaTrader 5

Indicators drawing trendlines error

To add comments, please log in or register
Ian Venner
2584
Ian Venner  

I wrote a test indicator to replicate issues I have been having with trendline objects. There are two of them. Here is the simple test indicator to place one, non raying trendline on every bar from previous close to current open.

int start()
{
 int  i,  counted_bars=IndicatorCounted();
//----
 if(counted_bars<Bars-1)
 {if(!makeline(Time[i+1],Close[i+1],Time[i],Open[i],"Test",White))
  Alert("ML error ",GetLastError() );
 }
//----
 return(0);
}
//+------------------------------------------------------------------+
bool makeline(datetime t1, double p1, datetime t2, 
              double p2, string name, color col )
{
 static double counter;
 counter+=0.00001;
 string id = StringConcatenate(name,"line-",DoubleToStr(counter,5));
 if(ObjectFind(id)>=0) return(1);
 if(!ObjectCreate(id,OBJ_TREND,0,t1,p1,t2,p2,0,0)) return(0);
 if(!ObjectSet(id,OBJPROP_COLOR,col)) return(0);
 if(!ObjectSet(id,OBJPROP_RAY,False)) return(0);
 return(1);
}

Here is two 1 minute charts created by that test indicator.

The first issue, two trendlines are drawn at the same bar with completely different parameters, it is intermittent and only happens on live prices, chart history is fine.

Double Object

Below is the second issue it happens when missed bars are added because PC was disconnected from the trading server and reconnected:

I suppose I could code to redraw the lines if there are two lines on the same bar but I would rather eliminate the error.

Ubzen
5394
Ubzen  
SDC: I wrote a test indicator to replicate an issue I have been having with tendlines there are two of them. Here is the simple test indicator to place one, non raying trendline on every bar from previous close to current open.Here is two charts created by that test indicator.

The first issue, two trendlines are drawn at the same bar with completely different parameters, it is intermittent and only happens on live prices, chart history is fine. Below is the second issue it happens when bars are added after PC was disconnected from the trading server and reconnected: I suppose I could code to redraw the lines if there are two lines on the same bar but I would rather eliminate the error.

Isn't this the same old issue with indicators drawing while bars are downloading?
Ian Venner
2584
Ian Venner  

I suppose so for the second one, but to draw 2 on the same bar with different parameters... how can previous close and current open change their values ?

EDIT : Oh I see what your saying now I had not noticed on the first chart, the trendline is already erroneous on the bar before the double trendline one ... so both issues are really the same thing. I guess I'll just have to make it redraw the whole chart on the tick after the downloaded history tick to give it time to sort itself out.

To add comments, please log in or register