Kolier.Li logo
  • Home
  • Article
  • Example
  • Indicator
  • Trading System
  • Project
  • Glossary
  • MT4 Coding Service
  • NinjaTrader Coding Service
Home ยป Example

MT4 Alternative Object Create/Modify Functions

Mon, 10/04/2010 - 08:46 | kolier 0 comments
Usually in MT4, you need to code some lines to create an object, even when you want to modify it you need to code some lines again. Now, here is the solution in one line only to simplize creation and modification of the objects in one line.

For clearing objects

//+------------------------------------------------------------------+
//| Clear Objects @http://kolier.li                                  |
//+------------------------------------------------------------------+
void objClear(string prefix)
  {
   string name;
   int obj_total = ObjectsTotal();
   for (int i=obj_total-1; i>=0; i--) {
      name = ObjectName(i);
      if (StringFind(name, prefix) == 0) ObjectDelete(name);
   }
  }

Object Trend Line

//+------------------------------------------------------------------+
//| Set object Trend Line, create if not exist yet @http://kolier.li |
//+------------------------------------------------------------------+
void objTrendLine(string name, datetime time_1, double price_1, datetime time_2, double price_2, int window=0, int width=1, color col=White, 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);
  }

object Horizonal Line

//+------------------------------------------------------------------+
//| Set object Horizonal Line, create if not exist yet @http://kolier.li |
//+------------------------------------------------------------------+
void objHLine(string name, double price, int window=0 color col=White, int style=STYLE_SOLID)
  {
   if(ObjectFind(name)==-1) {
      ObjectCreate(name, OBJ_HLINE, window, price);
   }
   ObjectSet(name, OBJPROP_PRICE1, price);
   ObjectSet(name, OBJPROP_COLOR, col);
   ObjectSet(name, OBJPROP_STYLE, style);
  }

Object Label

//+------------------------------------------------------------------+
//| Set Object Label, create if not exist yet @http://kolier.li      |
//+------------------------------------------------------------------+
void objLabel(string name, string tex, int corner, int position_x, int position_y, int window=0, color tex_color=White, string tex_font="Arial", int tex_size=12)
  {
   if(ObjectFind(name)==-1) {
      ObjectCreate(name, OBJ_LABEL, window, 0, 0);
   }
   ObjectSet(name, OBJPROP_CORNER, corner);
   ObjectSet(name, OBJPROP_XDISTANCE, position_x);
   ObjectSet(name, OBJPROP_YDISTANCE, position_y);
   ObjectSetText(name, tex, tex_size, tex_font, tex_color);
  }

Object Arrow

//+------------------------------------------------------------------+
//| Set object arrow, create if not exist yet @http://kolier.li      |
//+------------------------------------------------------------------+
void objArrow(string name, int code, datetime time, double price, int window=0, color col=White, int width=1)
  {
   if(ObjectFind(name)==-1) {
      ObjectCreate(name, OBJ_ARROW, window, time, price);
   }
   ObjectSet(name, OBJPROP_ARROWCODE, code);
   ObjectSet(name, OBJPROP_TIME1, time);
   ObjectSet(name, OBJPROP_PRICE1, price);
   ObjectSet(name, OBJPROP_COLOR, col);
   ObjectSet(name, OBJPROP_WIDTH, width);
  }

Object Text

//+------------------------------------------------------------------+
//| Set Object Text, create if not exist yet @http://kolier.li       |
//+------------------------------------------------------------------+
void objText(string name, string tex, datetime time, double price, int window=0, color tex_color=White, string tex_font="Arial", int tex_size=12)
  {
   if(ObjectFind(name)==-1) {
      ObjectCreate(name, OBJ_TEXT, window, time, price);
   }
   ObjectSet(name, OBJPROP_TIME1, time);
   ObjectSet(name, OBJPROP_PRICE1, price);
   ObjectSetText(name, tex, tex_size, tex_font, tex_color);
  }

Object Rectangle

//+------------------------------------------------------------------+
//| Set Object Rectangle, create if not exist yet @http://kolier.li  |
//+------------------------------------------------------------------+
void objRectangle(string name, datetime time_1, double price_1, datetime time_2, double price_2 int window=0, color color_obj=Blue, bool draw_back=true)
  {
   if(ObjectFind(name)==-1) {
      ObjectCreate(name, OBJ_RECTANGLE, window, time_1, price_1, time_2, price_2);
   }
   ObjectSet(name, OBJPROP_TIME1, time_1);
   ObjectSet(name, OBJPROP_PRICE1, price_1);
   ObjectSet(name, OBJPROP_TIME2, time_2);
   ObjectSet(name, OBJPROP_PRICE2, price_2);
   ObjectSet(name, OBJPROP_COLOR, color_obj);
   ObjectSet(name, OBJPROP_BACK, draw_back);
  }

  • Projects
  • Examples
  • Indicators
  • Trading Systems
  • MT4
  • Object
  • Objects
  • MT4
  • Function
  • Snippet
  • Programming

Search

Hot Forex Offers

Get Cash Back on All your Forex Trades, Win or Lose
Free Auto Trade Signals
Premium Trading Signals

User login

What is OpenID?
  • Sign in with Twitter
  • Log in using OpenID
  • Cancel OpenID login
Facebook Connect
Sign in using Facebook
  • Create new account
  • Request new password

Example Category

  • Event Leading
  • Maths Theory
  • Indicator Use Case
  • Trading System
    • Entry Logic
    • Exit Logic
    • Money Management
  • Programming
    • Algorithm
    • Function
    • Snippet
  • Software
    • Trading Plaform
      • MT4
  • ABOUT
  • PRIVACY POLICY
  • Risk Disclaimer
  • CONTACT

© 2012 Kolier.Li All Right Reserved.