//+------------------------------------------------------------------+
//| CustomSymbolDelete.mq5 |
//| Copyright 2024, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#define CUSTOM_SYMBOL_NAME Symbol()+".C" // custom symbol name
#define CUSTOM_SYMBOL_PATH "Forex" // name of the group, in which a symbol is to be created
#define CUSTOM_SYMBOL_ORIGIN Symbol() // name of a symbol a custom one is to be based on
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- if failed to create a custom symbol, inform of that in the journal
if(!CustomSymbolCreate(CUSTOM_SYMBOL_NAME, CUSTOM_SYMBOL_PATH, CUSTOM_SYMBOL_ORIGIN))
{
Print("CustomSymbolCreate() failed. Error ", GetLastError());
return;
}
//--- check the existence of the created symbol and print the result in the journal
bool custom= false;
bool exist = SymbolExist(CUSTOM_SYMBOL_NAME, custom);
PrintFormat("Custom symbol '%s' exists: %s", CUSTOM_SYMBOL_NAME, (string)exist);
//--- wait two seconds and delete the created symbol with the resulting message in the journal
Sleep(2000);
ResetLastError();
bool deleted = CustomSymbolDelete(CUSTOM_SYMBOL_NAME);
Print(deleted ? StringFormat("Custom symbol '%s' removed", CUSTOM_SYMBOL_NAME) : StringFormat("CustomSymbolDelete() failed. Error ",GetLastError()));
//--- check the existence of the created symbol and print the result in the journal
exist = SymbolExist(CUSTOM_SYMBOL_NAME, custom);
PrintFormat("Custom symbol '%s' exists: %s", CUSTOM_SYMBOL_NAME, (string)exist);
/*
result:
Custom symbol 'EURUSD.C' exists: true
Custom symbol 'EURUSD.C' removed
Custom symbol 'EURUSD.C' exists: false
*/
}
|