Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1308

 
Alexandr Sokolov:
Where do I find out the order expiry time in the strategy tester? The columns tab does not have it
How do you set the expiry time?
 
MakarFX:
How do you set the expiry time?
void Open_Order(ENUM_ORDER_TYPE  Type,
                double           price,
                double           sl_price,
                double           tp_price,
                datetime         close)
  {
   
   MqlTradeRequest  request;
   MqlTradeResult   result;
   
   ZeroMemory(request);
   ZeroMemory(result);
   
   request.action        = TRADE_ACTION_PENDING;
   request.magic         = id_number;
   request.symbol        = _Symbol;
   request.volume        = volume;
   request.price         = price;
   request.sl            = sl_price;
   request.tp            = tp_price;
   request.deviation     = slippage;
   request.type          = Type;
   request.type_filling  = ORDER_FILLING_FOK;
   request.type_time     = ORDER_TIME_SPECIFIED;
   request.expiration    = close;
   
   if(!OrderSend(request,result)) Print("Error - ",result.retcode);
   
  }


 
Alexandr Sokolov:


Add in a comment on the warrant, I don't see any other options(
 
MakarFX:
Add to the order comment, I don't see any other options(

Thank you

 
This is my first comment on the forum and I'm not particularly familiar with the community, so don't throw too many tomatoes at me. To the point. When I was writing my EA I faced with problem that OrdersTotal() works (which makes sense) for all open orders and in case of setting conditions for "one order closed, the next one opened" I was surprised to find out that even if I set masters in conditions and duplicate code, two or more EAs on open charts on my account don't let each other work simultaneously (until one order is closed, another will not open). I searched a lot of places on the subject - I got a lot of solutions and as I understand it is elementary, but in all cases, nothing worked. What condition should I set when opening and/or closing "if... (...) " to uniqueize OrdersTotal only for a specific EA which is attached and the other one (its OrdersTotal) would not be related in any way and keep its own count of all orders. Thank you.
 
Порт-моне тв:
This is my first comment on the forum, I'm not particularly familiar with the community, so don't throw tomatoes at me. To the point. When I was writing my EA I faced with problem that OrdersTotal() works (which makes sense) for all open orders and I was surprised to find out that even if I set a master in conditions and copy code, two or more EAs on open charts at the same time do not let each other work (until one order is closed, the next one will not open). I searched a lot of places on the subject - I got a lot of solutions and as I understand it is elementary, but in all cases, nothing worked. What condition should I set when opening and/or closing "if... (...) " to uniqueize OrdersTotal only for a specific EA which is attached, and the other one (its OrdersTotal) would not be related in any way and keep its own count of all orders. Thank you.

Attach your code and you will be pointed out the errors

 
//+------------------------------------------------------------------+
//| sova_2bars.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp.
#property link "https://www.mql5.com"
#property version "1.00"
#property strict

extern int Magic = 6477;
extern double Lot = 0.01;
extern int Slippage = 3;
extern int TakeProfit = 1600;
extern int StopLoss = 800;
extern int Experation = 0;

double Openone, //opening price of the first candle
Opentwo, //opening price of the second candle
Closeone, //close price of the first candle
Closetwo, //the scene of the second candle
Lowone, //first candle's minimum price
Lowtwo, //first candle's price
Lowthree, //the scene of the third candle's minimum
Openthree, //open price of a third candle
Closethree, //close price of the third candle
CloseOrder, //close order
Highone, //maximal price of the first candle
Hightwo, //the price maximum of the second candle
Highhree, //the price maximum of the second candle
Highfour, //the price is the maximum of the second candle
Highfive, //price of a maximum of a second candle
Highsix, //price of the maximal second candle.
Highseven, //price of the maximum second candle
Highheight, //price of a maximum of a second candle
Lowfour, //the price of the fourth candle's minimum
Lowfive, //first price of a fifth candle
Lowsix, //the scene of a sixth candle's minimum
Lowseven, //the scene of a minimum of a seventh candle
Loweight, //the scene of the eighth candle's minimum
Closefour, //the closing price of the fourth candle
Openfour,
Low15,
Low25,
SLbuy, TPbuy, SLsell, TPsell, //open price of the fourth candle
OrderOpenPrice;
int ticket, ticketclose;

//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- determining prices of the necessary bars
Openone = NormalizeDouble(iOpen(Symbol(), Period(), 0), Digits);
Highone = NormalizeDouble(iHigh(Symbol(), Period(), 0), Digits);
Hightwo = NormalizeDouble(iHigh(Symbol(), Period(), 1), Digits);
Highthree = NormalizeDouble(iHigh(Symbol(), Period(), 2), Digits);
Highfour = NormalizeDouble(iHigh(Symbol(), Period(), 3), Digits);
Highfive = NormalizeDouble(iHigh(Symbol(), Period(), 4), Digits);
Highsix = NormalizeDouble(iHigh(Symbol(), Period(), 5), Digits);
Highseven = NormalizeDouble(iHigh(Symbol(), Period(), 6), Digits);
Higheight = NormalizeDouble(iHigh(Symbol(), Period(), 7), Digits);
Opentwo = NormalizeDouble(iOpen(Symbol(), Period(), 1), Digits);
Openthree = NormalizeDouble(iOpen(Symbol(), Period(), 2), Digits);
Openfour = NormalizeDouble(iOpen(Symbol(), Period(), 3), Digits);
Closeone = NormalizeDouble(iClose(Symbol(), Period(), 0), Digits);
Closetwo = NormalizeDouble(iClose(Symbol(), Period(), 1), Digits);
Closethree = NormalizeDouble(iClose(Symbol(), Period(), 2), Digits);
Closefour = NormalizeDouble(iClose(Symbol(), Period(), 3), Digits);
Lowone = NormalizeDouble(iLow(Symbol(), Period(), 0), Digits);
Lowtwo = NormalizeDouble(iLow(Symbol(), Period(), 1), Digits);
Lowthree = NormalizeDouble(iLow(Symbol(), Period(), 2), Digits);
Lowfour = NormalizeDouble(iLow(Symbol(), Period(), 3), Digits);
Lowfive = NormalizeDouble(iLow(Symbol(), Period(), 4), Digits);
Lowsix = NormalizeDouble(iLow(Symbol(), Period(), 5), Digits);
Lowseven = NormalizeDouble(iLow(Symbol(), Period(), 6), Digits);
Low15 = NormalizeDouble(iLow(Symbol(), Period(), 14), Digits);
Low25 = NormalizeDouble(iLow(Symbol(), Period(), 24), Digits);

//----индикатор - условия--------------------------------------


double BigTrand = iMA(NULL, 0,50,0,MODE_SMA, PRICE_CLOSE, 1);
double SmallTrand = iMA(NULL, 0,5,0,MODE_SMA, PRICE_CLOSE, 1);
double LowerBB = iBands(_Symbol,_Period,17,1,0,PRICE_CLOSE,MODE_LOWER,1);
double UpperBB = iBands(_Symbol,_Period,17,1,0,PRICE_CLOSE,MODE_UPPER,1);
double MiddleBB = iBands(_Symbol,_Period,17,1,0,PRICE_CLOSE,MODE_MAIN,1);
double Bears = iBearsPower(_Symbol,_Period, 5, PRICE_CLOSE,0);
double Bulls = iBullsPower(_Symbol,_Period, 5, PRICE_CLOSE,0);
double Parab = iSAR(_Symbol,_Period,0.002, 1, 0);

SLbuy = NormalizeDouble(Ask - StopLoss*Point, 5);
TPbuy = NormalizeDouble(Ask + TakeProfit*Point, 5);
SLsell = NormalizeDouble(Bid + StopLoss*Point, 5);
TPsell = NormalizeDouble(Bid - TakeProfit*Point, 5);

//-------------функции---------------------------------------

if ( Ask>0 && Bid >0)
{

if (OrdersTotal()<1)
if (Close[1]>Open[1])
if(Bears < -0.00035 && MiddleBB > Ask)
{
ticket = OrderSend(Symbol(),OP_BUY, Lot, Ask, Slippage, SLbuy, TPbuy, "open buy order", Magic, 0, Blue)
}
if(OrdersTotal()==1)
if(Bulls > 0.00035 && MiddleBB < Ask && Bears > 0 && Opentwo < Closetwo && Openthree < Closethree && BigTrand < Ask)
CloseBuyPositions1();
}





//---- end of function
}
//---------------------------------------------------------------------
void CloseBuyPositions1()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS,MODE_TRADES);
string CurrencyPair=OrderSymbol();
if(_Symbol==CurrencyPair)
if(OrderType()==OP_BUY)
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3, NULL);
}
}
}




 
 int OrderOfSymbol=CounterOrderTradeType(-1);
 
//-------------функции---------------------------------------

if ( Ask>0 && Bid >0)
   {

 if (OrderOfSymbol<1)
    if (Close[1]>Open[1])
    if(Bears < -0.00035 && MiddleBB > Ask)
         {
    ticket = OrderSend(Symbol(),OP_BUY, Lot, Ask, Slippage, SLbuy, TPbuy, "открыт ордер на покупку", Magic, 0, Blue);
         }
         
   
if (OrderOfSymbol==1)
   if(Bulls > 0.00035 && MiddleBB < Ask && Bears > 0 && Opentwo < Closetwo && Openthree < Closethree && BigTrand < Ask)
    CloseBuyPositions1();
   } 
//+------------------------------------------------------------------+
//| Подсчет ордеров потекущему символу                               |
//+------------------------------------------------------------------+
int CounterOrderTradeType(ENUM_ORDER_TYPE order_type)
   {
   int cnt=0;
   //----
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
      {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)==false) continue;
      if(OrderSymbol()!=_Symbol) continue;
      if(order_type == OrderType() || order_type == -1) cnt++;
      }
   //----
   return(cnt);
   }
 
Порт-моне тв:
//+------------------------------------------------------------------+
//| sova_2bars.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+

OrdersTotal() returns the total amount of all positions and orders in Metatrader 4

   for(int i = OrdersTotal() - 1; i >= 0; i--)
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         if(OrderMagicNumber() == iMagicNumber)
            if(OrderSymbol() == Symbol())
              {

               }

This way you can separate orders for a MedgX and a symbol...

 

@MakarFX,thank you.... I get these errors when compiling

'CounterOrderTradeType' - function not defined test for many expt trade.mq4 48 19

'CounterOrderTradeType' - function declarations are allowed on global, namespace or class scope only test for many expt trade.mq4 141 5


MakarFX
MakarFX
  • www.mql5.com
Добавил тему Окно модификации Доброго времени суток. В терминале, если я дважды щелкаю мышью на линию ордера, то открывается окно модификации. Но если на линии находится цена открытия одного ордера и тейк профит другого, то открывается последний измененный ордер. Уважаемые Профи Добавил тему Нужен индикатор. Кто может написать такое? Я уже...