Download MetaTrader 5

Compare the current and past price

To add comments, please log in or register
player0004
14
player0004  

Would this for loop work? 

currentask = (MarketInfo(symbol, MODE_ASK))

for(int f=market_refresh; f<=3600; f++)

      {

        if (Ask / currentask > 1)

        {

           Market = "bear";

           break;

        }

        else

        {

          RefreshRates();

          Sleep(1000);

        }

      }

I want to compare the current ask with the previous ask to set the behavior of my trade.

Keith Watford
Moderator
10541
Keith Watford  

Please use the SRC button when posting code. I have done it for you this time.

Your code will not work because Ask is the same as currentask, so the loop is pointless. You cannot get previous Ask values in MT4.

whroeder1
16555
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it

  2. You must use RefreshRates, to use any Predefined Variables after server calls and Sleep.
  3. The first iteration of the loop, Ask and currentask will always be the same. That is useless. Sleep and RefreshRates first, then check.
  4. if (Ask / currentask > 1)
    Why the divide? Why not just compare?
    if(Ask > currentask)
    Also see The == operand. - MQL4 forum
To add comments, please log in or register