Question: I have a long complicated expression that refers to multiple tables. The expression returns a string, but i want to return a different string if the returned string was empty "".

With the IF function i have to write my expression twice like:

```
IF(*expression* = "", "string not found", *expression*)

```

I know that NULLIF has something close to what i want as:

```
NULLIF(*expression*, "")

```

would return my expression if it was not empty, but if it was empty, it would return NULL, rather than a costum string.

Is there any way to avoid duplicating the expression, while still being able to choose a custom return string instead of just null, since duplicating the expressions (i have several cases of this in my query) would make the view-quera virtually unreadable

Answer: 
No, you don't need a cycle. You can attain your layer system like this:

```
double GroupExponent(int type)
{
   double lot=0,exponent=1.8,initialLot=0.01;
   int group = 5;
   if(type==OP_SELL)                         
   {
      lot = NormalizeDouble(initialLot * MathPow(exponent, (TotalSell() - 1) / group), 2);
   }
   return lot;
}

int TotalSell()
{
   int Sell=0;
   for(int trade=OrdersTotal()-1; trade>=0; trade--)
   {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))continue;
      if(OrderSymbol()==Symbol() && OrderType()==OP_SELL))
         Sell++;
   }
   return Sell;
}

```

Note: This will work as intended only if `Layer == 1` equals `TotalSell() == 1`. If `Layer == 1` equals `TotalSell() == 0`, then there is no need to subtract 1 from `TotalSell()` inside `MathPow()`.
> 
> **Q** : *"How to group a lot exponent in MQL4 / MT4?"*
> 
> 
> 

Well, technically speaking, the ***Exponent = 1.8*** is not an exponent per-se, but rather a scaling constant, that ***gets exponentiated*** by plain ordinals.

See the calculation formula of the Lot-sizings, that match the Table above:

```
|
|>>> for                                   aLayerNUMBER in range( 1, 11 ):
...      aVolumeInLOTs = 0.01 * ( 1.8 ** ( aLayerNUMBER - 1 ) )
...      print "LAYER: {0: >2d} - {1: >5.2f} Lots".format( aLayerNUMBER,
...                                                        aVolumeInLOTs
...                                                        )
... 
LAYER:  1 -  0.01 Lots
LAYER:  2 -  0.02 Lots
LAYER:  3 -  0.03 Lots
LAYER:  4 -  0.06 Lots
LAYER:  5 -  0.10 Lots
LAYER:  6 -  0.19 Lots
LAYER:  7 -  0.34 Lots
LAYER:  8 -  0.61 Lots
LAYER:  9 -  1.10 Lots
LAYER: 10 -  1.98 Lots
+0:01:07.587141
13:31:06
|
|>>>

```

In MQL4 there will go, most often this :  
`double aVolumeInLOTs = NormalizeDouble( 0.01 * MathPow( 1.8, aLayerNUMBER - 1 ), 2 );`

The groupings are groups of (here) 5 trades, each having the same size / volume,  
again in the exponentiated progression of ( 0.01, 0.02, 0.03, 0.06, 0.10, 0.19, 0.34, 0.61, 1.10, 1.98, 3.57, 6.42, 11.56, 20.82, 37.48, 67.46, 121.43, 218.59, 393.46, ... )

The last piece of the puzzle is a reason, where to stop producing the 5-trades' groups ( why stopping right at the fourth group-of-5-s, sized 0.06 Lots each, and not proceeding anywhere further ).

That information was not present in the Question and remains thus an un-decidable for us, obviously, unless more pieces of information were added.