Objects Finding Expect Doesnt Find any in the Custom when they re There

 

Goodday i Created An expect that Finds Newly Created Objects on a custom Indicator And Reports that a new object has being created on Chart But is its Doesnt Report Anything Even when the Object re created Ive Provided the example and the indicator.
//+------------------------------------------------------------------+
//|                                        Object expert advisor.mq5 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

string  NamePart;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
string NamePart = "ePASimple_0";
ChartSetInteger(0,CHART_EVENT_OBJECT_CREATE,true);
ChartSetInteger(0,CHART_EVENT_OBJECT_DELETE,true);


   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
 
   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---
   return(ret);
  }
//+------------------------------------------------------------------+
//| TesterInit function                                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| TesterPass function                                              |
//+------------------------------------------------------------------+
void OnTesterPass()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   if(id==CHARTEVENT_OBJECT_CREATE){
   
   NewObject(sparam);
  
   
   
   return;
   
   
   
  }
  }
//+------------------------------------------------------------------+
void NewObject(string name){


if (StringSubstr(name ,StringLen(NamePart))!=NamePart)return;
int sub_window = ObjectFind(0,name);
if(sub_window !=0) return;
long type = ObjectGetInteger(0,name ,OBJPROP_TYPE);
if(type!=OBJ_ARROW_BUY && type!=OBJ_ARROW_SELL)return;

//Found do something else 
//ReportObject
string objet_type = ObjectGetString(0,name,OBJPROP_TEXT);
PrintFormat("OBJ TEXT IS"+objet_type);
ReportObject("New",name);
}
void ReportObject(string event , string name){

datetime object_time   = (datetime) ObjectGetInteger(0,name , OBJPROP_TIME);
ENUM_OBJECT object_type = (ENUM_OBJECT)ObjectGetInteger(0,name ,OBJPROP_TYPE);
int object_bar        = iBarShift(Symbol(),Period(), object_time);
double object_Price   =ObjectGetDouble(0,name,OBJPROP_PRICE);
double bsr_high       =iHigh(Symbol(),Period(),object_bar);
double bar_low        =iLow(Symbol(), Period(),object_bar);
string objet_type1 = ObjectGetString(0,name,OBJPROP_TEXT);

PrintFormat("This is where you trade your strategy using information ftom thw objeçt");
PrintFormat("Event =%s",event);
PrintFormat(""+name+""+"Description"+objet_type1);
PrintFormat("Object type =%s", EnumToString(object_type));
PrintFormat("time=%s,bar=%i,price=%f, high=%f , low=%f", TimeToString(object_time),object_bar);
}

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2.  string  NamePart;
    //+------------------------------------------------------------------+
    //| Expert initialization function                                   |
    //+------------------------------------------------------------------+
    int OnInit()
      {
    //---
    string NamePart = "ePASimple_0"; 
    You created a local unused variable. The global variable is never initialized.
 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. You created a local unused variable. The global variable is never initialized.

Thanks Done Just Initialize it but Still Nothing is Showing ....

 

I Even Tried to get the total Number of Objects and Check to seeif the Object Texts Match Meaning there are object with this text decription.

for (int i = ObjectsTotal(0,0,OBJPROP_ARROWCODE)-1; i> 0 ; i--){
   
   string Name = ObjectName(0,i);
   string objet_type1 = ObjectGetString(0,Name,OBJPROP_TEXT);
      if (objet_type1 == "Shootng Star")
        {
            PrintFormat("StarS fOUND");
        }
     if(objet_type1 == "Bullish Engulfing")
         {
           PrintFormat("BEng fOUND");
         }
         
     if (objet_type1 == "Hammer")
         {
           PrintFormat(" Hammer fOUND");
         }
     if(objet_type1 == "Bearish Engulfing")
         {
          PrintFormat("Engulfing fOUND");
         }
     if (objet_type1 == "Bull Harami")
      {
      PrintFormat("Har fOUND");
      }
     if(objet_type1 == "Bear Cross")
         {
         PrintFormat("Cross fOUND");
         }
       if (objet_type1 == "Bull Piercing")
      {
          PrintFormat("Piercing fOUND");
      }
     if(objet_type1 == "Bull Cross")
         {
           PrintFormat("DD fOUND");
         }
      if (objet_type1 == "Dark Cloud")
      {
       PrintFormat("DD fOUND");
      }
     if(objet_type1 == "Bull Harami")
         {
         PrintFormat("BHara fOUND");
         }
         
   }
 
hbill Hadebe #:

I Even Tried to get the total Number of Objects and Check to seeif the Object Texts Match Meaning there are object with this text decription.

Where they found? You did not say?

Print this out before the return, that is the string itself (line 2, NewObject function)

Print(StringSubstr(name ,StringLen(NamePart))

Cause, off my head, am feeling the name of the object from the chart would be something like "Daily Trendline 32564" which would be different from your namepart, hence returning, since the condition was failed.

 
Thank-god Avwerosuoghene Odukudu #:

Where they found? You did not say?

Print this out before the return, that is the string itself (line 2, NewObject function)

Cause, off my head, am feeling the name of the object from the chart would be something like "Daily Trendline 32564" which would be different from your namepart, hence returning, since the condition was failed.

Nope they were not then found So I  used the objects array to get the total number  of objects on chart then  looped through each then I found them but then the new problem was how to get the current objeck bring show in the current bar... Well I tried using the datetime function if the current bar time matches with objects time then do something..... Thanks for the reply