Questions from Beginners MQL5 MT5 MetaTrader 5 - page 54

 
My older brother's here. I guess I'll go tomorrow.
 
Merkulovv_Artem:

Please advise where the mistake is. I'm getting the exact value, but I can't make the "Obem_Pozic" value to be 1.00, so I can calculate the lot for displaying, I don't want to normalize it, just gives out 4 decimal places.

I am writing in MQL4.

I'm asking about MQL4 on the appropriate forum, here it's an A.


You should use DoubleToStr() to display more accurate values on the screen.

DoubleToStr - Документация на MQL4
  • docs.mql4.com
DoubleToStr - Документация на MQL4
 
Yedelkin:

This pair is probably provided by the terminal, it just needs to be connected. If manually, then in Market Watch. And if it's a grown-up one, it should be done manually with SymbolSelect().

As soon as you have one error, others will follow. The first errors are at the bottom of the terminal. So, we should try to eliminate the first errors and then we'll see :)

Thanks!!! Very well understood and beautifully written. I do have SymbolSelect() in my EA. I posted it with the code on pg. 53, if you need it, you can see it. I checked with the help - it's correct!!! So, if this pair is provided by the terminal, what should I think?

Further, if the First in line errors are at the bottom of the terminal. Why don't the printer error messages and the terminal messages alternate - no, they are grouped together?

Maybe the terminal is not reporting the error from this function?

 
Apparently not this one!!! Or this one, but not like that. At first the program messages (printers) and the messages from the terminal really alternate, and then suddenly - and 10-12 times all of a sudden the very error 4002 comes up!!!
 
I should probably still look in the code... where else I might have an indicator
 
Dimka-novitsek: I have SymbolSelect() in my EA. I posted it with the code on page 53. 53, if you need it, you can see it.

Yes, I can see that. Let's try it this way:

ResetLastError();
if(SymbolSelect(a_symbol,true)) Print("Символ ",a_symbol," успешно выбран");
else Print("Неудача с выбором символа ",a_symbol,", error = ",_LastError);
 

Thank you!!! !!

Could you please tell me what the variable timeframe print should look like, can it be digital? I see one, I mean the number one is displayed.

///////////////////////////////////////////////////////////////////////////////////////////////////////
 
 double  iMAf( string symbol, ENUM_TIMEFRAMES timeframe, int period, int mama_shift, ENUM_MA_METHOD mama_method, int applied_pricece, int shift){
 
    Print ( " iMAfsymbol  ",symbol,"    iMAftimeframe ",timeframe,"  iMAfperiod  ",period," iMAfmama_shift  ",mama_shift ,"  iMAfmama_method ",mama_method,
    "  iMAfapplied_pricece ", applied_pricece,"  iMAfshift ",shift);
 
                     MA_handle=iMA(symbol,timeframe,periodd(period),mama_shift, mama_method,applied_pricece);Sleep(2000);
                     //--- если не удалось создать хэндл
   if(MA_handle==INVALID_HANDLE)
     {
      //--- сообщим о неудаче и выведем номер ошибки
     PrintFormat("Не удалось создать хэндл индикатора iMA для пары %s/%s, код ошибки %d",
                 symbol,
                  EnumToString(timeframe),
                  GetLastError()); ResetLastError();return (0.0);} 
                     
                    CopyBuffer( MA_handle,0,0,100,MA);
                    ArraySetAsSeries(MA,true);
                     if(shift>99) return(0);
    return( (MA[shift])); } 
                   
///////////////////////////////////////////////////////////////////////////////////////////////////////

I'm asking why. This is a function, it has a line with the prints. The second one from the top accordingly.

Here is the function call.

/////////////////////////////////////////////////////////////////////
int Distance_from_MA(string symbb)
{
 double MAMA = iMAf( symbb, periodd(TFMA), periodMA, ma_shift, ma_method, applied_price, 0);
 
 int spread = (int) MathRound(SymbolInfoInteger(symbb,SYMBOL_SPREAD));
 double point = SymbolInfoDouble(symbb,SYMBOL_POINT);
 
if(SymbolInfoInteger(symbb,SYMBOL_DIGITS) == 3 || SymbolInfoInteger(symbb,SYMBOL_DIGITS) == 5)
{spread = (int) MathRound(SymbolInfoInteger(symbb,SYMBOL_SPREAD)/10);
point = SymbolInfoDouble(symbb,SYMBOL_POINT)*10;}
 
 if(iClose(symb,TF_Price,0)+(spread*point)+(Min_Distance_from_MA*point)<=MAMA) return(-1);
 if(iClose(symb,TF_Price,0)-(Min_Distance_from_MA*point)>=MAMA) return (1);
 
 
 return(0);
} 

////////////////////////////////////////////////////////////////////

Note that I use another function in the call line. It is used to convict the timeframe. It is so because my Expert Advisor has been pyrivided from 4. I have usedcase opener in it.Later on, just in case, I added F to F4 timeframes to further use it.

///////////////////////////////////////////////////////////////////////////////////////////////  
    
   ENUM_TIMEFRAMES  periodd(int per)
  {
   switch(per)
     {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      
      default: return(PERIOD_CURRENT);
     }
  }  
  
  
  ///////////////////////////////////////////////////////////////////////////

And this is what I see

 
Dimka-novitsek: Please tell me, what should the timeframe variable print look like, can it be numeric? I see one, I mean the number one is displayed.

Well, just below in this code is used

EnumToString(timeframe), 
 
Thank you! I'll have another look.
 
Dimka-novitsek: Thank you! Let me look at it again.

I think I've figured out where the problem might be. I will describe it now.

From the picture, you can see that EA is running on M1, timeframe==1, period==140. Is it correct?

The timeframe==1 value most likely indicates that timeframe==M1. At the same time, the periodd(period) entry means periodd(140). According to the code, the periodd(140) function must return the PERIOD_CURRENT value. So it turns out that periodd(140)==M1.
And that means that the iMA call looks like this: iMA(symbol,M1,M1...) I don't know if it's acceptable when calculating iMA for the value of the second argument to coincide with the value of the third argument (i.e. for the period to coincide with the averaging period), but something tells me that this is wrong.

Reason: