Hello folks,
What i want to do: I have two target prices. A low target and a high target. I want to check what has been reached last on the current chart. Like checking if the last renko bar was down or up.
I also tried all variations of Low[], High[], iLow and iHigh, nothing changed
This is what I have but it is not working. iLow and iHigh are always returning 0
It's running endless because iLow and iHigh are always 0 (Checked with a simple pring in the while queue)
Oops! I accidentally deleted my original post, and now I have to re-write it (but I will only re-state a few of the things for now):
- Is this an Indicator, EA or a Script?
- Please show us in what context this code is being called?
- Also, please check the number of available Bars and don't just increment the shift (the "i") indiscriminately.
- Also, I assume this is MQL4 used on MetaTrader 4 - correct?
- docs.mql4.com
Oops! I accidentally deleted my original post, and now I have to re-write it (but I will only re-state a few of the things for now):
- Is this an Indicator, EA or a Script?
- Please show us in what context this code is being called?
- Also, please check the number of available Bars and don't just increment the shift (the "i") indiscriminately.
- Also, I assume this is MQL4 used on MetaTrader 4 - correct?
It is an EA on MQL4 using MT4.
The available Bars are beyond 1000, I usually check them I just left it out to see if this was the reason for the error. Put it back in now ( && i<=Bars-1 )
The function is being called in the OnTick event
It is an EA on MQL4 using MT4.
The available Bars are beyond 1000, I usually check them I just left it out to see if this was the reason for the error. Put it back in now ( && i<=Bars-1 )
The function is being called in the OnTick event
There is your problem! On EUR/USD that would be 2000000 pips. There is no way that the High or a Low would ever break that!
EDIT: Here is your code rewritten but untested:
EDIT 2: NB! Please note that I changed the code from Ask to Bid, because the OHLC Bar prices are based on Bid prices and not Ask Prices.
extern double rSize = 0.0002;
void OnTick()
{
double
price = Bid,
lowT = price - rSize,
highT = price + rSize,
low,
high;
bool breakout = false;
for( int i = 1; i < Bars; i++ )
{
low = Low[ i ];
high = High[ i ];
breakout = ( high >= highT ) || ( low <= lowT );
if( breakout ) break;
}
if( breakout )
{
// Do something
}
}
There is your problem! On EUR/USD that would be 2000000 pips. There is no way that the High or a Low would ever break that!
EDIT: Here is your code rewritten but untested:
EDIT 2: NB! Please note that I changed the code from Ask to Bid, because the OHLC Bar prices are based on Bid prices and not Ask Prices.
extern double rSize = 0.0002;
void OnTick()
{
double
price = Bid,
lowT = price - rSize,
highT = price + rSize,
low,
high;
bool breakout = false;
for( int i = 1; i < Bars; i++ )
{
low = Low[ i ];
high = High[ i ];
breakout = ( high >= highT ) || ( low <= lowT );
if( breakout ) break;
}
if( breakout )
{
// Do something
}
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello folks,
What i want to do: I have two target prices. A low target and a high target. I want to check what has been reached last on the current chart. Like checking if the last renko bar was down or up.
I also tried all variations of Low[], High[], iLow and iHigh, nothing changed
This is what I have but it is not working. iLow and iHigh are always returning 0
double low;
double high;
int rSize = 200;
int i=1;
double lowT=price-rSize;
double highT=price+rSize;
while(high < highT && low > lowT)
{
low=iLow(Symbol(),PERIOD_CURRENT,i);
high=iHigh(NULL,0,i);
i++;
}
It's running endless because iLow and iHigh are always 0 (Checked with a simple pring in the while queue)