How to open multiple operarions at different prices?

 
Hi!
I'm trying to code an EA, just started a couple of days ago, and I am very new to the programming language so I'm semi-lost on pretty much everything. I'm currently trying to code a while loop that checks if the price of the market has passed the opening price of a previous (now open) BuyStop operation, and if it has, then it places a new BuyStop, otherwise it just keeps checking the price. I had no problem creating a loop that places multiple operations at different prices, but I don't know why the code doesn't work when I try to implement the "passing x price" condition. I've tried with different "If's" such as "If(Ask>OpenPrice()) or" If(Ask-OpenPrice() >0)" or similar, but it doesn't work. Could someone help me? Thanks in advance and have a great day! 
 
Thehopingnoob: , but it doesn't work. Could someone help me?
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. 2004
              When asking about code

  2. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

    Fix your broken code.

    With the information you've provided — we can only guess. And you haven't provided any useful information for that.

 
William Roeder:
  1. “Doesn't work” is meaningless — just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires — meaningless.
         How To Ask Questions The Smart Way. 2004
              When asking about code

  2. Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

    We can't see your broken code.

    Fix your broken code.

    With the information you've provided — we can only guess. And you haven't provided any useful information for that.

I see. Thank you for the advice then, I apologize.

Okay, so to put an example of what I mean, let's say I have this code:

if(OrdersTotal()==0){
         
         x=OrderSend("EURUSD",OP_BUYSTOP,0.05,1.08580,300,0,0,NULL,0,0,clrGreen);
            OrderSelect(x,SELECT_BY_TICKET);
            z=OrderOpenPrice();}
      while (OrdersTotal()<7){
               vintpips=z+0.002;
               y=OrderSend("EURUSD",OP_BUYSTOP,0.05,vintpips,300,0,0,NULL,0,0,clrGreen); 
               OrderSelect(y,SELECT_BY_TICKET);
               z=OrderOpenPrice();  }  }
            


With al the variables well defined and such. If i compile this, it works (on the timeframe I've selected) and it opens seven BUYSTOPS, each one at 20 pips from the previous one. What I want to do is alter this code so each of the operations only appears when the last one has been opened, or in other words, the first time the Ask price equals the variable "z" which is the OrderOpenPrice of the last pending BUYSTOP.

So what I have tried is writing some variables around this:

if(OrdersTotal()==0){
         
         x=OrderSend("EURUSD",OP_BUYSTOP,0.05,1.08580,300,0,0,NULL,0,0,clrGreen);
            OrderSelect(x,SELECT_BY_TICKET);
            z=OrderOpenPrice();}
      while (OrdersTotal()<7){
         if (Ask>=z){
            vintpips=z+0.002;
            y=OrderSend("EURUSD",OP_BUYSTOP,0.05,vintpips,300,0,0,NULL,0,0,clrGreen); 
            OrderSelect(y,SELECT_BY_TICKET);
            z=OrderOpenPrice();  }  }}

I first tried with "If(Ask==z)" but when It didn't work I thought maybe the timing between the Ask reaching the desired price and the "while "    checking the condition was impossible to match, so I tried with the condition seen above, so the first time the "while" could check, if the "Ask" had already reached the price and surpassed it, it would put the next "BUYSTOP", but it doesn't work. I tried adding a condition in case the error was something like the "while" freezing not knowing what to do if the price had not been reached yet, something silly like "if(Ask<z){number++}" but it has not changed anyhing either. Maybe it is just an issue of semantics, but for what I have searched and tried, the "Ask>z" should not be an issue, as both are floating variables (I think, at least I have been able to operate with both, z being a floating variable).

I hope this is more understandable now, and thanks again for the reply!

 
Please edit your post and
use the code button (Alt+S) when pasting code
 
Keith Watford:
Please edit your post and
use the code button (Alt+S) when pasting code
Done, thanks!
 
  1. Thehopingnoob: I first tried with "If(Ask==z)"

    Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  2.             z=OrderOpenPrice();}
    We have no idea what z is, or even if it is static or global. Always post all relevant code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  3.          x=OrderSend("EURUSD",OP_BUYSTOP,0.05,1.08580,300,0,0,NULL,0,0,clrGreen);

    Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  4.       while (OrdersTotal()<7){
             if (Ask>=z){

    If the if is false you have an infinite loop.

  5. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum 2013.02.15
              PositionClose is not working - MQL5 programming forum 2020.02.21
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles 24 July 2006
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles Small>1 February 2011

 
William Roeder:
  1. Doubles are rarely equal. Understand the links in:
              The == operand. - MQL4 programming forum #2 2013.06.07

  2. We have no idea what z is, or even if it is static or global. Always post all relevant code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  3. Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (strict), it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum 2012.05.20
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles 25 March 2014

  4. If the if is false you have an infinite loop.

  5. Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum 2013.02.15
              PositionClose is not working - MQL5 programming forum 2020.02.21
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles 24 July 2006
              Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles Small>1 February 2011

Okay, it has been solved, thank you!
Reason: