//+------------------------------------------------------------------+
//| 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" // カスタマ銘柄名
#define CUSTOM_SYMBOL_PATH "Forex" // 銘柄が作成されるグループの名前
#define CUSTOM_SYMBOL_ORIGIN Symbol() // カスタム銘柄の基となる銘柄の名前
//+------------------------------------------------------------------+
//| スクリプトプログラム開始関数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- カスタム銘柄の作成に失敗した場合、操作ログにその旨を通知する
if(!CustomSymbolCreate(CUSTOM_SYMBOL_NAME, CUSTOM_SYMBOL_PATH, CUSTOM_SYMBOL_ORIGIN))
{
Print("CustomSymbolCreate() failed. Error ", GetLastError());
return;
}
//--- 作成された銘柄の存在を確認し、結果を操作ログに出力する
bool custom= false;
bool exist = SymbolExist(CUSTOM_SYMBOL_NAME, custom);
PrintFormat("Custom symbol '%s' exists: %s", CUSTOM_SYMBOL_NAME, (string)exist);
//--- 2秒待ってから、作成された銘柄と操作ログ内の結果メッセージを削除する
Sleep(2000);
ResetLastError();
bool deleted = CustomSymbolDelete(CUSTOM_SYMBOL_NAME);
Print(deleted ? StringFormat("Custom symbol '%s' removed", CUSTOM_SYMBOL_NAME) : StringFormat("CustomSymbolDelete() failed. Error ",GetLastError()));
//--- 作成された銘柄の存在を確認し、結果を操作ログに出力する
exist = SymbolExist(CUSTOM_SYMBOL_NAME, custom);
PrintFormat("Custom symbol '%s' exists: %s", CUSTOM_SYMBOL_NAME, (string)exist);
/*
結果:
Custom symbol 'EURUSD.C' exists: true
Custom symbol 'EURUSD.C' removed
Custom symbol 'EURUSD.C' exists: false
*/
}
|