Good Day All
Please assist on the following, how do i write a code that will alert that " The Ask > 1.25654 and it has spent 30minutes trading at the level or not ".
I want to receive an alert if the market (ASK / BID) is above a certain price level and has spent so much time at the level.
Thank you for your assistance.
Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum 2017.07.19
Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum 2017.07.19
Apologies It wont happen again
Thank a lot. This is how I manage to do it. I am open for corrections and advise.
Thank a lot. This is how I manage to do it. I am open for corrections and advise.
Hello
Actually this is not the most accurate way for making it to work . for many reasons
1- You didn't check check the closing price of each bar in the body of your loop instead you just made it to check the same bar 30 times :) becuase you declared the PREVIOUS_CLOSE outside of the bool functions . So technically the code just compate the PREVIOUS_CLOSE against the aupPrice 30 times . which of course is not what you want . the correct way id to set the price inside of the loop body so it can change . this way
double prev_price= iClose(Symbol(),PERIOD_M1, i );
2- you need to not return true from the loop once single bar closes above the specified level . because this way if only one candle closed above the the specified level the loop would break without continue to check the remaining bars . I suggest you to use while loop in this case . so the code will be like that
double price = iClose(Symbol(),PERIOD_M1,31) ; // Arbitrary level int i=30 ; // First candle index for last 30 minutes bool isValid=true // Start with true while(isValid && i>=1) // Loop until this is not valid { isValid=iClose(Symbol(),PERIOD_M1,i)>=price ; i-- ; } if(isValid) { /// Do Something } else { // Do somethinf else }
Hello
Actually this is not the most accurate way for making it to work . for many reasons
1- You didn't check check the closing price of each bar in the body of your loop instead you just made it to check the same bar 30 times :) becuase you declared the PREVIOUS_CLOSE outside of the bool functions . So technically the code just compate the PREVIOUS_CLOSE against the aupPrice 30 times . which of course is not what you want . the correct way id to set the price inside of the loop body so it can change . this way
2- you need to not return true from the loop once single bar closes above the specified level . because this way if only one candle closed above the the specified level the loop would break without continue to check the remaining bars . I suggest you to use while loop in this case . so the code will be like that
WOW !!!, Thank You Kareem, It is working Perfectly. Appreciate Your Help.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good Day All
Please assist on the following, how do i write a code that will alert that " The Ask > 1.25654 and it has spent 30minutes trading at the level or not ".
I want to receive an alert if the market (ASK / BID) is above a certain price level and has spent so much time at the level.
Thank you for your assistance.