'ObjectFind' - pass 'object_name' parameter forward into...

 

Hi!

Is there a short way to pass 'object_name' parameter from ObjectFind() forward into another (custom) function? Like:

int OnInit()
  {
...
   if(ObjectFind(0,"above")==0 || ObjectFind(0,"below")==0) TrailHLineOnChart(AboveOrBelow); // i.e. object (horizontal line) with object_name "above" is found on main window
...
  }

 ... then this 'object_name' (i.e. "above") is to be passed into function:

void TrailHLineOnChart(string foundLine) // object_name needs to be passed inhere
{
if(TrailHLineInPips>0)
  {
  if(AboveOrBelow=="above")
    {
     // then trail this horizontal line above Bid...
    }
  if(AboveOrBelow=="below")
    {
     // then trail this horizontal line below Bid...
    }
  }
}

Thanks for your generous help.


Best regards,


Simon

S love nia

 
   if(ObjectFind(0,"above")==0)
      TrailHLineOnChart("above");
   if(ObjectFind(0,"below")==0) 
      TrailHLineOnChart("below");

void TrailHLineOnChart(string AboveOrBelow) // object_name needs to be passed inhere
  {
   if(TrailHLineInPips>0)
     {
      if(AboveOrBelow=="above")
        {
         // then trail this horizontal line above Bid...
        }
      if(AboveOrBelow=="below")
        {
         // then trail this horizontal line below Bid...
        }
     }
  }
 
Thank you, GumRai, for your answer. So close I was! LOL

I have in meantime solved the matter like this:

extern int TrailHLineInPips=300;
...
void OnTick()
  {
   if(ObjectFind(0,"above")==0 || ObjectFind(0,"below")==0) TrailHLineOnChart(); // object is on main window
   ...
  }
...
//--- TRAIL HORIZONTAL LINE ON CHART ---- custom function
void TrailHLineOnChart() // https://forum.mql4.com/67445
  {
   double HLineToPips=TrailHLineInPips*Point;
   if(TrailHLineBB==0) // condition is met for trailing in pips
     {
      //Print("TrailHLineBB = "+TrailHLineBB); // test, works OK
      //--- Write info on chart, into the button
      ObjectSetString(0,"btn_HorizontalLineTF",OBJPROP_TEXT,TrailHLineInPips);ObjectSetInteger(0,"btn_HorizontalLineTF",OBJPROP_COLOR,clrLightBlue);
      ObjectSetString(0,"btn_HorizontalLineTF",OBJPROP_TOOLTIP,"BB=0!\nUsing pips\nfor trailing");
      AboveHLineTS=ObjectGet("above",OBJPROP_PRICE1); // 'initialize' "above" price
      if(Ask<AboveHLineTS-HLineToPips) AboveHLineTS=Ask+HLineToPips; // Ask = buy, calculate trailing in pips, if price goes lower, move horizontal line
      BelowHLineTS=ObjectGet("below",OBJPROP_PRICE1); // 'initialize' "below" price
      if(Bid>BelowHLineTS+HLineToPips) BelowHLineTS=Bid-HLineToPips; // Bid = sell, calculate..., if price goes higher, move...
     }
   else if(TrailHLineBB>0) // calculate trailing in high/low on selected timeframe (...TF) x bars back (...BB)
     {
      AboveHLineTS=iHigh(NULL,TrailHLineTF,iHighest(NULL,TrailHLineTF,MODE_HIGH,TrailHLineBB,1));
      BelowHLineTS=iLow(NULL,TrailHLineTF,iLowest(NULL,TrailHLineTF,MODE_LOW,TrailHLineBB,1));
     }
   ObjectSet("above",OBJPROP_PRICE1,AboveHLineTS); // move line down...
   ObjectSet("below",OBJPROP_PRICE1,BelowHLineTS); // move line up...
/* Print("TrailHLineOnChart function: AboveHLineTS = "+NormalizeDouble(AboveHLineTS,_Digits)+", BelowHLineTS = "+NormalizeDouble(BelowHLineTS,_Digits)+" TrailHLineInPips = "+
         TrailHLineInPips+" HLineToPips = "+HLineToPips); // test, works OK*/
  }

Best regards,


Simon

S love nia

Reason: