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);
}
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.
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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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);