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

 
Николай Никитюк:
Hello, 2020.11.15_05:51 GMT+3. Something about my strategy tester in MT4 being too slow. It used to seem to be testing fine for three months of history on an hourly chart of GBPUSD not long. I was testing my Expert Advisor. And recently I tested my EA on GOLD,M15 for one month of history. It took me an hour and forty seven minutes to check it, but in the tester it was a day and a half. What can I do to make my strategy tester work fast? Should I write to Service Desk? Who knows what to do? I will wait for an answer. 06:04 GMT+3. Yes. I can attach the MT4 tester log.

It depends on which indicator is installed. There are indicators that not only slow down the tester, but also the whole computer hangs up.

 
SanAlex:

It depends on which indicator is installed. There are such Indicators, that not only the tester slows down, but also the whole computer hangs.

It's not waiting for an answer - time's up!

Message written:2020.11.15_05:51 GMT+3

The answer was also expected on the 15th:"I'll be waiting for an answer. 06:04 GMT+3"

strategy tester in MT4 being too slow. It used to seem to run fine on my three months of history on the GBPUSD hourly chart not long. I was testing my Expert Advisor. And recently I tested my EA on GOLD,M15 for one month of history. It took me an hour and forty seven minutes to check it, but in the tester it was a day and a half. What can I do to make my strategy tester work fast? Should I write to Service Desk? Who knows what to do? I will wait for an answer. 06:04 GMT+3. Yes. I can attach the MT4 tester log.


So if you want to help, answer quickly and on time!

P.S. I didn't have time to respond myself - I overslept.

 
Vitaly Muzichenko:

He's not waiting for an answer anymore - time's up!

Message written:2020.11.15_05:51 GMT+3

The answer was also expected on the 15th:"I'll be waiting for an answer. 06:04 GMT+3."


So, if you want to help, reply quickly and on time!

P.S. I myself have not had time to respond - slept through.

happens - what one asks and the other finds the answer.

 
Gudgeon:
Please tell me how to calculate the cube root? expression MathPow(x,1/3)=1

1/3=0 therefore one of the values must be of the double type i.e. 1/3.0 or 1.0/3 or 1.0/3.0

 
Alexey Viktorov:

1/3=0 therefore it is necessary to put one of the values into double type i.e. 1/3.0 or 1.0/3 or 1.0/3.0

Thank you!

 

Hello.

I've decided to start with an EA, for the first one, to redo it, that it would put a stop loss at breakeven.

I think everything is correct, it compiles, but it won't translate, please help.

//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Moving Average sample expert advisor"
#property strict
//#define MAGICMA  20131111
//--- Inputs
input double Lots          = 0.1;
input double MaximumRisk   = 0.02;
input double DecreaseFactor= 3;
input int    SL            = 600;
input int    Slip          = 50;
input int    MovingPeriod  = 12;
input int    MovingShift   = 6;
//extern string Trailing_Funcion   = "Main_step_tral";
//extern bool   tral               =true;
extern int    TralStop       = 40; // Растояние в пунктах, откуда начнем тралить : если цена прошла в плюс 40 пунктов, то стоп передвинется на 5 пунктов в плюсовом поле
extern int    Tral           = 5; // Шаг трала
extern int    MAGICMA        = 12345;

//+------------------------------------------------------------------+
//| Calculate open positions                                         |
//+------------------------------------------------------------------+
int CalculateCurrentOrders(string symbol)
  {
   int buys,sells;
   buys=0;
   sells=0;
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
         if(OrderType()==OP_BUY)  buys++;
         if(OrderType()==OP_SELL) sells++;
        }
     }
//--- return orders volume
   if(buys>0) return(buys);
   else       return(-sells);
  }

//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//--- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//--- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
           {
            Print("Error in history!");
            break;
           }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)
            continue;
         //---
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1)
         lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//--- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Функция выставления стоп лосс  в БУ                              |
//+------------------------------------------------------------------+
void T_SL()
{
int i=0;
for(i=0; i<OrdersTotal(); i++)
{
if((OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
if(OrderSymbol() != Symbol()) continue;
if(OrderMagicNumber()!=MAGICMA) continue;
if(OrderType()==OP_BUY)
{
if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble(TralStop*Point,Digits))
//if(OrderOpenPrice()<=(Bid-TralStop))//&&OrderOpenPrice()>OrderStopLoss())
{      
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Tral*Point,Digits),OrderTakeProfit(),0,Green);
}
}  
if(OrderType()==OP_SELL)
{
if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TralStop*Point,Digits))
//if(OrderOpenPrice()>=(Ask+TralStop))//&&OrderOpenPrice()<OrderStopLoss()) 
{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Tral*Point,Digits),OrderTakeProfit(),0,Red);
}
} 
}
}
//| Конец функции тралл стоп лосс |  
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double ma;
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//--- sell conditions
   if(Open[1]>ma && Close[1]<ma)
     {
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,Slip,NormalizeDouble(Bid+SL*Point,Digits),0,"",MAGICMA,0,clrDarkRed);
      return;
     }
//--- buy conditions
   if(Open[1]<ma && Close[1]>ma)
     {
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,Slip,NormalizeDouble(Ask-SL*Point,Digits),0,"",MAGICMA,0,clrDarkGreen);
      return;
     }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   double ma;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(Open[1]>ma && Close[1]<ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(Open[1]<ma && Close[1]>ma)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for start trall
   if (TralStop!=0) T_SL();
 //  if(tral){T_SL();}  // это строка запуска тралла
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(CalculateCurrentOrders( Symbol())==0) CheckForOpen();
   else                                  CheckForClose();
//---
  }
//+------------------------------------------------------------------+
 



double   Fibo_Level= ObjectGetDouble(
                       0,          // идентификатор графика
                       n,              // имя объекта
                       OBJPROP_LEVELVALUE,           // идентификатор свойства
                       4     // модификатор свойства
                    );

Hello!!! Can you tell me how to get the price of 61.8 Fibonacci level?

Why is there a function thatreturns a description of Fibonacci object level? If this description has no reference to the price, how can it be used from the practical point of view?)


Would the price have to be calculated by itself based on the distance between the anchor points???

Документация по MQL5: Операции с графиками / ChartID
Документация по MQL5: Операции с графиками / ChartID
  • www.mql5.com
ChartID - Операции с графиками - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Kira27:

Hello!!! Can you tell me how to get the price of 61.8 Fibonacci level?

Why is there a function thatreturns a description of Fibonacci object level? If this description has no reference to the price, how can it be used from the practical point of view?)


Would the price have to be calculated by itself by the distance between the anchor points???

Between the prices of the object coordinates is 100%. The 61.8 level is the price of level 0 plus 61.8%. This is not a charting operation.

 
Alexey Viktorov:

Between object co-ordinate prices is 100%. The 61.8 level is the price of level 0 plus 61.8%. It's not a chart operation.

Thank you!!! That's what I thought.

 

Hello. The MarketInfo() function is used in mql4 to obtain the current market information. What function should I use to get MODE_LOTSIZE, MODE_TICKVALUE and MODE_TICKSIZE not for the current moment, but according to close prices of bars in the history?

Reason: