Buy orders in history

 

Need some support with code. I want to find number of all buy orders in history for start with.

Have been looking for number of samples but they do not make sense for me as I am still in learning curve. 

Below is my sample for finding latest orders with magic number. Want to add here code for finding all buy orders in history

 

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
int   iTotal=OrdersHistoryTotal();
int   i;
int   ticket;
int   ticket2;
int   ticket3;

for(i=0;i<iTotal;i++)
{
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
   {
      if(OrderMagicNumber()==111)   
      {
      ticket=OrderTicket();
      }
      if(OrderMagicNumber()==222)
      {
      ticket2=OrderTicket();
      }
      if(OrderMagicNumber()==333)
      {
      ticket3=OrderTicket();
      }
   }
}

int total=OrdersTotal();

if(total==0)
{
   if(iTotal<=10)
   {
   OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-7*Point,Ask+7*Point,NULL,111,0,CLR_NONE);
   }
   else
   {
   OrderSend(Symbol(),OP_SELL,0.02,Bid,3,Bid+7*Point,Bid-7*Point,NULL,222,0,CLR_NONE);
      if(iTotal>=201)
      {
      OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-7*Point,Ask+7*Point,NULL,333,0,CLR_NONE);
      }
   }
}
else
{
Print("no reason to trade");
}
//----
Comment    ("\n| i | ",i,
            "\n| Total open | ",total,
            "\n| ticket | ",ticket,
            "\n| ticket2 | ",ticket2,
            "\n| ticket3 | ",ticket3);
   return(0);
  }
//+------------------------------------------------------------------+
 
elanin:

Need some support with code. I want to find number of all buy orders in history for start with.

Have been looking for number of samples but they do not make sense for me as I am still in learning curve. 

Below is my sample for finding latest orders with magic number. Want to add here code for finding all buy orders in history

So why aren't you checking what the OrderType() is ?  that will tell you if it's a Buy or Sell.
 
RaptorUK:
So why aren't you checking what the OrderType() is ?  that will tell you if it's a Buy or Sell.

Yes, that's correct. Maybe I was not clear when describing my problem. I want to code how many buy orders there have been in the past with xxx magic.
 
elanin:
Yes, that's correct. Maybe I was not clear when describing my problem. I want to code how many buy orders there have been in the past with xxx magic.

OK,  so check for . . .

int BuyCount = 0;

if(OrderType == OP_BUY && OrderMagicNumber == xxx) BuyCount++;
 
RaptorUK:

OK,  so check for . . .

 

 


perfect and thanks for support

here code with piece I missed. So now I can see how many buy or sell orders there were in history with magic number.

//----
int   iTotal=OrdersHistoryTotal();
int   i;
int   ticket;
int   ticket2;
int   ticket3;
int   buyCount=0;
int   sellCount=0;
int   buyCount2=0;

for(i=0;i<iTotal;i++)
{
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
   {
      if(OrderMagicNumber()==111)   
      {
      ticket=OrderTicket();
      }
      if(OrderMagicNumber()==222)
      {
      ticket2=OrderTicket();
      }
      if(OrderMagicNumber()==333)
      {
      ticket3=OrderTicket();
      }
      if(OrderType()==OP_BUY && OrderMagicNumber()==111)
      {
      buyCount++;
      }
      if(OrderType()==OP_SELL && OrderMagicNumber()==222)
      {
      sellCount++;
      }
      if(OrderType()==OP_BUY && OrderMagicNumber()==333)
      {
      buyCount2++;
      }
   }
}

int total=OrdersTotal();

if(total==0)
{
   if(iTotal<=10)
   {
   OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-7*Point,Ask+7*Point,NULL,111,0,CLR_NONE);
   }
   else
   {
   OrderSend(Symbol(),OP_SELL,0.02,Bid,3,Bid+7*Point,Bid-7*Point,NULL,222,0,CLR_NONE);
      if(iTotal>=201)
      {
      OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-7*Point,Ask+7*Point,NULL,333,0,CLR_NONE);
      }
   }
}
else
{
Print("no reason to trade");
}
//----
Comment    ("\n| i | ",i,
            "\n| Total open | ",total,
            "\n| ticket | ",ticket,
            "\n| ticket2 | ",ticket2,
            "\n| ticket3 | ",ticket3,
            "\n| hst buy orders with magic 111 ",buyCount,
            "\n| hst buy orders with magic 333 ",buyCount2,
            "\n| hst sell orders with magic 222 ",sellCount);
   return(0);
  }
//+------------------------------------------------------------------+

 

hope this sample will help others and save some time 

 
elanin:


perfect and thanks for support

here code with piece I missed. So now I can see how many buy or sell orders there were in history with magic number.

 

hope this sample will help others and save some time 


hope they don't do it this way.....

what good is it what you do with finding OrderTicket()

it is not needed for what you ask and the only one you comment can be every type

int total=OrdersTotal();

if(total==0)

 you can't use other system this way on your account 

if(iTotal<=10)
   {
   OrderSend(Symbol(),OP_BUY,0.01,Ask,3,Ask-7*Point,Ask+7*Point,NULL,111,0,CLR_NONE);
   }

 will fail on ECN accounts

if not ecn and 5 digit account  closeprice that small it is within the spread  .....  

make it work for 4 and 5 digit account

-------------

if you have used this system one time on your account  you have to stop it can't work again 

 
deVries:


hope they don't do it this way.....

what good is it what you do with finding OrderTicket()

it is not needed for what you ask and the only one you comment can be every type

 you can't use other system this way on your account 

 will fail on ECN accounts

if not ecn and 5 digit account  closeprice that small it is within the spread  .....  

make it work for 4 and 5 digit account

-------------

if you have used this system one time on your account  you have to stop it can't work again 


Than you for clearing some things for me as I am learning to code. It will take some time until I get done with (safe) EA code that can be used on real account
Reason: