Inform top and bottom line closest to current price

 

The attached code makes it possible to locate the line closest to the price, but I need a code that informs me:

1 - The closest line higher than the price;

2 - The closest line below the price.

3 - If possible, filter the names that start with .... Example "LinhaHigh"

I'm doing my first codes, I appreciate all the help you can give, thank you very much!

int OnInit()
{
EventSetTimer(5);
return(INIT_SUCCEEDED);
}

void OnTimer()
{
   double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   int x= ObjectsTotal(0,-1,OBJ_HLINE)-1;                  
   string obname=ObjectName(0,x,-1,OBJ_HLINE);           
   double level=ObjectGetDouble(0,obname,OBJPROP_PRICE);  
   double difference=MathAbs(Bid-level);                      
   string closest=obname;
   x--;
   string closestvr=level;                                 
    
     for(;x>=0;x--)
     {
     obname=ObjectName(0,x,-1,OBJ_HLINE);
     level=ObjectGetDouble(0,obname,OBJPROP_PRICE);
     double diff=MathAbs(Bid-level);
     if(diff<difference)                                 
   //if(diff>difference)                                 
       {
        closest=obname;
        difference=diff;
        closestvr=level;                                  
        }
      
     }
 Print("Nome:",closest,"  Valor:",DoubleToString(closestvr,2),"  Diferença: ",DoubleToString(difference*100,2) );
 
 
}
MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.