Download MetaTrader 5
To add comments, please log in or register
Enable MQL5 Storage to store your source codes. It is free!
Michal
13
Michal 2014.07.14 09:45 

Hi!

 

That's my first post, so let me welcome everyone.

 

I have found few topics about my issue, but nothing helped so far. While working on my ea, I would like to get Highest price of last 4 bars. That's my code:

 


if(Hour()==10)

{

int bar=iBarShift(Symbol(),PERIOD_H1,TimeCurrent());

    a=High[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0)];

}

 And than:

 

if((price+0.005)>a &&Hour()>9&&Hour()<16&&czy!=true)

 

Ea does strange things. It buys sometimes above High of the last bar, sometimes in area, which isnt't connected with any particular level of price. What is wrong?

 

 

Please, help me.

 

Cheers 

qjol
3243
qjol 2014.07.14 10:49  

if you are not using H1 TF you can't use High[xxx] you have to use iHigh:

iHigh(Symbol(), PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0))


B.T.W. what is the use of

int bar=iBarShift(Symbol(),PERIOD_H1,TimeCurrent());

in your code

Michal
13
Michal 2014.07.14 13:46  
I tried all variations with High[], iHigh(). Could anyone give me further explenation what should I do?
whroeder1
13589
whroeder1 2014.07.14 13:55  
What qjol said
Your code
a=High[iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0)];
Break it down
int    iHH_H1 = iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0);
double  HH_H1 = iHigh(   Symbol(),PERIOD_H1,iHH_H1);
iHH_H1 is the index on the H1 chart. High is the chart's timeframe, not H1. You can't use High[iHH_H1] Don't mix apples and oranges.
You also don't need to look at the H1
datetime now = Time[0];
datetime fourHours = now - 4 * PeriodSeconds(PERIOD_H1);
int      iFour     = iBarShift(NULL,0, fourHours);
int    iHH    = iHighest(NULL,0, MODE_HIGH, iFour+1, 0);
double  HH    = High[iHH];
Compute when. Find that chart bar. Find the highest on your chart [0 .. iFour] inclusive. Get the high from the chart. No other TF needed.
Keith Watford
Moderator
7861
Keith Watford 2014.07.14 13:57  
Michocio:
I tried all variations with High[], iHigh(). Could anyone give me further explenation what should I do?


Well, you could answer gjol's question.

 Also with your snippet of code

if((price+0.005)>a &&Hour()>9&&Hour()<16&&czy!=true)

 we have no idea where the variables "price" and "czy" come from.

qjol
3243
qjol 2014.07.14 14:05  
GumRai:


Well, you could answer gjol's question.



did I said already that I'm tired ?

Michal
13
Michal 2014.07.14 14:30  

As I said I found a lot of topics about that issue but nothing works. Big thank for everyone for help but even table from WHRoeder post didn't help me. Please take a butcher's on that code :

 

 

if(Ask>HH &&Hour()>9&&Hour()<16)

 {

int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Bid-0.005,Bid+0.015,"My order",16384,0,clrGreen);



   if(ticket<0)

     {

      Print("OrderSend failed with error #",GetLastError());

     }

   else

      Print("OrderSend placed successfully");


}

 Where HH is from gjol's code.

 

 

EA still makes order in wrong moments 

whroeder1
13589
whroeder1 2014.07.14 18:17  
Michocio: 

but nothing works. Big thank for everyone for help but even table from WHRoeder post didn't help me. Please take a butcher's on that code :

if(Ask>HH &&Hour()>9&&Hour()<16)

 Where HH is from gjol's code.

iHigh(Symbol(), PERIOD_H1,iHighest(Symbol(),PERIOD_H1,MODE_HIGH,4,0))
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  3. HH is the highest BID. What happens when when the Bid approaches HH? Ask becomes above HH and you open.
  4. If you change to Bid > HH you have another problem. What happens when Bid exceeds HH? HH increases because you are using bar zero
/
To add comments, please log in or register