Analizing market for checking price ranges, simply with iHighest and iLowest.

 
Hi.

I want use a simple code for checking out if market 
is under or not certain price-range criteria, into an expert advisor,
tick based (checking the values tick by tick),
utilizing the simple iHighest and iLowest function, with the 
timeframe and shift-bar in-function options.

In particular i want to check out bars back, if in the last
N timeframe, S shift bars back, the most high and low
price is, and then subtracting the low from the high,
math absoluting it (for avoid errors by minus sign),
and then verify the returned value (in pips/points)
comparing with the price-range criteria.

In other words, something like this:


int N=15; // 15 minutes chart

int S=5;  // shift bar back number 5

int Pips=60;

double Hi, Lo, H, L;


Hi=High[iHighest(NULL,N,MODE_HIGH,S,0)];

Lo=Low[iLowest(NULL,N,MODE_LOW,S,0)];


MathAbs(Hi); MathAbs(Lo);


H=MathAbs(Hi)-MathAbs(Lo);

L=MathAbs(Lo)-MathAbs(Hi);


if( ((MathAbs(SidH))<Pips*Point*10)

  Print("Max price range is below ",Pips," Pips);

else 

  Print("Max price range is over ",Pips," Pips);



OR this other one "if" condition (i think is the same):


if( ((MathAbs(SidH))<Pips*Point*10 && (MathAbs(SidL))<Pips*Point*10 )

  Print("Max price range is below ",Pips," Pips);

else 

  Print("Max price range is over ",Pips," Pips);



I coded, but it does not satisfy (true) the condition, or at least
seems not work properly, seems entering everytime in "else" condition (the false one).
Why?

I use Pips*Point*10; 
i use *10 because i don't know why
but if i not use *10 the results on Pips*Point,
when Pips value i.e. is 60, is not return 0.0060 (on eur/usd i.e.) but it
return value 0.0006; I need to multiply *10 the points in order
to get the correct (for my purpose) 0.0060 pips price
range. Some suggestions?

It is my idea correct, or applyiable for my purpose?

 
traderkmi:
[...] I coded, but it does not satisfy (true) the condition, or at least
seems not work properly, seems entering everytime in "else" condition (the false one).
[...]
I use Pips*Point*10; 
i use *10 because i don't know why
but if i not use *10 the results on Pips*Point,
when Pips value i.e. is 60, is not return 0.0060 (on eur/usd i.e.) but it
return value 0.0006;

You seem to have made several alterations to your post, to the point where the code is now fairly broken - it no longer uses the "Pips*Point*10" which you refer to.


If you're getting back a price range of 0.0006 rather than the 0.0060 which you're expecting, is it not just because your broker quotes prices to 5 decimal places whereas you're thinking in 4DP terms?


Either way, something like the following sounds as though it's what you're after:


   int N=15; // 15 minutes chart

   int S=5;  // shift bar back number 5

   int Pips=60;

   double Hi, Lo, H, L;


   Hi=High[iHighest(NULL,N,MODE_HIGH,S,0)];

   Lo=Low[iLowest(NULL,N,MODE_LOW,S,0)];


   // Returns a difference in price between the high and low, such as 0.00358

   // (Kept the use of MathAbs from the original code, but it should be

   // redundant. iHighest and iLowest examine the same range of bars, and

   // therefore Hi should always be higher than Lo.)

   double Range = MathAbs(Hi - Lo);

   

   // Convert the price range into a number of pips. 

   // (The range size must be an integer number of pips. However,

   // the use of MathRound is to avoid FPU problems where the division

   // produces a value such as 43.9999999999999992 which gets rounded 

   // down to 43 if there's a straight cast to an integer)

   int RangeInPips = MathRound(Range / Point);


   // Optional - if you want to specify the Pips parameter in 4DP terms,

   // regardless of whether your broker uses 4DP or 5DP, use something

   // like the following. (Also assumes that 3DP should be adjusted to 2DP,

   // and always rounds *down*)

   switch (MarketInfo(Symbol(), MODE_DIGITS)) {

      case 3:

      case 5:

         RangeInPips /= 10;

         break;

   }


   // Compare range size against the Pips parameter

   if (RangeInPips > Pips) {

      Print("Range is more than " + Pips);

   } else {

      Print("Range is less than or equal to " + Pips);

   }  


 
jjc:

You seem to have made several alterations to your post, to the point where the code is now fairly broken - it no longer uses the "Pips*Point*10" which you refer to.


Sorry.


I used for first time the SRC function in posting, and something goes wrong (does it altering my code itself?)


Of course, here what the original code i refer to:


int N=15; // 15 minutes chart

int S=5;  // shift bar back number 5

int Pips=60;

double Hi, Lo, H, L;


Hi=High[iHighest(NULL,N,MODE_HIGH,S,0)];

Lo=Low[iLowest(NULL,N,MODE_LOW,S,0)];


MathAbs(Hi); MathAbs(Lo);


H=MathAbs(Hi)-MathAbs(Lo);

L=MathAbs(Lo)-MathAbs(Hi);


if( ((MathAbs(SidH))<Pips*Point*10)

  Print("Max price range is below ",Pips," Pips);

else 

  Print("Max price range is over ",Pips," Pips);



OR this other one "if" condition (i think is the same):


if( ((MathAbs(SidH))<Pips*Point*10 && (MathAbs(SidL))<Pips*Point*10 )

  Print("Max price range is below ",Pips," Pips);

else 

  Print("Max price range is over ",Pips," Pips);




I will update the first post also.

 
jjc:



If you're getting back a price range of 0.0006 rather than the 0.0060 which you're expecting, is it not just because your broker quotes prices to 5 decimal places whereas you're thinking in 4DP terms?


>>>>> 4DP means  = 4 Digits Pips? (like 1.0000) ? And 5DP something like 1.00000 ? I suppose yes



Either way, something like the following sounds as though it's what you're after:


>>>> Thanks very much man. 

your suggestions are very clear and useful. Good fortune to you!



>>>>> Another one please:


it is possible to "embed" your code of this topic, into a function like pricerange() and use it

in the whole expert, where needed, instead of copy and paste the entire code

you suggested me?


 

Hi.


It seems those are the results in an example:


Range: 0.0069

RangeInPips: 6905


Pips:30



For your suggestion:

if (RangeInPips > Pips)

etc...


This means 

if (6905 > 30)

etc...


Some suggestions?


I will study this fact, too.


Thanks for suggestions ofc.




Reason: