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

 
Hello. Can you tell me if an EA has to open a position at the market price, how can I tell if an order has opened and what is its opening price?
 
awega:
Hello. Can you tell me if an EA has to open a position at the market price, how can I tell if an order has opened and what is its opening price?
https://book.mql4.com/ru/
 
How do I know the current time?
 
I need to implement a function to return a composite result from values of several types, can you tell me how to do it? Or should I just use global variables for the values of this function?
 
splxgf:
https://book.mql4.com/ru/
If you know which topic to look in
 
//+------------------------------------------------------------------+
//|                                                       10pips.mq4 |
//|                                                        fortrader |
//|                                                 www.fortrader.ru |
//+------------------------------------------------------------------+
#property copyright "fortrader"
#property link      "www.fortrader.ru"

extern int       TakeProfit_Buy = 10;
extern int       StopLoss_Buy = 5000;
extern int       TrailingStop_Buy = 5000;
extern int       TakeProfit_Sell = 10;
extern int       StopLoss_Sell = 5000;
extern int       TrailingStop_Sell = 5000;
extern double     Lots = 0.01;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
  if (Volume[0] > 1000) return(0);
// Объявляем переменные
int total, cnt;

  total=OrdersTotal();

  // Проверка средств
  if(AccountFreeMargin()<(1000*Lots))
     {
       Print("We have no money. Free Margin = ", AccountFreeMargin());   
       return(0);  
     }
  if(total<1000)
    {  
     // Открытие сделкок
       OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss_Buy*Point,Ask+TakeProfit_Buy*Point,"Покупаем",16384,0,Green);
       Sleep(10);//10 секунд
       RefreshRates();
       OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss_Sell*Point,Bid-TakeProfit_Sell*Point,"Продаем",16385,0,Red);
    }
  if(total==1000)
    {
       OrderSelect(0, SELECT_BY_POS, MODE_TRADES);
       if(OrderType()==OP_BUY)
         {
           OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss_Buy*Point,Ask+TakeProfit_Buy*Point,"Покупаем",16384,0,Green);
         }
       if(OrderType()==OP_SELL)
         {
           OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss_Sell*Point,Bid-TakeProfit_Sell*Point,"Продаем",16385,0,Red);
         }
    }   
  for(cnt=total-1;cnt>=0;cnt--)
     {
       OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
       if(OrderType()==OP_BUY)
         {
           if(TrailingStop_Buy>0)  
             {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop_Buy) // Bid - цена покупки
                 {
                   if(OrderStopLoss()<Bid-Point*TrailingStop_Buy)
                     {
                       OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop_Buy,OrderTakeProfit(),0,Green);
                       return(0);
                     }
                 }
             }
         }
       if(OrderType()==OP_SELL)
         {
           if(TrailingStop_Sell>0)  
             {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop_Sell))  // Ask - цена продажи
                 {
                   if((OrderStopLoss()>(Ask+Point*TrailingStop_Sell)) || (OrderStopLoss()==0))
                     {
                       OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop_Sell,OrderTakeProfit(),0,Red);
                       return(0);
                     }
                 }
             }
         }
  
     }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
I have a simple Expert Advisor, it opens sell or buy trades up to a certain amount and sets SL and TP (it is the amount of trades that is important to me). I have a simple Expert Advisor that just opens Sell or Buy position for a certain amount of trades, and then opens SL or TP (it is only the amount of trades that matters to me). Please advise what may be done here?
 
DOCTORS:
How do I know the current time?
TimeCurrent()
 
utyff:
I have a simple Expert Advisor, it opens sell or buy trades up to a certain amount and sets SL and TP (it is the amount of trades that is important to me). I have a simple Expert Advisor that just opens Sell or Buy position for a certain amount of trades, and then opens a Sell or Buy position for a certain amount of trades (it is the number of trades that I am interested in). Please advise what may be done here?

Increase slip and normalize prices
 
awega:
Hello. Can you tell me, if an EA has to open a position at the market price, how can I determine whether an order has opened and how to determine its opening price?
Open the help in MetaEditor, "Trading functions": OrderSend() and OrderOpenPrice() - there are ready answers to your questions.
 
utyff:
I have a simple Expert Advisor, it opens sell or buy trades up to a certain amount and sets SL and TP (it is the amount of trades that is important to me). I have a simple EA, it just opens sell or buy trades with certain amount of lots and places SL or TP (it is the amount of trades that I am interested in). Please advise what can be done here?
The first thing to do is to check the Car Registration Journal: the Expert Advisor will leave error messages there. And then according to these messages the analyze what and why. And it is desirable that you yourself learn to analyze, rather than throwing here bundles of code in the hope that others will do the same for you.
Reason: