#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#define OBJ_NAME "TestObjectFind"
#define WND 0
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- grafik kimliği
long chart_id=ChartID();
//--- OBJ_NAME grafiksel nesnesi WND penceresindeki grafikte bulunursa,
//--- bunu raporla ve çalışmayı sonlandır
ResetLastError();
if(ObjectFind(chart_id, OBJ_NAME)==WND)
{
PrintFormat("A graphic object named \"%s\" exists on chart with ID %I64d", OBJ_NAME, chart_id);
return;
}
//--- nesne bulunamazsa
else
{
//--- son hata kodu 4202 (“Grafiksel nesne bulunamadı”) değilse
//--- bir hata raporla ve çık
if(GetLastError()!=ERR_OBJECT_NOT_FOUND)
{
Print("ObjectFind() failed. Error ", GetLastError());
return;
}
//--- günlükte OBJ_NAME nesnesinin chart_id kimlikli grafikte olmadığını yazdır
PrintFormat("There is no graphic object named \"%s\" on the chart with ID #%I64d. Let's create it.", OBJ_NAME, chart_id);
//--- WND penceresinde OBJ_NAME adlı “dikey çizgi” grafiksel nesnesi oluştur
ResetLastError();
if(!ObjectCreate(chart_id, OBJ_NAME, OBJ_VLINE, WND, TimeCurrent(), 0))
{
Print("ObjectCreate() failed. Error ", GetLastError());
return;
}
//--- değişiklikleri hemen yansıtmak için grafiği yeniden çiz
ChartRedraw(chart_id);
//--- oluşturulan nesnenin mevcut olup olmadığını kontrol et
if(ObjectFind(chart_id, OBJ_NAME)!=WND)
{
Print("ObjectFind() failed. Error ", GetLastError());
return;
}
//--- nesne oluşturulmuşsa, bunu günlükte raporla,
//--- bir saniye bekle ve oluşturulan grafiksel nesneyi sil
PrintFormat("Now a graphic object named \"%s\" exists on the chart with ID #%I64d. Let's delete it.", OBJ_NAME, chart_id);
Sleep(1000);
ObjectDelete(chart_id, OBJ_NAME);
//--- değişiklikleri hemen yansıtmak için grafiği yeniden çiz
ChartRedraw(chart_id);
}
/*
sonuç:
There is no graphic object named "TestObjectFind" on the chart with ID #133246248352168439. Let's create it.
Now a graphic object named "TestObjectFind" exists on the chart with ID #133246248352168439. Let's delete it.
*/
}
|