Is it possible to draw line on graphic ?

 

Hello all,

    Is it possible to raw a graphic (line) on gaphic with MT4 ?

Thnaks for your answer.

See you! 

 
canarich:

Hello all,

    Is it possible to raw a graphic (line) on gaphic with MT4 ?

Yes use the Object functions,  you can draw Horizontal, Vertical, Trend lines and channels, Fibs, etc.
 

Thanks for your prompt answer.


I tried ti implement it but it seems to not work.

I add it on my code :

<SNIP>

then in the start() session :

objTrendLine("Test", 1357492150, 3700,1357492854, 3731.5,0,1,0,STYLE_SOLID, true);


Could you pelase give me an exemple ?

Thanks

 
canarich:

Thanks for your prompt answer.


I tried ti implement it but it seems to not work.

I add it on my code :

<SNIP>

then in the start() session :

objTrendLine("Test", 1357492150, 3700,1357492854, 3731.5,0,1,0,STYLE_SOLID, true);

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.

 
canarich:

Thanks for your prompt answer.

I tried ti implement it but it seems to not work.

Your code looks OK  . . .  the datetime of time1 and time2 are only 704 seconds apart,  if you create that Onject on any timeframe shorter than M15 there is a good chance that both times will be on the same bar and in that case you won't see the line.

Your function call may be wrong,  you seem to have a colour of  0
 
RaptorUK:
Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.



It works now. Thanks.

I used : DateTime = D'04.01.2013 18:24:27' (it's easier to locate on graph) and now it appears on my graph!

I tried to make a Griphical Analyse with program.

 
How do we delete the line on graph ?
 
canarich:
How do we delete the line on graph ?

Use ObjectDelete() . . .

 

Please edit the code in your earlier post.  Use the SRC button . . . 

 

Thanks RaptorUK.

For the moment, I am only testing to draw line on graph.

Once the line is draw, is it possible to compare the value of Close and the position of the line dawn ? (upper or down the line ?)

For exemple :

if(Close[0]>Line) then....

or

if(Close[0]<Line) then....

 
RaptorUK:

 

Please edit the code in your earlier post.  Use the SRC button . . . 

 
//+------------------------------------------------------------------+
//|                                                   aaa_mytest.mq4 |
//|                                                               me |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "me"
#property link      "http://www.metaquotes.net"

#property indicator_separate_window

  void objTrendLine(string name, datetime time_1, double price_1, datetime time_2, double price_2, int window=0, int width=3, 
           color col=Black, int style=STYLE_SOLID, bool ray=true)
  {
   if(ObjectFind(name)==-1) {
      ObjectCreate(name, OBJ_TREND, window, time_1, price_1, time_2, price_2);
   }
   ObjectSet(name, OBJPROP_PRICE1, price_1);
   ObjectSet(name, OBJPROP_PRICE2, price_2);
   ObjectSet(name, OBJPROP_TIME1, time_1);
   ObjectSet(name, OBJPROP_TIME2, time_2);
   ObjectSet(name, OBJPROP_WIDTH, width);
   ObjectSet(name, OBJPROP_COLOR, col);
   ObjectSet(name, OBJPROP_STYLE, style);
   ObjectSet(name, OBJPROP_RAY, ray);
   }
   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   Print("counted_bars=",counted_bars);
   
   objTrendLine("EURUSD",D'04.01.2013 22:28:27',1.3088, D'04.01.2013 23:58:27',1.3070,0,1,Black,STYLE_SOLID,true);

    //
    if(Close[0]<Line)
    {
    Print("Down");
    }
    if(Close[0]>Line)
    {
    Print("Up");
    }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+


I draw a Line on "EURUSD" and i would like to compare the Close[0] position with the Line.

Reason: