GetSetObjects

Download script

This script is designed for MetaTrader users to automate the management and restoration of technical analysis objects—specifically vertical lines, horizontal lines, trend lines, and Fibonacci retracements—on a trading chart. It functions by reading configuration data from an external text file and translating that data into visual elements on your screen.

Here is a breakdown of how the logic works:

Core Functionality

The script acts as a bridge between a saved data file and your live trading chart. Instead of manually drawing every support, resistance level, or trend line, this tool reads a "blueprint" from a text file (named based on the current currency symbol) and constructs those objects automatically.

Operational Modes

The script offers two primary ways to interact with your chart:

  1. Data Retrieval: The script scans the current chart, identifies specific types of drawing objects, and saves their properties (like price, color, width, and time) into a text file.
  2. Object Placement: The script reads an existing text file and generates all the corresponding lines and zones on your chart.

Key Features & Logic

  • Smart Filtering: The script is programmed to recognize specific objects: Vertical Lines (V_LINE), Horizontal Lines (H_LINE), Trend Lines (TREND), and Fibonacci levels (FIBO). It ignores other types of drawings to keep the data clean.
  • Precision Mapping: For every object it finds or creates, it captures detailed metadata, including:
    • Visual Styles: Line width, color, and dashed/solid styles.
    • Temporal Data: The exact timeframes and coordinates (Price 1, Price 2) where the lines start and end.
    • Fibonacci Details: For Fibonacci retracements, it specifically captures the number of levels, the specific values of those levels, and their unique text labels.
  • Safety & Confirmation: Before performing a "Delete" action (which clears existing objects to make room for the new data), the script can trigger a pop-up warning message. If the user cancels this warning, the script stops immediately to prevent accidental loss of data.
  • Automated Cleanup: When in "Set" mode, it provides an option to automatically remove current chart objects. This ensures that the visual environment is wiped clean before the new data from the file is applied, preventing overlapping or cluttered charts.

Summary for the User

Essentially, this is a backup and restoration system for your technical analysis. It allows you to save your "trading map" into a text file and instantly redeploy that exact same map onto any chart by simply running the script.

Miscellaneous
Uses files from the file systemIt writes information to fileIt plays sound alertsIt opens Message Boxes to the userIt issuies visual alerts to the screenIt reads information from a file
5 Views
0 Downloads
0 Favorites
GetSetObjects
ÿþ#property script_show_inputs

#include <WinUser32.mqh> // @54C?@5645=85 >1 C40;5=88

#property strict

//+------------------------------------------------------------------+

enum MODE

  {

   A=0,     // Obtain data

   B=1,     // Set the objects

  };

//+------------------------------------------------------------------+

input MODE Mode=A;

input bool DeleteObjects=true;

//+------------------------------------------------------------------+

bool Warning = true;        // @54C?@5640BL >1 C40;5=88 >1J5:B>2

//+------------------------------------------------------------------+

string imya,text,adres;

int handle,TYP;

//+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH+

void OnStart()

  {

   adres="GetSetObjects\\"+Symbol()+".txt";

   if(Mode){ObjSet();}else {ObjGet();}

  }

//+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH+

void ObjGet()

  {

//+-----------------------------------------------------------------------------------------------+

   FileDelete(adres,FILE_COMMON);

   handle=FileOpen(adres,FILE_WRITE|FILE_COMMON);

//+-----------------------------------------------------------------------------------------------+

   for(int obj=ObjectsTotal(); obj>=0; obj--)

     {

      imya=ObjectName(0,obj);

      if(StringLen(imya)<1){continue;}

      //+-----------------------------------------------------------------------------------------------+ V.LINE

      if(ObjectGetInteger(0,imya,OBJPROP_TYPE)==OBJ_VLINE)

        {

         //+------------------------------------------------------------------------------------------+

         FileWrite(handle,"TYP"+(string)ObjectGetInteger(0,imya,OBJPROP_TYPE));

         FileWrite(handle,imya);

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_WIDTH));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_STYLE));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIMEFRAMES));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_COLOR));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIME));

         continue;

         //+------------------------------------------------------------------------------------------+

        }

      //+-----------------------------------------------------------------------------------------------+ H.LINE

      if(ObjectGetInteger(0,imya,OBJPROP_TYPE)==OBJ_HLINE)

        {

         //+------------------------------------------------------------------------------------------+

         FileWrite(handle,"TYP"+(string)ObjectGetInteger(0,imya,OBJPROP_TYPE));

         FileWrite(handle,imya);

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_WIDTH));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_STYLE));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIMEFRAMES));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_COLOR));

         FileWrite(handle,ObjectGetDouble(0,imya,OBJPROP_PRICE));

         continue;

         //+------------------------------------------------------------------------------------------+

        }

      //+-----------------------------------------------------------------------------------------------+ T.LINE

      if(ObjectGetInteger(0,imya,OBJPROP_TYPE)==OBJ_TREND)

        {

         //+------------------------------------------------------------------------------------------+

         FileWrite(handle,"TYP"+(string)ObjectGetInteger(0,imya,OBJPROP_TYPE));

         FileWrite(handle,imya);

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_WIDTH));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_STYLE));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIMEFRAMES));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_COLOR));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_RAY));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIME1));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIME2));

         FileWrite(handle,ObjectGetDouble(0,imya,OBJPROP_PRICE1));

         FileWrite(handle,ObjectGetDouble(0,imya,OBJPROP_PRICE2));

         continue;

         //+------------------------------------------------------------------------------------------+

        }

      //+-----------------------------------------------------------------------------------------------+ F.LINE

      if(ObjectGetInteger(0,imya,OBJPROP_TYPE)==OBJ_FIBO)

        {

         //+------------------------------------------------------------------------------------------+

         FileWrite(handle,"TYP"+(string)ObjectGetInteger(0,imya,OBJPROP_TYPE));

         FileWrite(handle,imya);

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_WIDTH));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_LEVELWIDTH));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_STYLE));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_LEVELSTYLE));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIMEFRAMES));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_COLOR));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_LEVELCOLOR));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_RAY));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIME1));

         FileWrite(handle,ObjectGetInteger(0,imya,OBJPROP_TIME2));

         FileWrite(handle,ObjectGetDouble(0,imya,OBJPROP_PRICE1));

         FileWrite(handle,ObjectGetDouble(0,imya,OBJPROP_PRICE2));

         //+------------------------------------------------------------------------------------------+

         int levels=(int)ObjectGetInteger(0,imya,OBJPROP_LEVELS);

         FileWrite(handle,levels);

         //+------------------------------------------------------------------------------------------+

         for(int i=0; i<levels; i++)

           {

            FileWrite(handle,ObjectGetDouble(0,imya,OBJPROP_LEVELVALUE,i));

            FileWrite(handle,ObjectGetString(0,imya,OBJPROP_LEVELTEXT,i));

           }

         //+--------------------------------------------------------------------------------------------+

        }

     }

   FileClose(handle); PlaySound("ok.wav");

  }

//+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH+

void ObjSet()

  {

//+=========================================================================================================+

   if(DeleteObjects)

     {

      if(Warning)

        {

         int ret=MessageBox("A5 >1J5:BK 1C4CB C40;5=K","GetSetObjects",MB_OKCANCEL);

         if(ret==IDCANCEL){PlaySound("timeout.wav"); return;}

        }

      ObjectsDeleteAll(0,0,0); ObjectsDeleteAll(0,0,1); ObjectsDeleteAll(0,0,2); ObjectsDeleteAll(0,0,10);

     }

//+=========================================================================================================+

   handle=FileOpen(adres,FILE_READ|FILE_COMMON);

   if(handle==INVALID_HANDLE){Alert("No copied data "+Symbol()); return;}

//+-----------------------------------------------------------------------------------------------+

   while(true)

     {

      text=FileReadString(handle);

      if(StringLen(text)==0)

        {

         FileClose(handle); ChartRedraw(0);

         PlaySound("ok.wav"); return;

        }

      if(StringFind(text,"TYP")>=0){TYP=(int)StringSubstr(text,3);}else {continue;}

      //+-----------------------------------------------------------------------------------------------------+ V.LINE

      if(TYP==0)

        {

         //+---------------------------------------------------------------------------------+

         imya=FileReadString(handle);

         int WIDTH=(int)FileReadString(handle);

         int STYLE=(int)FileReadString(handle);

         int TFRAMES=(int)FileReadString(handle);

         color COLOR=(color)(int)FileReadString(handle);

         int TIME=(int)FileReadString(handle);

         //+---------------------------------------------------------------------------------+

         ObjectCreate(0,imya,OBJ_VLINE,0,TIME,0);

         ObjectSetInteger(0,imya,OBJPROP_WIDTH,WIDTH);

         ObjectSetInteger(0,imya,OBJPROP_COLOR,COLOR);

         ObjectSetInteger(0,imya,OBJPROP_STYLE,STYLE);

         ObjectSetInteger(0,imya,OBJPROP_TIMEFRAMES,TFRAMES);

         continue;

        }

      //+-----------------------------------------------------------------------------------------------------+ H.LINE

      if(TYP==1)

        {

         //+---------------------------------------------------------------------------------+

         imya=FileReadString(handle);

         int WIDTH=(int)FileReadString(handle);

         int STYLE=(int)FileReadString(handle);

         int TFRAMES=(int)FileReadString(handle);

         color COLOR=(color)(int)FileReadString(handle);

         double PRICE=(double)FileReadString(handle);

         //+---------------------------------------------------------------------------------+

         ObjectCreate(0,imya,OBJ_HLINE,0,0,PRICE);

         ObjectSetInteger(0,imya,OBJPROP_WIDTH,WIDTH);

         ObjectSetInteger(0,imya,OBJPROP_COLOR,COLOR);

         ObjectSetInteger(0,imya,OBJPROP_STYLE,STYLE);

         ObjectSetInteger(0,imya,OBJPROP_TIMEFRAMES,TFRAMES);

         continue;

        }

      //+-----------------------------------------------------------------------------------------------------+  T.LINE

      if(TYP==2)

        {

         imya=FileReadString(handle);

         int WIDTH=(int)FileReadString(handle);

         int STYLE=(int)FileReadString(handle);

         int TFRAMES=(int)FileReadString(handle);

         color COLOR=(color)(int)FileReadString(handle);

         int RAY=(int)FileReadString(handle);

         int TIME1=(int)FileReadString(handle);

         int TIME2=(int)FileReadString(handle);

         double PRICE1=(double)FileReadString(handle);

         double PRICE2=(double)FileReadString(handle);

         //+---------------------------------------------------------------------------------+

         ObjectCreate(0,imya,OBJ_TREND,0,TIME1,PRICE1,TIME2,PRICE2);

         ObjectSetInteger(0,imya,OBJPROP_WIDTH,WIDTH);

         ObjectSetInteger(0,imya,OBJPROP_COLOR,COLOR);

         ObjectSetInteger(0,imya,OBJPROP_STYLE,STYLE);

         ObjectSetInteger(0,imya,OBJPROP_TIMEFRAMES,TFRAMES);

         ObjectSetInteger(0,imya,OBJPROP_RAY,RAY);

         continue;

        }

      //+-----------------------------------------------------------------------------------------------------+  F.LINE

      if(TYP==10)

        {

         //+---------------------------------------------------------------------------------+

         imya=FileReadString(handle);

         int WIDTH=(int)FileReadString(handle);

         int LvlWIDTH=(int)FileReadString(handle);

         int STYLE=(int)FileReadString(handle);

         int LvlSTYLE=(int)FileReadString(handle);

         int TFRAMES=(int)FileReadString(handle);

         color COLOR=(color)(int)FileReadString(handle);

         color LvlCOLOR=(color)(int)FileReadString(handle);

         int RAY=(int)FileReadString(handle);

         int TIME1=(int)FileReadString(handle);

         int TIME2=(int)FileReadString(handle);

         double PRICE1=(double)FileReadString(handle);

         double PRICE2=(double)FileReadString(handle);

         //+=========================================================================================================+

         ObjectCreate(0,imya,OBJ_FIBO,0,TIME1,PRICE1,TIME2,PRICE2);

         int levels=(int)FileReadString(handle);

         ObjectSetInteger(0,imya,OBJPROP_LEVELS,levels);

         //+-----------------------------------------------------------------------------------------------+

         for(int i=0; i<levels; i++)

           {

            double value=(double)FileReadString(handle);

            ObjectSetDouble(0,imya,OBJPROP_LEVELVALUE,i,value);

            text=FileReadString(handle);

            ObjectSetString(0,imya,OBJPROP_LEVELTEXT,i,text);

           }

         //+-----------------------------------------------------------------------------------------------+

         ObjectSetInteger(0,imya,OBJPROP_WIDTH,WIDTH);

         ObjectSetInteger(0,imya,OBJPROP_LEVELWIDTH,LvlWIDTH);

         ObjectSetInteger(0,imya,OBJPROP_STYLE,STYLE);

         ObjectSetInteger(0,imya,OBJPROP_LEVELSTYLE,LvlSTYLE);

         ObjectSetInteger(0,imya,OBJPROP_COLOR,COLOR);

         ObjectSetInteger(0,imya,OBJPROP_LEVELCOLOR,LvlCOLOR);

         ObjectSetInteger(0,imya,OBJPROP_TIMEFRAMES,TFRAMES);

         ObjectSetInteger(0,imya,OBJPROP_RAY,RAY);

         //+=========================================================================================================+

        }

     }

  }

//+HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH+

Comments