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

To add comments, please log in or register
Eng Keat Ang
2016
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 :

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

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

Seng Joo Thio
1209
Seng Joo Thio  
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.

Keith Watford
Moderator
20375
Keith Watford  
Eng Keat Ang:

Do not double post.

I have deleted your other topic.

Aliakbar Kavosi
6704
Aliakbar Kavosi  

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];
     openSellTrade();}
}

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))) 
         openSellTrade(); 
}
Eng Keat Ang
2016
Eng Keat Ang  

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

asds

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)) { 
     openSellTrade(); 
}

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]?

Seng Joo Thio
1209
Seng Joo Thio  
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.)
Eng Keat Ang
2016
Eng Keat Ang  
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?

asa

Seng Joo Thio
1209
Seng Joo Thio  
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?

Too bad then, hope someone else will understand your contradicting posts better.

Eng Keat Ang
2016
Eng Keat Ang  

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)) { 
     openSellTrade(); 
}

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]); 
      }
}
To add comments, please log in or register