# Where i should "return" operator in this UDF

To add comments, please log in or register
1025

```double CalculateHH ()// This function is to get the highest high price since open price of certain order

{  for ( int n=OrdersTotal()-1; n>=0; n-- )// first i need to loop all orders
{
if (OrderSelect( n ,SELECT_BY_POS,MODE_TRADES)) // select my order of interest
{
if(OrderType()== OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==mBMagicf && n<=1 )
{
datetime    OOTs         = OrderOpenTime();          // Assumes OrderSelect() done already
int         iOOTs        = iBarShift(NULL,0, OOTs);   // Bar of the open.
#define     iBarCURRENTs   0                         // Include current bar.
int         nSinceS  = iOOTs - iBarCURRENTs + 1;       // No. bars since open.
int         iHi         = iHighest(NULL,0, MODE_HIGH, nSinceS, iBarCURRENTs);
double      HH          = High [iHi];                // Highest high.
return (HH);// Now i need to return this value but i am not sure where i should put the " return" operator???
}

}
}
}```
`I am getting this error:`
1025

When i put it in this position to terminate the function and return the double value, i got this down error

```double CalculateHH ()// This function is to get the highest high price since open price of certain order

{  for ( int n=OrdersTotal()-1; n>=0; n-- )// first i need to loop all orders
{
if (OrderSelect( n ,SELECT_BY_POS,MODE_TRADES)) // select my order of interest
{
if(OrderType()== OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==mBMagicf && n<=1 )
{
datetime    OOTs         = OrderOpenTime();          // Assumes OrderSelect() done already
int         iOOTs        = iBarShift(NULL,0, OOTs);   // Bar of the open.
#define     iBarCURRENTs   0                         // Include current bar.
int         nSinceS  = iOOTs - iBarCURRENTs + 1;       // No. bars since open.
int         iHi         = iHighest(NULL,0, MODE_HIGH, nSinceS, iBarCURRENTs);
double (HH)          = High [iHi];                // Highest high.

}

}
}
return (HH);// Now i need to return this value but i am not sure where i should put the " return" operator???
}```
1025

Ok, i have just read and understood the idea that a UDF has to return a value and for IF statements, we need to make sure that we return a value even with false IFs.  I got that.
1025

However, when i added another function for getting the lowest low. I got this warning
```double CalculateLL ()// This function is to get the highest high price since open price of certain order

{  for ( int n=OrdersTotal()-1; n>=0; n-- )// first i need to loop all orders
{
if (OrderSelect( n ,SELECT_BY_POS,MODE_TRADES)) // select my order of interest
{
if(OrderType()== OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==mBMagicf && n<=1 )
{

Comment ("Order selected");
datetime    OOTs         = OrderOpenTime();          // Assumes OrderSelect() done already
int         iOOTs        = iBarShift(NULL,0, OOTs);   // Bar of the open.
#define     iBarCURRENTs   0                         // Include current bar.
int         nSinceS  = iOOTs - iBarCURRENTs + 1;       // No. bars since open.
int         iLi         = iLowest(NULL,0, MODE_LOW, nSinceS, iBarCURRENTs);
double LL          = High [iLi];                // Lowest low.

}

}
}
return (LL);
}```
1025

I solved this macro redefinition issue. By deleting #define code line in both functions and only post one of them on top of EA code just above extern variables. :)
To add comments, please log in or register