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

 
Artyom Trishkin:

I understand that you need to somehow indicate to the Expert Advisor the ticket of the position opened manually, which you want it to trawl.

  1. You should add to the Expert Advisor tracking of newly opened positions and if it does not have a magik, it means that it was opened manually. The Expert Advisor shall mark the opening of this position on the price and bar of its opening. The name of the object must contain a prefix with the common name of the object for all such objects, for example "manual_" and the position's ticket must also be present. As a result, name of the object can be as follows: "manual_12345678". Here: manual_ - prefix, 12345678 - position ticket.
  2. Add to the Expert Advisor OnChartEvent() and monitor the event of the mouse click on the object. Analyze the name of the object and if it contains a substring manual_, then look at the number after manual_. This number is the ticket of the position on which you have clicked.
  3. Then you need to save the found number so that it is not lost when you restart the EA/terminal/computer/world... For example, in resources or global variables of the terminal.
  4. The Expert Advisor should read this resource and take the ticket of the position to be trawled from it
  5. In the trawl cycle, you should fetch the ticket of the selected position and look for this number in the list of saved tickets. If such a ticket is found, the position with this ticket must be trawled.
  6. If the number of positions is changed, the ticket of the closed position must be checked and found in the saved list. If such a ticket exists in the list, it must be deleted from that list - the position no longer exists, and there is nothing to do with its ticket in the ticket list for trawling.
Something like this. The logic was written on a crank, so could not take into account something...


Thanks for the clarification, now I understand what I mean.

For me mql lessons recommend to set 3 (EURUSD), but liquidity of currencies is different and so is their speed. What are the figures that may be used as a reference point during normal market conditions for dollar pairs and crosses?

 
Is it possible to fill a multidimensional buffer with CopyOpen, CopyHigh, CopyLow and CopyClose? The description says that it copies to a dynamic array - but a dynamic array can be multidimensional MQL5
 
Alexandr Sokolov:
Is it possible to fill a multidimensional buffer using the CopyOpen, CopyHigh, CopyLow and CopyClose functions? The description says that it copies to a dynamic array - but a dynamic array can be multidimensional MQL5

Use a one dimensional array...

 
Alexandr Sokolov:
Is it possible to fill a multidimensional buffer using functions CopyOpen, CopyHigh, CopyLow and CopyClose? The description says that it copies into a dynamic array - but a dynamic array can be multidimensional.

If you have difficulty understanding the structures, you can use ArrayCopyRates

int  ArrayCopyRates( 
   void&     dest_array[][],    // массив, переданный по ссылке 
   string    symbol=NULL,       // инструмент 
   int       timeframe=0        // таймфрейм 
   );

If you have a good understanding of it, you'd better

CopyRates - Доступ к таймсериям и индикаторам - Справочник MQL4
CopyRates - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
Получает в массив rates_array исторические данные структуры MqlRates указанного символа-периода в указанном количестве. Отсчет элементов от стартовой позиции ведется от настоящего к прошлому, то есть стартовая позиция, равная 0, означает текущий бар. При копировании заранее неизвестного количества данных рекомендуется в качестве приемного...
 

Hello. I have tried to build an EA out of several ones, everything is working properly in the strategy tester (I checked it in visualisation mode). I tried to use a demo account and now and then I got the following problem, an order is opened and then deleted, and this happens during one hour, until the hour changes. I thought there is a condition to enter and delete the order at the same time, but the deletion is only in time, I deleted this entire block error has not disappeared. If someone is not difficult tell me where the error.

int start()
{
   // модификация до безубытка
   if (MathAbs((OrderOpenPrice()-Ask)/Point) > BUP && CountBuy() > 0)
      ModifyLoss();

   if (MathAbs((OrderOpenPrice()-Bid)/Point) > BUP && CountSell() > 0)
      ModifyLoss();
      
      
   CurrHour = TimeHour(TimeCurrent());
   
   if (CloseByTime == true && DayOfWeek() == DayEnd && CurrHour >= CloseHour)
   {
      if (CountTrades() > 0 || CountStop() > 0) CloseTrades();
   
     
   }
     

   if (DayStart == DayOfWeek() && CurrHour == StartHour && ((!SetLimits && CountStop() == 0) || (SetLimits && CountLimits() == 0)) && CountTrades() == 0)
   {
      high = iHigh(Symbol(), 0, 1);
      low  = iLow(Symbol(), 0, 1);
      spread = MarketInfo(Symbol(),MODE_SPREAD);
      
      if ((high - low)/Point <= MaxPips && spread < Maxspread)
      {
         buy  = NormalizeDouble(high + Indent*Point, Digits);
         sell = NormalizeDouble(low - Indent*Point, Digits);
        
      
         if (FixedLot > 0)
            Lots = FixedLot;
         else Lots = GetLots();

         if (UseMartingale == true)
         {
            if (AccountBalance() < abalance) 
               Lots = getlotlast();
            else abalance = AccountBalance();
         }
         
         if (!SetLimits)
         {
            tp_sell = ND(sell-spread*Point - TPP*Point);
            tp_buy  = ND(buy + spread*Point + TPP*Point);
         
            sl_sell = ND(sell + SLP*Point+spread*Point);
            sl_buy  = ND(buy-SLP*Point-spread*Point);
            
          if (iClose(NULL,1440,1) < iMA(NULL,1440,PeriodMA,0,MODE_EMA,PRICE_CLOSE,1)) 
                  OrderSendReliable(Symbol(), OP_SELLSTOP, Lots, (sell-spread*Point), Slippage, sl_sell,  tp_sell, comment, Magic, 0, Red);
                                                                         
                                                                        else
                  OrderSendReliable(Symbol(), OP_BUYSTOP,  Lots, (buy+spread*Point),  Slippage, sl_buy, tp_buy,  comment, Magic, 0, Blue);
                                                                       
         
            
         }else
         {
            tp_sell = ND(sell - MathAbs(buy-sell)*TakeProfitK);
            tp_buy  = ND(buy +  MathAbs(buy-sell)*TakeProfitK);
         
            sl_sell = ND(buy + MathAbs(buy-sell)*StopLossK);
            sl_buy  = ND(sell - MathAbs(buy-sell)*StopLossK);
         
            OrderSendReliable(Symbol(), OP_SELLLIMIT, Lots, buy,  Slippage, sl_sell, tp_sell,  comment, Magic, 0, Red);
            OrderSendReliable(Symbol(), OP_BUYLIMIT,  Lots, sell, Slippage, sl_buy,  tp_buy, comment, Magic, 0, Blue);
         }
      }
   }
   return(0);
}
 
craft11111:

Hello. I have tried to build an EA out of several ones, everything is working properly in the strategy tester (I checked it in visualisation mode). I tried to use a demo account and now and then I got the following problem, an order is opened and then deleted, and this happens during one hour, until the hour changes. I thought there is a condition to enter and delete the order at the same time, but the deletion is only in time, I deleted this entire block error has not disappeared. Please advise where the error is.

It is necessary to do overflow in a loop throughOrderSelect

int start()
{
   // модификация до безубытка
   if (MathAbs((OrderOpenPrice()-Ask)/Point) > BUP && CountBuy() > 0)
      ModifyLoss();

   if (MathAbs((OrderOpenPrice()-Bid)/Point) > BUP && CountSell() > 0)
      ModifyLoss();
      
OrderOpenPrice - Торговые функции - Справочник MQL4
OrderOpenPrice - Торговые функции - Справочник MQL4
  • docs.mql4.com
OrderOpenPrice - Торговые функции - Справочник MQL4
 

As far as I understand, when a condition occurs, a transition to the modification function takes place where just the order select is used. And I also tried to remove this piece all the same error remains, and it is not always visible what condition occurs.

void ModifyLoss()
{
   for (int trade = OrdersTotal() - 1; trade >= 0; trade--) 
   {
      OrderSelect(trade, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
      if (OrderType() == OP_BUY)
      {
         SL = ND(OrderOpenPrice());
         if (OrderStopLoss() < SL && (Ask - OrderOpenPrice())/Point>= BUP)
         {
            if (SL != ND(OrderStopLoss()))
               OrderModify(OrderTicket(), OrderOpenPrice(), SL, OrderTakeProfit(), 0);
         }
      } else
      if (OrderType() == OP_SELL)
      {
         SL = ND(OrderOpenPrice());
         if (OrderStopLoss() > SL && (OrderOpenPrice()-Bid)/Point >= BUP)
         {
            if (SL != ND(OrderStopLoss()))
                OrderModify(OrderTicket(), OrderOpenPrice(), SL, OrderTakeProfit(), 0);
         }
      }
   }
}
 
craft11111:

Hello. I have tried to build an EA out of several ones, everything is working properly in the strategy tester (I checked it in visualization mode). I tried to use a demo account and now and then I got the following problem, an order is opened and then deleted, and this happens during one hour, until the hour changes. I thought there is a condition to enter and delete the order at the same time, but the deletion is only in time, I deleted this entire block error has not disappeared. Please advise where the error is.

You have to write in the function Print(__FUNCTION__) or in Print(such-and-such block, such-and-such parameters). Observe the order in which the functions/blocks are triggered. The first one that triggered and should not have, that's where the question is then. Relying on the fact that "I have described here rather incompatible conditions for their simultaneous triggering" is not a good idea. Maybe the unit should not have triggered, but external parameters allowed it to trigger, maybe something inside the unit should not have triggered.

 

OnChartEvent() does not work in the tester.

Please show the button that can work in the tester. For example, click on which will raise the flag trade = true; click again? trade = false;

 
Ghabo:

OnChartEvent() does not work in the tester.

Please show the button that can work in the tester. For example, click on which will raise flag trade = true; click again? trade = false;

In OnTick() control the button press. You can do by condition, if it works in the tester - control in OnTick(), but in the real world this control will not be executed and will be controlled in OnChartEvent()

Reason: