Highest price of few last bar

 

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 

 

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

 
I tried all variations with High[], iHigh(). Could anyone give me further explenation what should I do?
 
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.
 
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.

 
GumRai:


Well, you could answer gjol's question.



did I said already that I'm tired ?

 

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 

 
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
 
whroeder1:
What qjol said
Your code
Break it downiHH_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 H1Compute when. Find that chart bar. Find the highest on your chart [0 .. iFour] inclusive. Get the high from the chart. No other TF needed.

super explanation

Reason: