Horizontal line at current MA level

 

Hi guys,


Any idea how one can draw a horizontal line (ideally a trendline (so that I can switch "Ray" function off) at the current level of EMA? I need that line to be redrawn automatically when EMA changes its position.


MANY THANKS!!!

 
Grizzly:

Hi guys,


Any idea how one can draw a horizontal line (ideally a trendline (so that I can switch "Ray" function off) at the current level of EMA? I need that line to be redrawn automatically when EMA changes its position.


MANY THANKS!!!


You can use this code to draw your line.


Load the ma value in xfb5. Of course, you can change the names to your liking.


drawLine(xfb5,TAG+"Fib5", Fibcolor5, 2,""+DoubleToStr(iLevel1*100,1 ) + "% "+DoubleToStr(xfb5,digits) ) ;





//+------------------------------------------------------------------+
void drawLine(double lvl,string name, color Col,int type,string text)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_TREND, 0, Time[0], lvl,Time[1],lvl);

if(type == 1)
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
else
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,1);
ObjectSet(name,OBJPROP_RAY,true);

}
else
{
ObjectDelete(name);
ObjectCreate(name, OBJ_TREND, 0, Time[0], lvl,Time[1],lvl);

if(type == 1)
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
else
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,1);
ObjectSet(name,OBJPROP_RAY,true);

}

string Obj0002 = name+"linelbl" ;
ObjectDelete(Obj0002);
if(ObjectFind(Obj0002) != 0)
{
ObjectCreate(Obj0002, OBJ_TEXT, 0, Time[ShiftLabel], lvl);
ObjectSetText(Obj0002,text, 8, "Arial", Col);
}
else
{
ObjectMove(Obj0002, 0, Time[ShiftLabel], lvl);
}


}
//+------------------------------------------------------------------+

 

TheRumpledOne wrote

>>


You can use this code to draw your line.


Load the ma value in xfb5. Of course, you can change the names to your liking.


drawLine(xfb5,TAG+"Fib5", Fibcolor5, 2,""+DoubleToStr(iLevel1*100,1 ) + "% "+DoubleToStr(xfb5,digits) ) ;

Wow, TheRumpledOne himself! :)


Thank you so much, TRO, I greatly appreciate your help. Will the same code allow me to display the line on other timeframes (whilst still taking MA reading from the original TF; e.g. MA on D1, and lines to be shown on H4 etc)?


Best regards,


G

Reason: