Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1456

 
rex1818 position closing when price crosses MA.

In this code section

I get the following picture on the tester : the price crosses the MA and closes the position at the closing of the candle / opening of the next candle, already far from the desired closing level (MA boundary)....

The ticks are much more volatile than the average MA on the tick cloz, so the spread between ticks within which the MA value appeared is a common thing. Price is discrete, and I hope you don't confuse bid and ask. i.e. ma by bid and closing open prices are also bid, and ma by ask and prices are also ask).

Zy, you can not recalculate ma by bid or ask, but add spread and subtract, the error will be minimal.
 
Valeriy Yastremskiy #:

The ticks are volatile much more than the average MA on the tick cloz, so the spread between ticks within which the MA value appeared is a common thing. Price is discrete, and I hope you don't confuse bid and ask. i.e. ma by bid and closing open prices are also bid, and ma by ask and prices are also ask).

Zy, you can not recalculate ma by bid or ask by the way, but add spread to subtract, the error will be minimal.

Thanks for the answer!

Today I will try to figure it out taking into account your recommendations.

 
rex1818 position closing when price crosses MA.

In this code section

I get the following picture on the tester : the price crosses the MA and closes the position at the closing of the candle / opening of the next candle, already far from the desired closing level (MA boundary)....

Isn't testing by closing bars selected?

 
Alexey Viktorov #:

Isn't testing by bar closures selected?

Good afternoon!

Testing model: All ticks (.....). I understand the most accurate...

 
rex1818 #:

Good afternoon!

Testing model: All ticks (.....). I understand the most accurate...

And the Expert Advisor is not written based on the opening of a new bar?

The part of the code you have shown is not enough to assume the cause of such behaviour more accurately.

 

Thanks to everyone who responded!

Found the errors.

Now everything works as it should.

 

Can anyone advise, if the chart has a limit of 3000 bars, and we need to take the history of 2000000 bars, possible options to pull out historical data, without changing the parameter - max. bars in the window ????.


My system overloads when the array becomes 2 million indexes. I have to look for a solution to unload the history bypassing the chart.

   void SMA(const int aRatesTotal,const int aPrevCalc,const double  &aData[], double  &aMA[])
     {
      int Start=0;
      if(aPrevCalc==0)
        {
         for(int i=0;i<aRatesTotal;i++)
           {
            if(aData[i]!=0 && aData[i]!=EMPTY_VALUE)
              {
               Start=i+m_MAPeriod-1;
               break;
              }
           }
         aMA[Start]=0;
         for(int i=Start;i>Start-m_MAPeriod;i--)
           {
            aMA[Start]+=aData[i];
           }


But before that, I feed this array.


   rt=aRatesTotal;
   prv=aPrevCalc;
   for(int i=0; i<m_max_period; i++)
     {
      ArrayResize(d[i].m,rt);
      ArrayResize(d[i].f,rt);
     }

   chsma.Solve(rt,prv,aData,d[m_max_period-1].m);
It seems that the system crashes not because of one array, but because it starts creating arrays of such size.
 

Good afternoon everyone!

I want to switch from Mql4 to Mql5. Started reading the Mql5 Reference Manual. Unfortunately I understand, but not everything. Where can I find information like Kovalev's textbook on Mql4 that would start from the basics and describe in detail the features of Mql5 and most importantly that would give specific examples of coding the simplest and most common operations. That is, we need training information not for advanced users, but for beginners who need to learn the basics and moving on from them.

Thanks for your help

 
ANDREY #:

Good afternoon, everyone!

I want to switch from Mql4 to Mql5. Started reading the Mql5 Reference Manual. Unfortunately I understand, but not everything. Where can I find information like Kovalev's textbook on Mql4 that would start from the basics and describe in detail the features of Mql5 and most importantly that would give specific examples of coding the simplest and most common operations. That is, we need training information not for advanced users, but for beginners who need to learn the basics and moving on from them.

Thanks for your help

In the code base there are Expert Advisors and indicators that were originally written on MT4 and then rewritten on MT5 - you can use them for training.

In many ways the languages are similar, set yourself the task to rewrite the code that you understand on MT5 - and actively use the search on the instructions and portal - you will always find the answer, including in the articles.

 
Aleksey Vyazmikin #:

In the code base there are Expert Advisors and indicators that were originally written on MT4 and then rewritten on MT5 - you can use them for training.

In many ways the languages are similar, set yourself the task to rewrite the code you understand on MT5 - and actively use the search on the instructions and portal - you will always find the answer, including in the articles.

Thank you very much for your valuable advice. If you don't mind, please send me a link to the Expert Advisor (not indicator) which was on 4 and then became on 5 (if it is possible on the simplest), or the EA itself in 4 and then the same in 5
Started to study. I realised that trading operations for a beginner is easiest to open in the trading class STrade and I even managed to open orders and deals with the help of this class
But as soon as I conditioned the opening of an order, orders stopped opening, please tell me what I did wrong. Here is the code that opened orders when there were no conditions.

#include<Trade\Trade.mqh>
 CTrade  trade;

void OnTick()
{
MqlDateTime time_now;  
if(time_now.hour==10||time_now.hour==11&&time_now.min==0)


trade.Buy(0.1);


}

I have not yet understood this point.... When orders BAY were opened, they were closed, as I understood, by counter orders CEL. And I don't understand where the code took the information about how many pips to close the orders, because I didn't specify the size of SL and TP anywhere and I didn't specify the function of closing orders at all. I suspect that this information is written in some place of some attached file, i.e. in some class or structure. If it is so, how to find this place to make changes in the parameters of the open order?

Thanks again for your help