@Chris Pinter
Try to code it like this:
do { price1 = SymbolInfoDouble(_Symbol,SYMBOL_ASK); Sleep(500); price2 = SymbolInfoDouble(_Symbol,SYMBOL_ASK); } while(price1>=price2); PrintFormat(" BUY price direction: Price: %f < %f",price1,price2);
I am building an EA program but I am having an unexpected result.
I want to make sure the market is going in the right direction.
So I want to check the price every 1/2 second.
The problem I have is that the code accepts the same price as true.
....
Crazy issue.....Thanks for your help.
Chris
Hello Chris,
What results can I expect/get from your code :
if (Marketdirection == true) // check to see if I selected a buy direction or a sell direction { double price1; double price2; string s_price1; string s_price2; do { price1 = SymbolInfoDouble(_Symbol,SYMBOL_ASK); //get the current price s_price1= DoubleToString(price1); PrintFormat(" Price1: %s",s_price1); Sleep(500); // wait 1/2 second price2 = SymbolInfoDouble(_Symbol,SYMBOL_ASK); //get the current price s_price2= DoubleToString(price2); PrintFormat(" Price2: %s",s_price2); } while((price1>price2) && (price1!=price2)); //spin if the first price is greater then or equal to the second price (sell direction) PrintFormat(" BUY price direction: Price: %s < %s",s_price1, s_price2); }
Steps of the process in words:
- Compare the number changes in every half second.
- At the beginning of the loop process, price1 contains the current price, and price2 is empty (or can be assumed as 0).
- Then in the next half second, price2 contains the latest current price.
- The expression "while" requires that
4.1. as long as price1 > price2
4.2 and price2 are not equal to price2,
-- then for sure the loop will continue. - When price1 is no longer greater than price2 or contains the same price, or price1 is less than price2,
-- then the loop ends. - After the loop ends, your EA will always write the result via PrintFormat() for 2 variables containing:
6.1. the same price
6.2 or price1 is less than price2 - return to step 1
So, the final result after the "while" ends must be:
-- price1 is equal or less than price2.
Result as text " BUY price direction: Price: 130.5930000 < 130.5930000" is correct.
Q:
How can I do a greater than operation but not include the equal too?
Is this is a bug in the C++ version used on MQL5? It is very frustrating.
A: No, I am sure that's not a bug :)
- - -
If you expect the EA to do something about the price changes between price1 & price2 through the "while" loop,
-- I'll place the order here:
do { price1 = SymbolInfoDouble(_Symbol,SYMBOL_ASK); s_price1= DoubleToString(price1); PrintFormat(" Price1: %s",s_price1); Sleep(500); price2 = SymbolInfoDouble(_Symbol,SYMBOL_ASK); s_price2= DoubleToString(price2); PrintFormat(" Price2: %s",s_price2); //-- if(price1>price2) { //-- do something } else if(price1<price2) { //-- do something } } while(price1!=price2 && !IsStopped());
Kind regards,
Yohana
PS.
I apologize if I misunderstood your needs.
What!? This is about the while loop.....it does not work.
Any comments on the issue at hand?.....about the "greater than " operator?
Thanks everyone,
That makes total sense now you explained it to me. I will rethink and try your suggestion. :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am building an EA program but I am having an unexpected result.
I want to make sure the market is going in the right direction. So I want to check the price every 1/2 second. The problem I have is that the code accepts the same price as true. for some reason the "greater than" operator (<) actually means "greater than or equal to" (<=) . which is not standard to C++. I am either going nuts or MQL5 is not the same as C++.
this example above SHOULD WORK just fine....but it does not. I tried a work around and add a != to the while statement so it looks like
my while statement looks like this
want to eliminate this by adding a not equal statement. The code is not doing what I want it to do.
Here is my actual code,,,,with lots of detail.
The output of the code is as follows:
Price1: 130.5930000
Price2: 130.5930000
BUY price direction: Price: 130.5930000 < 130.5930000 <--- this is not right....it should just keep spinning!
If the two prices are different by 1 pip then it would work just fine....but the code exits the do while loop too soon. Once the two number equal it exits.
the greater than (>) should not be accepting equal numbers....but it is.
In the while statement I attempted to fix this by adding the not equal statement but this has not worked.....
How can I do a greater than operation but not include the equal too?
Is this is a bug in the C++ version used on MQL5? It is very frustrating.
Crazy issue.....Thanks for your help.
Chris