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

 
natawik:

Hello all, help please!

I have a problem like this. I bought a vpc from mql5 everything is working fine, installed an expert, set up 8 charts and put an expert. And i transferred the whole thing to vpc.

I had to uninstall metatrade from my computer because it was not mine.

And now when I go in from my computer.

Everything works, the expert. It works, but I cannot see it to make any changes in the settings. How can I return the EA and schedules so that I can manage them from my computer?

Thank you!

You need to save profiles for this case. To upload it later under the UPU.

 

Who knows how to export all data from the report to exel without distortion?

if i just copy some of the data in the column "profit" is exported as date e.g. january 94 instead of 1.94

No matter how I try to save, I can't get rid of this problem.

 
законопослушный гражданин:

Who knows how to export all data from the report to exel without distortion?

if i just copy some of the data in the column "profit" is exported as date e.g. january 94 instead of 1.94

No matter how I try to save, I cannot get rid of this problem.

Before uploading, or before opening the exported file, replace the separator between integer part and fractional part in Excell with a dot.

 
законопослушный гражданин:

Who knows how to export all data from the report to exel without distortion?

if i just copy some of the data in the column "profit" is exported as date e.g. january 94 instead of 1.94

No matter how I try to save it, I cannot get rid of the problem.

So

 
SGarnov:

Maybe you should also take into account the number of stops triggered. For example, the EA will find a stop in the history, and if there are two of them, it should add them both to three or four, it all depends on the external setting "number of stop losses".

The best thing in your case, and not only in your case, but in most cases, instead of turning to the trading history with a search of closed orders, keep tickets of open orders in an array. Periodically, going through the array, check if this order was closed by a simple condition.

if(OrderCloseTime() != 0) // значит ордер закрылся…

If the order has closed, it can be selected by the ticket and checked whether it closed with a profit or not. You may also check the distance from the open position to the stop and add to this distance as much as your mother allows.

After all those manipulations, we should reset the array size to 0 and fill it anew with the ticks of the orders opened at the current moment in the loop, increasing the array size.

 
Vladislav Andruschenko:

you have to save profiles for this occasion. To upload it later under the UPU.

What if I turn off the VPN and put everything back on and turn the VPN back on and transfer all the graphics and EA to you?
There won't be any old data on you, will there?
 

Hello

Help me understand the code

Attached a piece of code that has classes and everything is working fine but

I want to connect some functions from the classes into a separate function of my own and writes errors

example

void OpenHandPosition(int tp)
   {
      string lot=0.01
      bool response = actionTrade.ManageOrderSend(tp, lt, 0, 0, 0, 0, 0);//
   }

it works like this

and this doesn't work

void OpenHandPosition(int tp)
   {

    int stopLoss   = GetStopLossPoints(size);
    int takeProfit = GetTakeProfitPoints();
    bool response = actionTrade.ManageOrderSend(tp, lt , stopLoss, takeProfit, 0, 0, 0);

   }

this function works

void StrategyTrader::DoEntryTrade(TradeDirection tradeDir)

and this one doesn't

OpenHandPosition(int tp)

help

Files:
test.mq5  21 kb
 
SGarnov:

I've come to the conclusion that it's difficult to implement, your code is much simpler, clearer and more logical, but ..... somehow doesn't add up either. The main thing is not to give up.

It seems to be OK. Try it, ask...

//+------------------------------------------------------------------+
//|                                                 SGarnov.v2.1.mq4 |
//|                                           Copyright 2020, DrMak. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, DrMak."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--- input parameters
input int      T_Profit = 2;     // Коэффициент Take Profit
input int      S_Loss   = 200;   // Уровень Stop Loss
input double   O_Lots   = 0.01;  // Лоты
input int      SL_Count = 2;     // Количество убыточных ордеров
input int      Slippage = 30;    // Проскальзывание
input int      N_Magic  = 888;   // Magic

datetime T_Start;
double sl_price,tp_price,t_profit,s_loss;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- 
   Comment("");
//--- 
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   t_profit = S_Loss*T_Profit * Point();
   tp_price = NormalizeDouble(t_profit+GetPointLoss(), Digits);
//---
   s_loss   = MathMax(S_Loss, MarketInfo(_Symbol, MODE_STOPLEVEL)) * Point();
   sl_price = NormalizeDouble(s_loss, Digits);
//---
   // Удаляем отложенный ордер после профита
   if(CountOrders(-1)==1) DeletePending();
//---
   // Проверяем серию убыточных ордеров
   if(CountOrders(-1)==1&&GetLossOrders()<SL_Count)
     {
      // Устанавливаем отложенный ордер
      SendPending();
     }
//---
   // Проверяем наличие ордеров
   if(CountOrders(-1)>0)
     {
      // Устанавливаем StopLoss/TakeProfit
      ModifyOrder();
     }
//---
   int a=(int)TimeStart();
   int b=GetLossOrders();
   int c=(int)((GetPointLoss()+t_profit)/Point);
   
   Comment("Время начала цикли: ",TimeToStr(a,TIME_SECONDS),"\n",
           "Серия StopLoss ордеров: ",b,"\n",
           "Размер TakeProfita: ",c);
  }
