problem listing my orders

 

here is my problem, I have try to list up my orders for in case my pc shuts down during the night for exemple...

here is what I coded for the listing

tough it dosent seem to operate properly... maybe it's not on init() function I need to set these variables up. anyone haves a clue about it? I hope this is enough info too...

int init()
  {
//----
   if (OrdersTotal() != 0)
      {
         for (list=OrdersTotal()-1;list>0;list++)
            {
               OrderSelect(list, SELECT_BY_POS, MODE_TRADES);
                  {
                     tck = OrderTicket();
                     sym = OrderSymbol();
                     ty = OrderType();
                     if (sym == "GBPJPY" && ty == OP_BUY && OrderMagicNumber() == Magic1)
                        {
                           pos1 = tck;
                           stat1 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_SELL && OrderMagicNumber() == Magic1)
                        {
                           pos1 = tck;
                           stat1 = 2;
                        }
                     if (sym == "USDJPY" && ty == OP_BUY && OrderMagicNumber() == Magic1)
                        {
                           pos2 = tck;
                           stat1 = 2;
                        }
                     if (sym == "USDJPY" && ty == OP_SELL && OrderMagicNumber() == Magic1)
                        {
                           pos2 = tck;
                           stat1 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_BUY && OrderMagicNumber() == Magic2)
                        {
                           pos3 = tck;
                           stat2 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_SELL && OrderMagicNumber() == Magic2)
                        {
                           pos3 = tck;
                           stat2 = 2;
                        }
                     if (sym == "NZDJPY" && ty == OP_BUY && OrderMagicNumber() == Magic2)
                        {
                           pos4 = tck;
                           stat2 = 2;
                        }
                     if (sym == "NZDJPY" && ty == OP_SELL && OrderMagicNumber() == Magic2)
                        {
                           pos4 = tck;
                           stat2 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_BUY && OrderMagicNumber() == Magic3)
                        {
                           pos5 = tck;
                           stat3 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_SELL && OrderMagicNumber() == Magic3)
                        {
                           pos5 = tck;
                           stat3 = 2;
                        }
                     if (sym == "CHFJPY" && ty == OP_BUY && OrderMagicNumber() == Magic3)
                        {
                           pos6 = tck;
                           stat3 = 2;
                        }
                     if (sym == "CHFJPY" && ty == OP_SELL && OrderMagicNumber() == Magic3)
                        {
                           pos6 = tck;
                           stat3 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_BUY && OrderMagicNumber() == Magic4)
                        {
                           pos7 = tck;
                           stat4 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_SELL && OrderMagicNumber() == Magic4)
                        {
                           pos7 = tck;
                           stat4 = 2;
                        }
                     if (sym == "EURJPY" && ty == OP_BUY && OrderMagicNumber() == Magic4)
                        {
                           pos8 = tck;
                           stat4 = 2;
                        }
                     if (sym == "EURJPY" && ty == OP_SELL && OrderMagicNumber() == Magic4)
                        {
                           pos8 = tck;
                           stat4 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_BUY && OrderMagicNumber() == Magic5)
                        {
                           pos9 = tck;
                           stat5 = 1;
                        }
                     if (sym == "GBPJPY" && ty == OP_SELL && OrderMagicNumber() == Magic5)
                        {
                           pos9 = tck;
                           stat5 = 2;
                        }
                     if (sym == "AUDJPY" && ty == OP_BUY && OrderMagicNumber() == Magic5)
                        {
                           pos10 = tck;
                           stat5 = 2;
                        }
                     if (sym == "AUDJPY" && ty == OP_SELL && OrderMagicNumber() == Magic5)
                        {
                           pos10 = tck;
                           stat5 = 1;
                        }
                  }
            }
      }
//----
  }
 
for (list=OrdersTotal()-1;list>=0;list--)
 

like most of the time you are the man of the situation thanks alot :)

 
liquidd:

here is my problem, I have try to list up my orders for in case my pc shuts down during the night for exemple...

here is what I coded for the listing

tough it dosent seem to operate properly... maybe it's not on init() function I need to set these variables up. anyone haves a clue about it? I hope this is enough info too...


Well, great work! You have helped me to improve my knowledge about this field. Thank you so much for sharing.



__________________
<a href="http://letswatchmovies.org">watch online movies</a>

 
I'm not sure that doing that in init is valid. There are some things (history for one) that isn't setup yet during init. You might want
bool first;
init(){ first=true; }
start(){
    if (first){ first=false;
        for (list=OrdersTotal()-1;list>0;list--) if (
            OrderSelect(list, SELECT_BY_POS)           // Only my orders w/
        &&  OrderMagicNumber()  == magic.number        // my magic number
        &&  OrderSymbol()       == Symbol() ){         // and my pair.
            tck = OrderTicket();
            ...
  1. Note the testing of OrderSelect return code.
  2. You don't need the if(ordersTotal) since the loop will not do anything if there are no open orders.
  3. I don't know why you need to test the pair and magic numbers. The EA should only be concerned with its own chart and its own orders.