Detected Country () : English
Text Object - codingforex.com

Welcome to CodingForex.Com!

Knowledge portal where you can learn how to create forex indicators and robot.

Click button below to choose level that suite you:

Text Object

Level Advance [2017-11-19 19:46:19] - by hillzx
Featured Image

Creating a Text object is quite easy, by writing the following 5 lines of code:

 

// text1 is the name of the object
// Corner is a corner variable
// XPos is the X coordinate
// YPos is the Y coordinate
// Message is written content
// TextSize is a big letter
// TextColor is the color of the post

extern int Corner=0;
extern int XPos=0;
extern int YPos=0;
extern string Message="Halo percobaan";
extern int TextSize=14;
extern color TextColor=White;

ObjectCreate("text1",OBJ_LABEL,0,0,0,0,0);
ObjectSet("text1",OBJPROP_CORNER,Corner);
ObjectSet("text1",OBJPROP_XDISTANCE,XPos);
ObjectSet("text1",OBJPROP_YDISTANCE,YPos);
ObjectSetText("text1",Message,TextSize,"Verdana",TextColor);



OK, here's the formula:

 

//+------------------------------------------------------------------+
//|                                                         Text.mq4 |
//|                                                 hillzx@gmail.com |
//|                          https://www.facebook.com/groups/hillzx/ |
//+------------------------------------------------------------------+
#property copyright "hillzx@gmail.com"
#property link      "https://www.facebook.com/groups/hillzx/"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
extern int Corner=0;
extern int XPos=10;
extern int YPos=20;
extern string Message="Halo percobaan";
extern int TextSize=14;
extern color TextColor=White;

int OnInit()
  {
//--- indicator buffers mapping
TulisText();
//---
   return(INIT_SUCCEEDED);
  }
  
void OnDeinit(const int reason)
{
   DeleteObjects();
   return;
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
TulisText();
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+

void TulisText(){
   ObjectCreate("text1",OBJ_LABEL,0,0,0,0,0);
   ObjectSet("text1",OBJPROP_CORNER,Corner);
   ObjectSet("text1",OBJPROP_XDISTANCE,XPos);
   ObjectSet("text1",OBJPROP_YDISTANCE,YPos);
   ObjectSetText("text1",Message,TextSize,"Verdana",TextColor);
}

void DeleteObjects()
{
  for (int i = ObjectsTotal() - 1; i > -1; i--)
  {
   if (StringFind(ObjectName(i), "text") >= 0) ObjectDelete(ObjectName(i));
  }
}




The result after the indicator is installed will appear in the top left corner, because of all variables set extern that means the variable can be changed from Inputs Tab.

texthasil


Good luck, do not forget to share and follow our official facebook and youtube, happy trading!



Next Article

Featured Image

Arrow Object




- Provided by HiLLzSoft Studio -