//+------------------------------------------------------------------+
//| Модификация ордера                                               |
//+------------------------------------------------------------------+
void ModifyOrder()
  {
   double op=0;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderStopLoss()==0)
              {
               if(OrderType()==OP_BUY)
                 {op=OrderOpenPrice();
                  if(OrderModify(OrderTicket(), OrderOpenPrice(), op-sl_price, op+tp_price, OrderExpiration()))
                    {Print("Ордер модифицирован");}
                  else
                    {Print("Ошибка модификации ордера:", GetLastError());}
                 }
               if(OrderType()==OP_SELL)
                 {op=OrderOpenPrice();
                  if(OrderModify(OrderTicket(), OrderOpenPrice(), op+sl_price, op-tp_price, OrderExpiration()))
                    {Print("Ордер модифицирован");}
                  else
                    {Print("Ошибка модификации ордера:", GetLastError());}
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
//|  0 - ордера типа BUY          1 - ордера типа SELL               |
//|  2 - ордера типа BUYLIMIT     3 - ордера типа SELLLIMIT          |
//|  4 - ордера типа BUYSTOP      5 - ордера типа SELLSTOP           |
//|  6 - ордера типа Balance     -1 - Все типы ордеров               |
//+------------------------------------------------------------------+
int CountOrders(int or_ty=-1) 
  {
   int cnt=0;
   for(int pos=OrdersTotal()-1;pos>=0;pos--)
     {
      if(OrderSelect(pos,SELECT_BY_POS)==true)
        {
         if(OrderSymbol()==_Symbol)
           {
            if(or_ty<0 || or_ty==OrderType()) cnt++;
           }
        }
     }
   return(cnt);
  }
//+------------------------------------------------------------------+
//| Установка отложенного ордера                                     |
//+------------------------------------------------------------------+
void SendPending()
  {
   double op=0;
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS)==true)
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderStopLoss() != 0)
                 {
                  op=OrderStopLoss();
                  if(OrderSend(_Symbol,OP_SELLSTOP,O_Lots,op,Slippage,0,0,NULL,N_Magic))
                    {Print("Отложенный ордер установлен");}
                  else
                    {Print("Ошибка установки отложеного одера: ", GetLastError());}
                 }
              }
            if(OrderType()==OP_SELL)
              {
               if(OrderStopLoss() != 0)
                 {
                  op=OrderStopLoss();
                  if(OrderSend(_Symbol,OP_BUYSTOP,O_Lots,op,Slippage,0,0,NULL,N_Magic))
                    {Print("Отложенный ордер установлен");}
                  else
                    {Print("Ошибка установки отложеного одера: ", GetLastError());}
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|  Возвращает пункты убытка закрытых ордеров с начала цикла        |
//+------------------------------------------------------------------+
double GetPointLoss()
  {
   double result=0,b=0,s=0;;
   int i=OrdersHistoryTotal();
   for(int pos=0; pos<i; pos++)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               if(OrderProfit()<0)
                 {
                  if(OrderCloseTime()>=TimeStart())
                    {
                     if(OrderType()==OP_BUY)
                       {
                        b+=OrderOpenPrice()-OrderClosePrice();
                       }
                     if(OrderType()==OP_SELL)
                       {
                        s+=OrderClosePrice()-OrderOpenPrice();
                       }
                    }
                 }
              }
           }
        }
     }
   return(b+s);
  }
//+------------------------------------------------------------------+
//| Удаление отложенного ордера                                      |
//+------------------------------------------------------------------+
void DeletePending()
  {
   for(int i = OrdersTotal() - 1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS)==true)
        {
         if(OrderSymbol()==_Symbol)
           {
            if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
              {
               if(OrderMagicNumber() == N_Magic)
                 {
                  if(OrderDelete(OrderTicket()))
                    {Print("Отложенный ордер удален");}
                  else
                    {Print("Ошибка удаления отложеного одера: ", GetLastError());}
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Возвращает время начала цикла                                    |
//+------------------------------------------------------------------+
datetime TimeStart()
  {
   datetime ts1=0,ts2=0;
   if(OrdersTotal()!=0)
     {
      for(int i = OrdersTotal() - 1; i >= 0; i--)
        {
         if(OrderSelect(i, SELECT_BY_POS))
           {
            if(OrderMagicNumber()!=N_Magic)
              {
               if(OrderType()==OP_BUY || OrderType()==OP_SELL)
                 {
                  if(OrderSymbol()==_Symbol)
                    {
                     if(ts1<OrderOpenTime())
                       {
                        ts1=OrderOpenTime();
                       }
                    }
                 }
              }
           }
        }
      for(int pos=0; pos<OrdersHistoryTotal(); pos++)
        {
         if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
           {
            if(OrderMagicNumber()!=N_Magic)
              {
               if(OrderType()==OP_BUY || OrderType()==OP_SELL)
                 {
                  if(OrderSymbol()==_Symbol)
                    {
                     if(ts2<OrderOpenTime())
                       {
                        ts2=OrderOpenTime();
                       }
                    }
                 }
              }
           }
        }
     }
   return(MathMax(ts1,ts2));
  }
//+------------------------------------------------------------------+
//|  Возвращает кол-во серии убыточных ордеров                       |
//+------------------------------------------------------------------+
int GetLossOrders()
  {
   int cnt=0;
   int i=OrdersHistoryTotal();
   for(int pos=0; pos<i; pos++)
     {
      if(OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY))
        {
         if((OrderSymbol()==_Symbol))
           {
            if(OrderCloseTime()>=TimeStart())
              {
               if(OrderProfit()<0) cnt++;
              }
           }
        }
     }
   return(cnt);
  }
//+------------------------------------------------------------------+
 
MakarFX:

It seems to be OK. Try it, ask...

Thanks for the help, only next week I will be able to write the correctness of the EA, today is Friday and I am not looking for market entry prices anymore.

 
natawik:
What if I turn off the VPN and put it all back on and then turn it back on again and transfer everything to you, the graphics and the expert?
There won't be any old data on you, will there?
I often encounter such problems when I set up a PC, configure the terminal, then migrate everything, keep working, change graphics, etc., and then bam, something needs to be changed.... I have to do it all over again.
Reason: