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

 
ANDREY:
Good day to you all!
I am testing this algorithm in MT4 tester using mql4. I need Print() function to output the Bid price in log with 5 (five) decimal places. But it would only print 4 (four) decimal places. Please tell me how to fix my mistake, if it exists.
Here is my code.
void OnTick()
{
Print("=======Bid ======= ",NormalizeDouble(Bid,Digits) );

}


At the same time, if I print using Print() the opening, and closing price of the order( by SL and TP), then Print() prints the price with 5(five) digits.
Thank you all for your help.

DoubleToString(), not NormalizeDouble()

 
Igor Makanu:

I told you I didn't like my decision (((

I'm too lazy to write again.

Google "array find repetitions" - I think you'll find something

enum EResult{Ok,AllocError};

template<typename T>
EResult GetRepeat(const T &arr[],T &ret[],uint count){
   int size=ArraySize(arr);
   if (ArrayResize(ret,size)!=size) return AllocError;
   int ii=0;
   for (int i=0;i<size;){
      T tmp=arr[i];
      uint repeatCount=1;
      while(++i<size&&arr[i]==tmp) ++repeatCount;
      if (repeatCount>=count) ret[ii++]=tmp;}
   return ArrayResize(ret,ii)==ii?Ok:AllocError;
}

void OnStart()
{
   int arr[]={1,2,4,4,4,55,55,7,7,7,7,7,8,9,77,66,66,66};
   int ret[];
   if (!GetRepeat(arr,ret,3)) ArrayPrint(ret);
} 
 
Artyom Trishkin:

DoubleToString(), not NormalizeDouble()

Thank you very much for your informative support.

 
Colleagues, if it's not too much trouble, please look into my question.
https://www.mql5.com/ru/forum/160683/page1251#comment_18219493
Specifically, how do I know the value of the minute at which the position is open?
 
Aleksey Masterov:
Specifically, how do you find the value of the minute at which a position is open?

use TimeToStruct()

https://www.mql5.com/ru/docs/dateandtime/timetostruct

 
Yes I have it on mt4
 
Aleksey Masterov:
Yes I have it on mt4

it works in MT4

 
Igor Makanu:

it works in MT4

I still don't understand how I can get the value of the minute when aposition was opened from this structure...
 
Aleksey Masterov:
I don't understand how I can get the value of minute whenposition was opened from this struct which returns trumpet...

datetime o_open = OrderOpenTime();

MqlDateTime dt_struct;

TimeToStruct( o_open, dt_struct;)

int min = dt_struct.min;

 

If you can help me understand what's wrong when trying to read indicator buffer data.

Here is the code from the EA:

      if (IsTesting())
         {
         Trend    = GlobalVariableGet(GV_tradesTrend);
         TrendUP  = iCustom(NULL,0,"Used\\# Once Trades Trend",3,0);
         TrendDN  = iCustom(NULL,0,"Used\\# Once Trades Trend",4,0);
         if (TrendUP>0) {Trend=1; GlobalVariableSet(GV_tradesTrend,1);}
         if (TrendDN>0) {Trend=-1;GlobalVariableSet(GV_tradesTrend,-1);}
         if (Trend==1)  {GlobalVariableSet(GV_Trend,1);}
         if (Trend==-1) {GlobalVariableSet(GV_Trend,-1);}
         if (Trend==0)  {GlobalVariableSet(GV_Trend,0);}
         }
      else
         {
         Trend = GetLastTrendChange();
         if (Trend==1)  {GlobalVariableSet(GV_Trend,1);}
         if (Trend==-1) {GlobalVariableSet(GV_Trend,-1);}
         if (Trend==0)  {GlobalVariableSet(GV_Trend,0);}
         }
//+----------------------------------------------------------------------------+
int GetLastTrendChange()
   {
   int   trendType=0;
   int   y=0;
   int   t=500;
   while (y<t)
      {
      if (iOpen(NULL,0,t)==y) {return(0);}
      trendType=FindTrendChange(y);
      if (trendType==1 || trendType==-1) {return(trendType);}
      y++;
      }
   return(0);
   }
//+----------------------------------------------------------------------------+
int FindTrendChange(int index)
   {
   double   trendUP,trendDN;
   int      trendType=0;
   trendUP = iCustom(NULL,0,"Used\\# Once Trades Trend",3,index);
   trendDN = iCustom(NULL,0,"Used\\# Once Trades Trend",4,index);
   if (trendUP>0) {trendType=1;}
   if (trendDN>0) {trendType=-1;}
   return (trendType);
   }
//+----------------------------------------------------------------------------+

In real and in tests searching for the last value through the function works, but the test is catastrophically slow (half year test stretches for several days).

So I decided to use swap on test and save last value to global variable - the Expert Advisor stopped seeing buffer data. And even though empty buffers are 0, for some reason EA's variables take EMPTY_VALUE values and do not change.

comm

But when I put the cursor over the buffer line in the data window, two values appear in the tooltip, and the first value is 0, for example Value 5; 0.0000; 0.8855.

I can't find it out, though I poke around in the indicator code. The search in Internet and documentation didn't help. May someone please advise why the test is so slow when I try to use this indicator?

Please help me!

Files: