Question: i try to code my first pinescript and i'm stuck:
Why does this not run?

I want do draw a dot when two lines cross up or cross down.
I want see the green dots only, when the crossdown is above the zero-line and i only want see the red dots, when crossup is below the zero-line.
x1 ist crossover and x2 is crossunder. x1 and x2 was delcared in the code further up in the script.

```
if x1 > 0
    plot(x1 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')
if x2 < 0
    plot(x2 ? circleYPosition : na, style=plot.style_circles, linewidth=6, color=dotColor, title='Dots')

```

When i use the code without the if-comand then the dots were shown.
So i think the problem have to do woth the if-command.

I've got this errors:

line 67: Cannot call 'operator >' with argument 'expr0'='x1'. An argument of 'series bool' type was used but a 'const float' is expected;

line 68: Cannot use 'plot' in local scope.;

line 70: Cannot call 'operator <' with argument 'expr0'='x2'. An argument of 'series bool' type was used but a 'const float' is expected;

line 71: Cannot use 'plot' in local scope.

Can you please help me to solve this problem?

Thanks a lot!!!

Answer: 
A key question to first ask yourself is:

> 
> Should `refreshBranchStatus` be re-invoked if `branchName` changes?
> 
> 
> 

If it *depends* on the value of `branchName` then in the majority of cases, yes, it probably should be re-invoked. But a comment thread on this answer seems to be implying that this is an obscure case where it depends on the value but *shouldn't* be re-invoked if that value changes.

Based on the answer to the above, there are two approaches:

---

**Option 1: Re-invoke when state changes**

Create a second effect. The first is triggered only once when the component is first loaded:

```
useEffect(() => {
  let newBranchName = getBranchName();
  setBranchName(newBranchName);
}, []);

```

The other is triggered when the `branchName` state value changes:

```
useEffect(() => {
  refreshBranchStatus();
}, [branchName]);

```

**Note:** This should also run on the initial load because the `branchName` state value "changed" (or "was set to") its initial state. So I'd expect this effect to be executed twice. Once on the initial state of `branchName` and once on the updated state of `branchName`. (And again on any subsequent updates of that state.)

---

**Option 2: Remove the dependency on state**

If you truly only want to invoke `refreshBranchStatus` once, and only once, when the component first loads **and** it needs the value of `branchName` to execute then you should pass that value to the function. Something like this:

```
useEffect(() => {
  let newBranchName = getBranchName();
  setBranchName(newBranchName);
  refreshBranchStatus(newBranchName);
}, []);

```

In this scenario `refreshBranchStatus` isn't internally checking the `branchName` state but is more of a "pure" function which requires that it be provided with the value it needs. Since you have that value when you invoke the function, just pass it to the function.
Every `usEffect` will be called on the initial render of the component, so if you're waiting for a value to be set, you need to check for it in the effect body.

I think what you're asking for could be achieved like this:

```
useEffect(() => {
  let branchName = getBranchName();
  setBranchName(branchName);
}, []);

useEffect(() => {
  if (branchName) refreshBranchStatus();
}, [branchName]);

```