how to get this range?

 

hi guys,

i thought about something like that:

i wanna test wether in the last 10 bars there is a rage of X pips.

i coded it like that but it doesnÄt really work for me.

can you help me?

for(int countback = 20 ; countback >= 0 ; countback--)
   {
   int high20Ago = High[countback];
   int low20Ago = Low[countback];
   int currentBid = Bid;
   }

   if(high20Ago == "X pips")
   {
      Alert("high");
      int diff = high20Ago - currentBid;
      if (diff == 20)
       {
         Alert("open sell");
      }
   }   
   if(low20Ago == "X pips")
   {
      Alert("low");
      diff = currentBid - low20Ago;
      if (diff == 20)
      {
         Alert("open buy");
      } 
   }
 

is my code a way to do that or not?

 

Why not use iHighest & iLowest ?

double RangeLastTenBars = High[iHighest(NULL, 0, MODE_HIGH, 10, 1)]  - Low[iLowest(NULL, 0, MODE_LOW, 10, 1)] ;
 
thanks, do i still need the "for()" when i use your code where the last 10 bars are declared?
 

yes but i want to check if there IS a range of X pips between the last ten bars:

for example X pips are 5 pips...so i wanna know if in the last 10 bars there is somewhere a range of 5 pips.

that can be between the 1st and the 2nd bar, but it can also be from the current up the the 9th or 10th bar.

you know what i mean?

 
FlashX:

yes but i want to check if there IS a range of X pips between the last ten bars:

for example X pips are 5 pips...so i wanna know if in the last 10 bars there is somewhere a range of 5 pips.

that can be between the 1st and the 2nd bar, but it can also be from the current up the the 9th or 10th bar.

you know what i mean?

Yes . . . if (RangeLastTenBars > 5 pips) then there is a range greater than 5 pips
 

not exactly:

it can also be:

if (RangeLastFIFEBars > 5 pips) then there is a range greater than 5 pips

i can be from RangeLastONEBars till RangeLastTENBars where 5 pips can appear...

thats what i wanna check you got me?


mybe put a variable in your code and put a for() to it?

double RangeLastTenBars = High[iHighest(NULL, 0, MODE_HIGH, COUNTER, 1)]  - Low[iLowest(NULL, 0, MODE_LOW, COUNTER, 1)] ;
 
FlashX:

mybe put a variable in your code and put a for() to it?

Sure, try it . . . this is what you said though " yes but i want to check if there IS a range of X pips between the last ten bars: "
 
sorry im not the best in english :D i mean somewhere within the ten bars and when yes, how many bars back from the current one?
 
FlashX:
sorry im not the best in english :D i mean somewhere within the ten bars and when yes, how many bars back from the current one?
Ahhhhhh . . . now I see. ;-) if you want the start and end bar numbers for the range I think you need 2 loops, one nested inside the other. If you just want the leftmost bar of the range you just need one loop.
 

sorry im a newbie to mql4 can you describe in a little code what you mean?

would be very nice :)

btw: yes now you understood what i mean ;)

Reason: