# How to separate old Close[1] and new Close[1]?

2016

Task : "If found a bullish candle, then wait until next candle close above the highest price among recent 50 candles".

I acheive the above task by writting the following code :

```if (Open[1] < Close[1])
{
double wanted_level = High[1];
}
if (Close[1] > iHigh(NULL, 0, iHighest(NULL,0,MODE_HIGH,50,2))) {
}```

But it fail, because new Close[1] value conflict with old Close[1], how to solve it?

1209

Eng Keat Ang:

Task : "If found a bullish candle, then wait until next candle close above the highest price among recent 50 candles".

I acheive the above task by writting the following code :

But it fail, because new Close[1] value conflict with old Close[1], how to solve it?

I assume the above is just pseudo code... so in terms of logic and the use of iHighest, there is no conflict, and I've just tested it.

Moderator
20375

Eng Keat Ang:

Do not double post.

I have deleted your other topic.

6704

I think you must use AND operator for your code:

```if ( Open[1] < Close[1] && Close[1] > iHigh(NULL, 0, iHighest(NULL,0,MODE_HIGH,50,2)) )
{
double wanted_level = High[1];
}
```

or use if block similar to this:

```if (Open[1] < Close[1])
{
double wanted_level = High[1];
if (Close[1] > iHigh(NULL, 0, iHighest(NULL,0,MODE_HIGH,50,2)))
}```
2016

Maybe my question is not clear enough, let me show more detail of the question :

```if ((Close[2] > Open[2]) && (Close[1] < Open[1])}
{
if(High[2] > iHigh(NULL, 0, iHighest(NULL,0,MODE_HIGH,50,2))) {
draw_purple_horizontal_line(High[2]);
}
}
if ((Close[1] > Open[1])&&(Close[1] > purple_horizontal_line)) {
}```

Fail to open sell trade, because system looks at Old Close[1] which is not close above purple horizontal line yet. How to make system look for new Close[1]?

1209

Eng Keat Ang:

Maybe my question is not clear enough, let me show more detail of the question :

Fail to open sell trade, because system looks at Old Close[1] which is not close above purple horizontal line yet. How to make system look for new Close[1]?

In this version of your code, when Close[2]>Open[2] && Close[1]<Open[1], note that High[2] may not be higher than High[1], and iHighest(NULL,0,MODE_HIGH,50,x) will include High[2] if x is 2, so change your x to 3.

Here's what I used to test, and concluded in my earlier post that your logic works:

```   if (Close[1]>High[iHighest(_Symbol,_Period,MODE_HIGH,5,2)])
Print ("Found High!");

if (Close[1]<Low[iLowest(_Symbol,_Period,MODE_LOW,5,2)])
Print ("Found Low!");
```
(I used 5 instead of 50 so I can see results earlier.)
2016

Seng Joo Thio:

In this version of your code, when Close[2]>Open[2] && Close[1]<Open[1], note that High[2] may not be higher than High[1], and iHighest(NULL,0,MODE_HIGH,50,x) will include High[2] if x is 2, so change your x to 3.

Here's what I used to test, and concluded in my earlier post that your logic works:

(I used 5 instead of 50 so I can see results earlier.)

it is out of topic. My question is why EA only open sell trade when 1st candle after purple horizontal line close above horizontal line. Why EA wont open sell trade in future new candle when they close above horizontal line?

1209

Eng Keat Ang:

it is out of topic. My question is why EA only open sell trade when 1st candle after purple horizontal line close above horizontal line. Why EA wont open sell trade in future new candle when they close above horizontal line?

2016

Ok problem is solved. Solution is declare variable globally, and move two block of if statement upside down.

```if ((Close[1] > Open[1])&&(Close[1] > purple_horizontal_line)) {