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.
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!!!
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.
/////////////////////////////////////////////////////////////////////
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.
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.
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.
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?
Yes, I can see that. Let's try it this way:
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.
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.
And this is what I see
Well, just below in this code is used
EnumToString(timeframe),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.