Criar HLINE com Texto

 
Bom dia galera,

Estou desenvolvendo um EA e queria deixar o visual mais interativo.

Gostaria de saber se é possível criar um HLINE e colocar nele talvez um RECTANGULE_LABEL com um texto.

O que quero fazer:

Vou inserir 3 linhas ao efetuar uma ordem: Linha da ordem, linha de Stop Loss e Linha de Take Profit.

Como quero deixar mais interativo, queria adicionar linhas e com seus respectivos nomes nos pontos, pois acho bem fraco o visual padrão.

Sabem me dizer como posso fazer?
 
Diogo Silva:
Bom dia galera,

Estou desenvolvendo um EA e queria deixar o visual mais interativo.

Gostaria de saber se é possível criar um HLINE e colocar nele talvez um RECTANGULE_LABEL com um texto.

O que quero fazer:

Vou inserir 3 linhas ao efetuar uma ordem: Linha da ordem, linha de Stop Loss e Linha de Take Profit.

Como quero deixar mais interativo, queria adicionar linhas e com seus respectivos nomes nos pontos, pois acho bem fraco o visual padrão.

Sabem me dizer como posso fazer?

Boa noite!


Três funções para lhe auxiliar:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawLine(const string name,
              const int sub_win,
              const double price1,
              const double price2,
              const datetime time1,
              const datetime time2,
              const color line_color,
              const int line_width,
              const ENUM_LINE_STYLE line_style,
              const bool ray_left=false,
              const bool ray_right=true,
              const string text="\n",
              const string tooltip="\n")
  {
   if(ObjectFind(0,name)<0)
     {
      ObjectCreate(0,name,OBJ_TREND,sub_win,time1,price1,time2,price2);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(0,name,OBJPROP_RAY_LEFT,ray_left);
      ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,ray_right);
     }
   ObjectSetInteger(0,name,OBJPROP_TIME,0,time1);
   ObjectSetInteger(0,name,OBJPROP_TIME,1,time2);
   ObjectSetDouble(0,name,OBJPROP_PRICE,0,price1);
   ObjectSetDouble(0,name,OBJPROP_PRICE,1,price2);
//---
   ObjectSetInteger(0,name,OBJPROP_WIDTH,line_width);
   ObjectSetInteger(0,name,OBJPROP_COLOR,line_color);
   ObjectSetInteger(0,name,OBJPROP_STYLE,line_style);
   ObjectSetString(0,name,OBJPROP_TEXT,text);
   ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void DrawText(const string name,
              const int sub_win,
              const double price,
              const datetime time,
              const color text_color,
              const int font_size,
              const ENUM_ANCHOR_POINT anchor,
              const string text,
              const string font_name="Calibri",
              const string tooltip="\n")
  {
   if(ObjectFind(0,name)<0)
     {
      ObjectCreate(0,name,OBJ_TEXT,sub_win,time,price);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
      ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
      ObjectSetString(0,name,OBJPROP_FONT,font_name);
     }
   ObjectSetInteger(0,name,OBJPROP_ANCHOR,anchor);
   ObjectSetInteger(0,name,OBJPROP_TIME,0,time);
   ObjectSetDouble(0,name,OBJPROP_PRICE,0,price);
//---
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetInteger(0,name,OBJPROP_COLOR,text_color);
   ObjectSetString(0,name,OBJPROP_TEXT,text);
   ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);
  }

Código completo [AQUI] . . .



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool LineMove(const long   chart_ID=0,   // chart's ID
               const string name="HLine", // line name
               double       price=0)      // line price
  {
//--- if the line price is not set, move it to the current Bid price level
   if(!price)
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
   ResetLastError();
//--- move a horizontal line
   if(!ObjectMove(chart_ID,name,0,0,price))
     {
      Print(__FUNCTION__,
            ": failed to move the horizontal line! Error code = ",GetLastError());
      return(false);
     }
//--- successful execution
   return(true);
  }

Código completo [AQUI] . . .



Os exemplos da Documentação já são bem completos também (OBJ_HLINE, OBJ_TEXT, OBJ_RECTANGLE_LABEL) . . .



Bons negócios!!

 
Comentários que não dizem respeito a este tema, foram transferidos para "Assuntos aleatórios".
Razão: