EA not updating low

 

Hi everyone,

Maybe you can figure what's wrong with the following program.

The logic of the code is to create a range of 10 pips where the low is always going to be the lowest price since the EA started and that the price did not touch the upper band of the range. Every time, the upper band is touched, the EA is taking the touching time as the new starting point.

Not always but sometimes, the EA is not updating the lower band to the lowest price as the figure below shows.


Am i missing something in my code ?

datetime x;
double y, y1;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
x = iTime(Symbol(), PERIOD_M1, 0);
y = iLow(Symbol(), PERIOD_M1, 0);
y1 = y + 50 * Point;
ObjectDelete("ligneV");
ObjectCreate("ligneV", OBJ_VLINE, 0, x, 0, 0, 0, 0, 0);
ObjectSet("ligneV", OBJPROP_COLOR, White);
ObjectDelete("ligneY");
ObjectCreate("ligneY", OBJ_HLINE, 0, 0, y);
ObjectSet("ligneY", OBJPROP_COLOR, White);
ObjectDelete("ligneY1");
ObjectCreate("ligneY1", OBJ_HLINE, 0, 0, y);
ObjectSet("ligneY1", OBJPROP_COLOR, White);
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(y != iLow(Symbol(), PERIOD_M1, iLowest(Symbol(), PERIOD_M1, MODE_LOW, iBarShift(Symbol(), PERIOD_M1, x, true), 0)))
{
y = iLow(Symbol(), PERIOD_M1, iLowest(Symbol(), PERIOD_M1, MODE_LOW, iBarShift(Symbol(), PERIOD_M1, x, true), 0));
y1 = y + 10 * Point;
ObjectDelete("ligneY");
ObjectCreate("ligneY", OBJ_HLINE, 0, 0, y);
ObjectSet("ligneY", OBJPROP_COLOR, White);
ObjectDelete("ligneY1");
ObjectCreate("ligneY1", OBJ_HLINE, 0, 0, y1);
ObjectSet("ligneY1", OBJPROP_COLOR, White);
}

if(MarketInfo(Symbol(), MODE_BID) >= y1)
{
x = iTime(Symbol(), PERIOD_M1, 0);
y = y1;
y1 = y + 10 * Point;
ObjectDelete("ligneV");
ObjectCreate("ligneV", OBJ_VLINE, 0, x, 0,0,0,0,0);
ObjectSet("ligneV", OBJPROP_COLOR, White);
ObjectDelete("ligneY");
ObjectCreate("ligneY", OBJ_HLINE, 0, 0, y);
ObjectSet("ligneY", OBJPROP_COLOR, White);
ObjectDelete("ligneY1");
ObjectCreate("ligneY1", OBJ_HLINE, 0, 0, y1);
ObjectSet("ligneY1", OBJPROP_COLOR, White);
}

//----
return(0);
}
//+------------------------------------------------------------------+

Thanks

 

Please use the SRC button to post code.

Instead of . . .

y = iLow(Symbol(), PERIOD_M1, iLowest(Symbol(), PERIOD_M1, MODE_HIGH, iBarShift(Symbol(), PERIOD_M1, x, true), 0));

don't you mean . . .

y = iLow(Symbol(), PERIOD_M1, iLowest(Symbol(), PERIOD_M1,   MODE_LOW,   iBarShift(Symbol(), PERIOD_M1, x, true), 0));
 

Fixed the src issue. Thanks

You were right about MODE_LOW but it was just a typo - the problem is still here.

I tried adding RefreshRates() but that doesn't make any difference.

Any ideas.

Cheers

 
ObjectSet("ligneY3" ???
 
RefreshRates only has any relevance to Predefined Variables
 
RaptorUK:
RefreshRates only has any relevance to Predefined Variables

Is there any reasons why MT4 could not get the lowest price then ?

I read somewhere that when the ticks come up too fast, MT4 can ignore some of them in the process but in my case, I am analyzing the data after so it should be able to get the right price.

 
y = iLow(Symbol(), PERIOD_M1, iLowest(Symbol(), PERIOD_M1,   MODE_LOW,   iBarShift(Symbol(), PERIOD_M1, x, true), 0));
Don't write indecipherable lines like that.
int iX = iBarShift(Symbol(), PERIOD_M1, x, true),
    iLL= iLowest(Symbol(), PERIOD_M1,   MODE_LOW, iX , 0);
y = iLow(Symbol(), PERIOD_M1, iLL); // Why not just Low[iLL]
How many bars are there between iX and bar 0. iX+1 But you're not looking at the x bar.
 
fftremblay:

Is there any reasons why MT4 could not get the lowest price then ?

nop, there is no reason for that, the only reason is the problem in your code

 

Thanks everyone - I will follow WHRoeder advice on writing clearer code and simplify the logic.

Reason: