[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 286

 
kolyango:


Please help a beginner. How to write such a piece of code:

Check market orders and if there are no market orders for our financial instrument, we buy it?

It's not working!!! Help... Maybe someone has a ready-made piece of code?

//---- Проверка отрытых ордеров
void CheckOpenedOrders()
 {
  my_OrderBuy=-1;
  my_OrderSell=-1;
  for (int j = 0; j < OrdersTotal(); j++)
   {
    OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
    if (OrderSymbol() == Symbol())
     {
      if (OrderType() == OP_BUY)
       {
        my_OrderBuy = OrderTicket();
       }
       else DoTrade(1);
      if (OrderType() == OP_SELL)
       {
        my_OrderSell = OrderTicket();
       }
       else DoTrade(2);
     }
   }
 }
//----

//----
void DoTrade(int workmode)
 {
  switch (workmode)
   {
    case 1:
     {
      my_OrderBuy=OrderSend(Symbol(),OP_BUY,lots,NormalizeDouble(Ask,Digits),SlipPage,
                  0,0,NULL,0,0,Red);
     }
    break;
    
    case 2:
     {
      my_OrderSell=OrderSend(Symbol(),OP_SELL,lots,NormalizeDouble(Bid,Digits),SlipPage,
                   0,0,NULL,0,0,Blue);
     }
    break;
   }
  return;
 }
//----

 
icas:



Can you give it all in working form, i.e. with a start function and a description? It's not very clear. Thanks in advance!
 
kolyango:

Can you give it all in working form, i.e. with a start function and a description? It's not very clear. Thanks in advance!


Question. I would like to know when to open orders?

 
icas:


Question. When do I open orders?

We check the market orders and if there are no market buy orders for our financial instrument, we make a buy? This is the kind of area we need...

 
kolyango:

We check market orders and if there are no market buy orders for our financial instrument, we make a buy? This is the kind of area we need...


So we only open long positions?
 
icas:

So we only open long positions?

Yes, if there are no market buy orders for our financial instrument, then we buy!
 
kolyango:

Yes, if there are no market buy orders for our financial instrument, then buy!

//+------------------------------------------------------------------+
//|                                                      OnlyBuy.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double lots=0.1;
extern int SlipPage=3;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  for (int j = 0; j < OrdersTotal(); j++)
   {
    OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
    if (OrderSymbol() == Symbol())
     {
      if (OrderType() == OP_BUY) return(0);
       else OrderSend(Symbol(),OP_BUY,lots,NormalizeDouble(Ask,Digits),SlipPage,0,0,NULL,0,0,Red);
     }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
icas, don't embarrass yourself in front of newcomers, fix your code to the right one.
 
sergeev:
icas, don't embarrass yourself in front of newcomers, fix your code to the right one.


Where? I don't see it.

 
on the first non-buy order you will flood the account with buy orders.
Reason: