Arrow with Text Question

Back to topics list To post a new topic, please log in or register
avatar
186
Yellowbeard 2016.04.12 19:19
 

The following code allows you to place an arrow, at a specific candle, at a specific time.  I wanted to know if there is a way to display a value, ( text ) above a down arrow and below an up arrow?  Which will signify the value at that point.

       ObjectCreate("UpSymbolAz"+i, OBJ_ARROW, 0, Time[i],vH+_Point+_Point);         
       ObjectSet("UpSymbolAz"+i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
       ObjectSet("UpSymbolAz"+i, OBJPROP_WIDTH,2);       
       ObjectSet("UpSymbolAz"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolAz"+i, OBJPROP_ANCHOR, ANCHOR_BOTTOM); 
avatar
1236
FMIC 2016.04.12 20:58 #
 

The OBJ_ARROW itself, does not have that property, but you can easily add an OBJ_TEXT at the same anchor point with the text you desire, such as the value of the Arrow.

See the following for an example: https://docs.mql4.com/constants/objectconstants/enum_object/obj_text


avatar
13012
WHRoeder 2016.04.12 21:08 #
 
Have the arrow show the text when you mouse over it. Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference

OBJPROP_TOOLTIP

The text of a tooltip. If the property is not set, then the tooltip generated automatically by the terminal is shown. A tooltip can be disabled by setting the "\n" (line feed) value to it

string




avatar
186
Yellowbeard 2016.04.13 15:37 #
 
Would it be written like this?  This draws the arrow and puts the word "TEXT" next to the arrow, but doesn't put the value for diff under the arrow.  Which is what I'm shooting for.
  if ( diff <= (-4.0) )
   {   
   
       ObjectCreate("UpSymbolBz"+i, OBJ_ARROW, 0, Time[i],vL+_Point+_Point);         
       ObjectSet("UpSymbolBz"+i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP); 
       ObjectSet("UpSymbolBz"+i, OBJPROP_WIDTH,2);       
       ObjectSet("UpSymbolBz"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolBz"+i, OBJPROP_ANCHOR, ANCHOR_TOP); 
      
       
       ObjectCreate("UpSymbolBy"+i, OBJ_TEXT, 0, Time[i],vL+_Point+_Point+_Point+_Point);         
       ObjectSet("UpSymbolBy"+i, OBJPROP_TEXT, diff);
       ObjectSet("UpSymbolBy"+i, OBJPROP_FONT,"Tahoma");       
       ObjectSet("UpSymbolBy"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolBy"+i, OBJPROP_ANCHOR, ANCHOR_TOP);  
       
       
   }   

avatar
1236
FMIC 2016.04.13 16:31 #
 

"diff" is not a "string" (probably a "double"), so maybe you should convert it to a "string", with the "DoubleToString()" function, before using it to set the text property.

PS! A screenshot may also help in case we are misunderstanding you!

avatar
186
Yellowbeard 2016.04.13 17:24 #
 

Thanks, FMIC, for all your help.  Tried a couple of options with DoubleToStr(), but still get same outcome.

   if ( diff >= 4.0 )
   {   
       textB = DoubleToStr(NormalizeDouble(diff,5),1);
   
       ObjectCreate("UpSymbolAz"+i, OBJ_ARROW, 0, Time[i],vH+_Point+_Point);         
       ObjectSet("UpSymbolAz"+i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
       ObjectSet("UpSymbolAz"+i, OBJPROP_WIDTH,2);       
       ObjectSet("UpSymbolAz"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolAz"+i, OBJPROP_ANCHOR, ANCHOR_BOTTOM); 
       textA = "HERE Down";
       
       
       ObjectCreate("UpSymbolAy"+i, OBJ_TEXT, 0, Time[i],vH+_Point+_Point+_Point+_Point);         
       ObjectSet("UpSymbolAy"+i, OBJPROP_TEXT, textB);
       ObjectSet("UpSymbolAy"+i, OBJPROP_FONT,"Tahoma");       
       ObjectSet("UpSymbolAy"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolAy"+i, OBJPROP_ANCHOR, ANCHOR_BOTTOM);       
       
       
       
       
   }


       
       

Here's the screen shot.

avatar
1236
FMIC 2016.04.13 20:53 #
 

Use the ObjectSetString() not ObjectSet() with the "OBJPROP_TEXT". It is a string not a double.

You don't need NormalizeDouble() inside a DoubleToString(). It already has a "Digits" parameter. Also, DoubleToStr is the old MQL4 name. Use the newer name to be compatible with MQL5.

PS! Alternatively you can also use "ObjectSetText()" which sets various properties in one go.

avatar
Moderator
3427
GumRai 2016.04.13 21:27 #
 
       textB = "      "+ DoubleToStr(NormalizeDouble(diff,5),1);


       ObjectCreate("UpSymbolAy"+i, OBJ_TEXT, 0, Time[i],vH+_Point+_Point+_Point+_Point);  
       ObjectSetText("UpSymbolAy"+i, textB);
       ObjectSet("UpSymbolAy"+i, OBJPROP_FONT,"Tahoma");       
       ObjectSet("UpSymbolAy"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolAy"+i, OBJPROP_ANCHOR, ANCHOR_LEFT);    
       ObjectSet("UpSymbolAy"+i, OBJPROP_ANGLE, 90);     

Maybe not the solution you want

avatar
186
Yellowbeard 2016.04.14 15:13 #
 

Thank you FMIC and GumRai for all your help!  You got me pointed in the right direction.  After a bit of trial and error, and a little cheating, I got it.

Here is the working code.  Not sure if there is a better or more correct way of doing this.


   if ( diff >= 4.0 )
   {   
    
       ObjectCreate("UpSymbolAz"+i, OBJ_ARROW, 0, Time[i],vH);         
       ObjectSet("UpSymbolAz"+i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
       ObjectSet("UpSymbolAz"+i, OBJPROP_WIDTH,2);       
       ObjectSet("UpSymbolAz"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolAz"+i, OBJPROP_ANCHOR, ANCHOR_BOTTOM); 
               
           
       textB = DoubleToStr(NormalizeDouble(diff,5),0);

       ObjectCreate("UpSymbolAy"+i, OBJ_TEXT, 0, Time[i],vM);  
       ObjectSetText("UpSymbolAy"+i, textB);
       ObjectSet("UpSymbolAy"+i, OBJPROP_FONT,"Tahoma");       
       ObjectSet("UpSymbolAy"+i, OBJPROP_COLOR,Lime);
       ObjectSet("UpSymbolAy"+i, OBJPROP_ANCHOR, ANCHOR_CENTER);    
       ObjectSet("UpSymbolAy"+i, OBJPROP_ANGLE, 360); 
       
              
   }    

   
   if ( diff <= (-4.0) )
   {   
                          
       textB = DoubleToStr(NormalizeDouble(diff,5),0);    
       
       ObjectCreate("UpSymbolBy"+i, OBJ_TEXT, 0, Time[i],vN);  
       ObjectSetText("UpSymbolBy"+i, textB);
       ObjectSet("UpSymbolBy"+i, OBJPROP_FONT,"Tahoma");       
       ObjectSet("UpSymbolBy"+i, OBJPROP_COLOR,Red);
       ObjectSet("UpSymbolBy"+i, OBJPROP_ANCHOR, ANCHOR_CENTER);    
       ObjectSet("UpSymbolBy"+i, OBJPROP_ANGLE, 360); 
              
       
       ObjectCreate("UpSymbolBz"+i, OBJ_ARROW, 0, Time[i],vL);         
       ObjectSet("UpSymbolBz"+i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP); 
       ObjectSet("UpSymbolBz"+i, OBJPROP_WIDTH,2);       
       ObjectSet("UpSymbolBz"+i, OBJPROP_COLOR,White);
       ObjectSet("UpSymbolBz"+i, OBJPROP_ANCHOR, ANCHOR_TOP);        
       
   }   


Here is the cheating, I had to do, to get the text above and below the arrows.

   double vM = (vH + 0.0006);
   double vN = (vL - 0.0006);


Here's the screen shot.




avatar
1236
FMIC 2016.04.14 16:32 #
 

As I stated before, "ObjectSetText()" can set several properties at a time, such as Font, Colour and also the text (thus saving you a few lines):

ObjectSetText("UpSymbolBy"+i,texB,0,"Tahoma",Red);
Back to topics list  

To add comments, please log in or register