is there a function which can detect the bar where the cursor traced

 

Hello,

first of all I 'm sorry for my english . But, you know ometimes when we see a long bar chart, sometimes, we can use the middle of this bar as a support or resistance .

that's why I would like to create an indicator, which traced automatically a line in the midle of the bar where we defined by cursor .

so I thought, that the first thing that we must do is to detect the bar ??

after we calculate the middle of this bar ??

and after we draw a line (horizontal) in this bar ??

so my question is : is there a function which detect where we clicked ???

thanks

in mql5 : there is a function which can manage event OnChartEvent(), EventChartCustom() etc ...: CHARTEVENT_CLICK

 
Create an object. Allow the user to move it.
 
WHRoeder:
Create an object. Allow the user to move it.


Hello ;

thank you for your answer . Yes I know I must create an object an horizontal line but How to manage the event ?? for example when i want to click for one bar where I would like to draw a horizontal line ??

that's the problem !!

something like this :

if (I clicked on this bar )

{

I draw an horizontal line

}

 

So my idea is like that ;

I try to draw a rectangle for example on the bar where I wuld like to draw a line but I would ask if it's possible to get the price of this bar ??? we must know the bar index I suppose ??

 
Draw an arrow Object and use it to point to the Bar where you want the line . . . get the OBJPROP_TIME1 from the arrow, use iBarShift to get the bar number from the bar number you can get OHLC values . . . detect when the arrow has been moved and repeat the process above . .
 

Hello ;

here is the begin of my code :

int start()
  {
   int    counted_bars=IndicatorCounted();
    int  obj_total = ObjectsTotal();  
     string name ; 
     datetime temps1 ;
     int  lignebar;
     double cloture, ouverture;
     double milieu ;
//----
         for(int i = 0; i < obj_total; i++)
     {
         name = ObjectName(i);
             if(ObjectType(name) == OBJ_ARROW)
         {
            
            temps1 = ObjectGet(name,OBJPROP_TIME1);
            // we search the bar shift 
            lignebar = iBarShift(NULL,0,temps1);
            // we search the price close 
            cloture =  iClose(NULL,0,lignebar);
            // we search the open PRICE_CLOSE
            ouverture =  iOpen(NULL,0,lignebar);
            
            milieu = (cloture+ouverture)/2;
            // we draw the line 
            if(!ObjectCreate("ligne1",OBJ_HLINE,0,temps1,milieu))
           {
             Print("error: can't create text_object! code #",GetLastError());
            return(0);

           }
            
            
            
            
            
            
            
         }
         
     
     
     }

   

 
   
//----
   return(0);
  }

it draw a line but my problem is when we want to put a lot of arrow for example 2, 3 or more .. it only draws one line and in the first arrow that I put . it's normal because when he draws the first line "ligne1" the name of line exists . so it's normal that it doesn't do the rest .

so how can we make to resolve this problem : that it draws lines for all arrows that we put ???

thanks

 
ludo31:

so how can we make to resolve this problem : that it draws lines for all arrows that we put ???

thanks

You need to loop through the Objects (https://docs.mql4.com/objects/ObjectsTotal), discover which are arrows (https://docs.mql4.com/objects/ObjectType using https://docs.mql4.com/objects/ObjectName ) and draw lines for them . .
 

Hi,

yes that's I made but the problem is when he draws the first line here : ligne1 is already exists

he don't pass the loop after because ligne1 does exit :

if(!ObjectCreate("ligne1",OBJ_HLINE,0,temps1,milieu))
           {
             Print("error: can't create text_object! code #",GetLastError());
            return(0);

           }

may be the only issue is to change the name of line according the loop something like this


  for(int i = 0; i < obj_total; i++)
     {
if(!ObjectCreate("ligne"."i",OBJ_HLINE,0,temps1,milieu))


}
 

So to resolve the problem of loop I wrote like this :

    
            nomligne = StringConcatenate("ligne",i);
            
           normal =  ObjectCreate(nomligne,OBJ_HLINE,0,temps1,milieu);
Reason: