Get values for specific number os bars

 

Hi there,

Perhaps some of you can help me developing a specific code I need.

I know that the routines are already included on mql language but my problem is that I do not know how to program it.


I am using a 30M timeframe and I need to get the values for a specific number os bars. The values I need are, higher, lower, open and close for a specific number of bars.


The idea is to decide if enter a position or not based on support, resistances and pivot point.


I need to enter long when the price reaches resistance 1, but none of the last 5 bars have crossed/touched the pivot line. Or enter short when the price reaches support 1 and none of the last five bars crossed/touched the pivot point.


That is, if the last five bars did not touched/crossed the pivot line and are above resistance 1, I BUY. The inverse happens with sell.


I already have the code for the PIVOT, R1, R2, R3, S1, S2 and S3 just don't know how to calculate the value for the last x bars.


Also, and if possible, I need to get the value for the first bars on the market open. Lets say, the 5 first bars.


Thank you very much


Regards

Paulo

 

Hint:

iHighest() is used to find the bar index among a range of bars

iHigh() takes that index and finds tthe high price

 
phy:

Hint:

iHighest() is used to find the bar index among a range of bars

iHigh() takes that index and finds tthe high price

Hi phy,


Thank you.

I have found on code library this two functions. My problem is that I do not to construct an array routine to find those values.

Can you please post a sample code on how to do it? That way I will try to adapt it to my needs after I understand your sample code...


Thank you once again


Paulo

 
No special array needed, it reads from price history.
 
phy:
No special array needed, it reads from price history.

Hi phy,


What about if I need it to consider only from the first bar on the new open market? Imagine that I get a signal at 1AM GMT, if it counts the last 5 bars (on a 30M timeframe) it will also consider the last bars from the closed (yesterday) day trading...


I take this sample on the mql library but unfortunetly they do not tell me nothing... I am a newbie programming in mql.

- For iHighest:


double val;

// calculating the highest value on the 20 consequtive bars in the range

// from the 4th to the 23rd index inclusive on the current chart

val=High[iHighest(NULL,0,MODE_HIGH,20,4)];


When it refers to 20 consecutive bars in range, does it refers to 20 last bars? If so, is the actual bar included?


Besides being a newbie on mql programming, my mother language is Portuguese and as you may understand it is difficult for me to understand some of English expressions.


Thank you very much


Paulo

 

----Bars on chart or price history---------------------------------------------------------

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbcccc

val=High[iHighest(NULL,0,MODE_HIGH,20,4)];

iHighest() finds the index of the highest "b" bar ( among 20 bars) and High(iHighest()) finds the high price of that bar

starting with bar 4

the current bar is bar 0

 
phy:

Bars on chart:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbcccc

val=High[iHighest(NULL,0,MODE_HIGH,20,4)];

finds the index of the highest "b" bar ( among 20 bars) and finds the high price of that bar

starting with bar 4

the current bar is bar 0

Dear phy


Your help is very helpfull. Thank you, thank you very much.

I have made some tests and I learn another way to find the highest/lowest price from a specific number of bars.

I also now that if I need to know if some of this bars have reached/touhced a specific value I can do it by testing the final valur for the "val" variable, like:

if (val >=x)...


What about if I need to get and pass the highest value of each bar counted? Not just the highest value for a number of bars, but the high price for a specific number of bars? For instance aaaaaaaaaaaaaaaaaaaaabbbccc... pass the high value of 3 bars starting from the third passed bar?


Also if possible, just consider from the first bar from the open market. That is, TODAY and not considering the yesterday bars?


I am very sorry to ask you all this codes,


Thank you very much once again


Regards


Paulo

 

aaaaaaaaaaaaaaaaaaaaabbbccc... pass the high value of 3 bars starting from the third passed bar?

High[3]... High[4]... High[5]

Also if possible, just consider from the first bar from the open market. That is, TODAY and not considering the yesterday bars?

iBarShift() takes a time value as input and returns a bar index to work with.
 

Hi phy,


I will try with these new code provided.

I will let you know the results

Thank you once again


Regards


Paulo