Problem with this code not returning a proper value...please help.

 

Hi there,

I have a problem with this piece of code it returns only 1 value insted of the 2 values that it should...

if any one knows whats wrong with it, please help me understand how to fix it.

thanx.


here is the code (after the code I will show whats wrong) :


void highest_lowest ()
  {
  ///////////////////////
  //----
    // Open price and ticket number of lowest pending buy order found
    // (LowestBuyPrice starts at a very big number so that any order 
    // we find is lower)

    LowestBuyPriceSoFar = 999999;
   int TicketOfLowestBuy = 0;

   // Open price and ticket number of highest pending sell order found

    HighestSellPriceSoFar = 0;
   int TicketOfHighestSell = 0;

   // Loop through all open and pending orders 

   for (int iOrder=0;iOrder<OrdersTotal();iOrder++)
      {
      // Select the nth order
OrderSelect(iOrder, SELECT_BY_POS);

     // Make sure that the order applies to this EA

      if (OrderSymbol()==Symbol()&&OrderMagicNumber()==magic) 
        {
         // Different handling for buys and sells. This code looks at ALL pending 
         // orders - both stops and limits. Stating the obvious: if there are both 
         // buy limits and buy stops, then this code will always return the
         // details of a buy limit order. Vice versa for sells. And, for the avoidance
         // of doubt, buys and sells are treated independently: the lowest buy
         // could be above/below the highest sell depending on the nature of your system.

         switch (OrderType()) 
               {
            case OP_BUYSTOP:

            case OP_BUYLIMIT:

               // Is the trigger price of this buy order lower than
               // the lowest we've found so far?
               if (LowestBuyPriceSoFar > OrderOpenPrice()) 
                 {

                  LowestBuyPriceSoFar = OrderOpenPrice();

                  TicketOfLowestBuy = OrderTicket();
               }
               break;

            case OP_SELLSTOP:

            case OP_SELLLIMIT:

               // Is the trigger price of this sell order higher than
               // the highest we've found so far?

               if (HighestSellPriceSoFar < OrderOpenPrice()) 
                 {

                  HighestSellPriceSoFar = OrderOpenPrice();

                  TicketOfHighestSell = OrderTicket();
               }         
               break;
              }
          }
      }
   // TicketOfLowestBuy and TicketOfHighestSell now contain the ticket numbers
   // of the highest/lowest pending orders. Either can contain zero if there
   // are no pending buy/sell orders. If non-zero, then HighestSellPriceSoFar
   // and/or LowestBuyPriceSoFar will contain the entry price(s) of the order(s).
  
 //////////////////////// 
  }


the code properly returns the value for the lowestbuypricesofar but will not return the value for the highestsellpricesofar...

have a look at this ( I used a print function to find this problem, but dont know how to fix the issue)




if anyone knows how to fix this please help me understand whats wrong with it...

thanx

 
23510 wrote >>

Hi there,

I have a problem with this piece of code it returns only 1 value insted of the 2 values that it should...

if any one knows whats wrong with it, please help me understand how to fix it.

thanx.

here is the code (after the code I will show whats wrong) :

the code properly returns the value for the lowestbuypricesofar but will not return the value for the highestsellpricesofar...

have a look at this ( I used a print function to find this problem, but dont know how to fix the issue)

if anyone knows how to fix this please help me understand whats wrong with it...

thanx

it is yr magic no; buystop magic no is different from sellstop magic no; take out the Magic+1 and make it all Magic

 
ronaldosim:

it is yr magic no; buystop magic no is different from sellstop magic no; take out the Magic+1 and make it all Magic

ronaldosim,

thanks for the answer but if you look at the code I posted I already changed it to just magic.

here :

 if (OrderSymbol()==Symbol()&&OrderMagicNumber()==magic) 

I dont exactly see what you are referring to in the code...there is nothing there called magic+1 that I can see.

if I am missing the correct area please point it out to me.


sorry for the stupidity...but please point out to me exactly where I must do that.

thanx

 

ronaldosim,

thank you! your post gave me an idea and so i removed the magic number and substituted it with a comment and it works now!

thanx mate, your help is appreciated!!!!

 
23510 wrote >>

ronaldosim,

thank you! your post gave me an idea and so i removed the magic number and substituted it with a comment and it works now!

thanx mate, your help is appreciated!!!!

great u got an answer; but u still need to know the Magic+1 is found in yr OrderSend command, not in the code u have posted

 
ronaldosim:

great u got an answer; but u still need to know the Magic+1 is found in yr OrderSend command, not in the code u have posted

thank you yes I realized that and thats why I took it out and replaced with a comment because I need it to stay magic+1 in the ordersend.

thanx much!