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

 
MakarFX #:

Thank you, Makar. I'm going to attach it to the EA and have a look at it.

 
MakarFX #:

Makar thanks Everything works just the way I wanted it to. Thank you!!!

 
MakarFX #:

I would like unwanted lines to be removed by themselves, let's say after 24 hours.

Thanks in advance!!!

 
EVGENII SHELIPOV #:

I would like unnecessary lines to be deleted by themselves, let's say after 24 hours.

Thanks in advance!!!

int OnInit()
  {
   if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
     {
      ObjectCreate(0,"Начало торговли"+TimeToString(Time[0],TIME_DATE),OBJ_VLINE,0,Time[0]+(StartTime*3600),0);
      ObjectSetInteger(0,"Начало торговли"+TimeToString(Time[0],TIME_DATE),OBJPROP_COLOR, clrBlue);
      ObjectCreate(0,"Окончание торговли"+TimeToString(Time[0],TIME_DATE),OBJ_VLINE,0,Time[0]+(StopTime*3600),0);
      ObjectSetInteger(0,"Окончание торговли"+TimeToString(Time[0],TIME_DATE),OBJPROP_COLOR, clrBlue);
     }
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   if((UseHour==1&&Hour()>=StartTime&&Hour()<=StopTime)||UseHour==0)
     {
      if(ObjectFind(0,"Начало торговли"+TimeToString(Time[1],TIME_DATE))==0)
        {
         ObjectMove(0,"Начало торговли"+TimeToString(Time[0],TIME_DATE),0,Time[0]+(StartTime*3600),0)
         ObjectMove(0,"Окончание торговли"+TimeToString(Time[0],TIME_DATE),0,Time[0]+(StopTime*3600),0)
        }
      if(CountTrade(0)==0 && CountTrade(1)==0 && TradeSignal()==0)
         SendFirsOrder(0);
      if(CountTrade(1)==0 && CountTrade(0)==0 && TradeSignal()==1)
         SendFirsOrder(1);
     }

   //-----
  }
 
Nerd Trader #:

From help:
"To ensure that you get a non-repeating sequence, use MathSrand(GetTickCount()), since GetTickCount()
has been increasing since the operating system started and will not be repeated for 49 days".

use a calculator to see how many attempts it takes to get the first repeated value (any of those previously generated) for rand()

 

From my experience - don't write Cyrillic

Opening ECN MT4

/+----------------------------------------------------------------------------+
//|    Функция открытия ордера  (c) BeerGod 2015                               |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" - текущий символ)                   |
//|    op - операция                                                           |
//|    ll - лот                                                                |
//|    sl - уровень стоп                                                       |
//|    tp - уровень тейк                                                       |
//|    mn - MagicNumber                                                        |
//+----------------------------------------------------------------------------+
//  OpenPosition(string symbol,int operation,double volume,int slippage,double stoploss,double takeprofit,string comment,int magic,color);
int OpenPosition(string sy, int op, double ll, int Slippage, int sl, int tp, string comment, int mn,color Color)
  {
   if(op == 0)  // открытие BUY
     {
      // проверяем доступность свободных средств
      if((AccountFreeMarginCheck(sy,OP_BUY,ll)<=0) || (GetLastError()==134))
        {
         Print(sy," ",ll," It is impossible to open the order Buy, not enough money.");
         return(0);
        }
      RefreshRates();

      // открываем ордер
      int ticketbuy = OrderSend(sy,OP_BUY,ll,MarketInfo(sy,MODE_ASK),Slippage,0,0,comment,mn,0,Color);
      if(ticketbuy<0)
         Print(sy," OpenPosition. OrderSend Buy fail #",GetLastError());
      else
         Print(sy," OpenPosition. OrderSend Buy successfully");

      //      Sleep (Pause);

      // модифицируем ордер (выставляем тейпрофит и стоплосс)
      if(sl !=0 || tp !=0)
        {
         //--- вычисленные значения цен SL и TP должны быть нормализованы
         double BSLoss = NormalizeDouble(MarketInfo(sy,MODE_ASK)-sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
         double BTProfit = NormalizeDouble(MarketInfo(sy,MODE_ASK)+tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
         //--- если входящие значения ноль то заменяем цену модификации на ноль
         if(sl == 0)
            BSLoss = 0;
         if(tp == 0)
            BTProfit = 0;

         bool resbuy = OrderModify(ticketbuy,OrderOpenPrice(),BSLoss,BTProfit,0,clrNONE);
         if(!resbuy)
            Print(sy," OpenPosition. OrderModify Buy fail #",GetLastError());
         else
            Print(sy," OpenPosition. OrderModify Buy successfully");
        }
     }

   if(op == 1)   // открытие Sell
     {
      // проверяем доступность свободных средств
      if((AccountFreeMarginCheck(sy,OP_SELL,ll)<=0) || (GetLastError()==134))
        {
         Print(sy," ",ll," It is impossible to open the order Sell, not enough money.");
         return(0);
        }
      RefreshRates();

      // открываем ордер
      int ticketsell = OrderSend(sy,OP_SELL,ll,MarketInfo(sy,MODE_BID),Slippage,0,0,comment,mn,0,Color);
      if(ticketsell<0)
         Print(sy," OpenPosition. OrderSend Sell fail #",GetLastError());
      else
         Print(sy," OpenPosition. OrderSend Sell successfully");

      //      Sleep (Pause);

      // модифицируем ордер (выставляем тейпрофит и стоплосс)
      if(sl !=0 || tp !=0)
        {
         //--- вычисленные значения цен SL и TP должны быть нормализованы
         double SSLoss = NormalizeDouble(MarketInfo(sy,MODE_BID)+sl*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
         double STProfit = NormalizeDouble(MarketInfo(sy,MODE_BID)-tp*MarketInfo(sy,MODE_POINT),(int)MarketInfo(sy,MODE_DIGITS));
         //--- если входящие значения ноль то заменяем цену модификации на ноль
         if(sl == 0)
            SSLoss = 0;
         if(tp == 0)
            STProfit = 0;

         bool ressell = OrderModify(ticketsell,OrderOpenPrice(),SSLoss,STProfit,0,clrNONE);
         if(!ressell)
            Print(sy," OpenPosition. OrderModify Sell fail #",GetLastError());
         else
            Print(sy," OpenPosition. OrderModify Sell successfully");
        }
     }
   return (0);
  }
//--- End ---
 

Good day to you all!

Please, advise me where you can find basic information about dynamic two-dimensional array in MQL4. First of all, I am interested in how to create it. How to use it? What functions are applicable to it?
Thank you.

 
ANDREY #:

Good day to you all!

Please, advise where you can find the basic information about dynamic two-dimensional array in MQL4. First of all, I am interested in how to create it. How to use it? What functions are applicable to it?
Thank you.

Documentation Arrays

And the dynamics are only in the first dimension. The other dimensions are static.
Объект динамического массива - Типы данных - Основы языка - Справочник MQL4
Объект динамического массива - Типы данных - Основы языка - Справочник MQL4
  • docs.mql4.com
Объект динамического массива - Типы данных - Основы языка - Справочник MQL4
 
Valeriy Yastremskiy #:

Documentation arrays

And dynamically only on the first dimension. The other dimensions are static.

CArray, and the like - you can make dynamic arrays of any dimension, changeable in any dimension.

Документация по MQL5: Стандартная библиотека / Коллекции данных
Документация по MQL5: Стандартная библиотека / Коллекции данных
  • www.mql5.com
Коллекции данных - Стандартная библиотека - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin #:

CArray, and the like - you can make dynamic arrays of any dimension, changeable in any dimension.

Thank you for your help. But you give me a link to the information about dynamic arrays in MQL5. I am still mastering MQL4, or the code from MQL5 is also suitable forMQL4 with respect to dynamic arrays ?
Thank you
.