Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1218

 
Pineapple88:

Fixed it, everything seems to be working!)

I transferred two MA indicators to the OnInit function.

I understand that we create only the indicator handle in the OnInit function and perform all other manipulations with the arrays in the OnTick function and check it on every tick?

Yes, we create the indicator handle in OnInit. And all other operations are implemented in OnTick.

 
Vladimir Karputov:

Yes, the indicator handle is created in OnInit. And the rest of the work is implemented in OnTick.

Got it, thanks!

 
Optimising an EA in MT5 is a necessary and useful thing. But here's the question: For what period are the best parameters for the EA operation to guarantee its breakevenness in the future? It is believed that optimization must be performed every month. But optimization guarantees that the deposit will not be lost at least within the next month?
 
BORIS GOLICIN:
Optimising an EA in MT5 is a necessary and useful thing. But here is the question: For what period are the best parameters for the EA's operation which guarantee its breakevenness in the future? It is believed that optimization must be conducted every month. But optimization guarantees that the deposit will not be lost at least within the next month?

for a guarantee to the banking industry )

 
BORIS GOLICIN:
Optimization of Expert Advisor in MT5 is useful and necessary. But here's the question: For what period the best parameters for the expert guaranty it to break-even in the future? It is believed that optimization must be performed every month. But optimization guarantees that the deposit will not be lost at least within the next month?

In my opinion, optimisation is useless. It is only good for estimating how much loss you made in a certain period and how much profit you could have made. Further, the market situation will change at any moment, and all the optimization will go down the drain. To make a strategy work longer in the automatic mode, you should not be greedy. Do not try to squeeze the maximum out of the market. The brokerage company will not let it.

 

Here's what I was able to find about optimisation on the Internet:

Suppose we have a chunk of history of 15 years (at least 10), say from 2000 to 2015. We divide this piece into the following periods: 2000-2003 is our backward test chunk, 2003-2012 is the optimization period, 2012-2015 is the forward test. After optimization we conduct the usual forward testing by selecting 10-20 most successful sets. After that we run those selected sets on a backward test. The results should be similar to those obtained in forward testing. Those sets, which passed the test, are saved for further comparison. Then we run the test against the remaining sets in the whole chunk of history and select the one that shows better results than the others. As a result, we are left with one set of settings that is the most suitable.
How do we select the sets at the first stage - the forward test? Very simple: the most important thing for us at this stage is the type of balance curve. Ideally, it should be a straight line going from the bottom left to the top right corner. That said, there's no point in looking at all the best sets in a row - they are often almost identical.

 

Good afternoon to all!

When accessing the ATR indicator handler, the first 30 seconds gives strange values.

Can't figure out what's causing it?

int ATRdefinition = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   ATRdefinition = iATR(_Symbol,_Period,14);
   if(ATRdefinition == INVALID_HANDLE)
     {
      Print("Ошибка создания Хендла");
     }

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   string signal = "";

   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

   double ATRarray[];
   ArraySetAsSeries(ATRarray,true);

   CopyBuffer(ATRdefinition,0,0,3,ATRarray);
   
   double ATRValue = NormalizeDouble(ATRarray[0],5);

   Print("ATRVALUE: ",ATRValue);
  }
Files:
ATR.png  51 kb
 
Pineapple88:

Good day all!

When accessing the ATR indicator handler, the first 30 seconds gives strange values.

I can not understand what is the reason?

Do you check if the indicator is ready?

//--- determine the number of values calculated in the indicator 
   int calculated=BarsCalculated(handle); 

(insert your handle instead of'handle')

 

It turns out that this data(402082) is not enough to calculate the indicator?

I thought that theBarsCalculated function should give an error (-1) if there is not enough data for the calculation

Files:
ATR2.png  21 kb
 
Pineapple88:

It turns out that this data(402082) is not enough to calculate the indicator?

I thought that theBarsCalculated function should give an error (-1) if there is not enough data for the calculation

It seems that the terminal continues to pump up the history - respectively, the indicator is recalculated all the time. Or, another option: in your terminal, you have set a VERY large number of bars to display on the chart and your computer is VERY weak.


Added.

Checked on MetaTrader 5 x64 build 2470 and with the "Show bars" setting of 100000 - with history long downloaded. The code worked perfectly.

Reason: