@kam-dorra said in bt.If operator/function:

I have no coding experience at all

The problem is not there (that's another problem), the problem is understanding why `bt.If`

delivers two values. `bt.If`

returns a **line**. This is just like, for example, `self.data.close`

.

Which means that for each tick (call iteration if you wish) it has to **have** a value.

@kam-dorra said in bt.If operator/function:

could you show me how to only have the self.data.low results in the line?

@ab_trader **cannot** show you that, neither can anyone else, because you **cannot** have a line that sometimes has values and some other times doesn't. You have something *similar* if you don't fill the value (which is often done when developing an indicator), because if you skip setting a value, the default value is filled in for you, with the default value bein `NaN`

(aka *"Not a Number"* or a default representation in the IEEE Floating Point Standard to indicate that it doesn't represent an actual value)

The thing with `NaN`

is that it may actually be what you need or it may not. Because, not being a number, arithmetic and logic operations won't work the way you expect them to (they will work, but the result may not match your expectations, which in fact means ... it doesn't work)

Use a well defined floating point value such as `Inf`

or `-Inf`

is better in order to have well defined operations and results. If your problem is the `low`

, what seems plausible is:

```
low_or_inf = bt.If(sma1(-2) > self.data.close(-1), self.data.low, float('Inf'))
```

One can be sure that the `low`

will *always* be *less* than `Inf`

.

Later in your code you can do the following

```
if low_or_inf[0] < float('Inf')
do_something_here()
```

With that logic implying that if something is less than *infinitum* ... it has to be `low`

Given that your initial statement gave an example

@kam-dorra said in bt.If operator/function:

```
def next(self):
if only_low[-1]>only_low[-2]:
self.buy() # enter long
```

the obvious thing would be

```
def next(self):
if low_or_inf[0] < float('Inf'):
if low_or_inf[-1] > low_or_inf[-2]: # this may also be pre-calculated as a line
self.buy() # enter long
```

To pack everything as a line

```
low_or_inf = bt.If(sma1(-2) > self.data.close(-1), self.data.low, float('Inf'))
low_signal = bt.If(low_or_inf < float('Inf'), low_or_inf(-1) > low_or_inf(-2), False)
```

Later in the code

```
def next(self):
if low_signal[0]:
self.buy()
```