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

 
novichok2018:

The message still comes up at the 12th minute.

Insert Print, at the beginning of the function where the array is filled

Print("Range = ", ArrayRange(NewsArr,1));

and show the number of values in the second dimension

 
Ilya Prozumentov:

I can tell from everything that NomNews gets into the While loop already in a state greater than 999. Then you need to find out why it happens and reset this variable somewhere.

To check this, write it at the beginning of the loop:

Yes, at the 11th minute the print is 1000.

 
Alekseu Fedotov:

Insert Print, at the beginning of the function where the array is filled

and show the number of values in the second dimension

I inserted it at the beginningof the Whileloop and got the infiniteRange = 1000. Did I insert it in the wrong place?

What is this number (or function?): datetime TimeNewsFunck(int nomf)

{

string s=NewsArr[0][nomf];

string time=StringConcatenate(StringSubstr(s,0,4),".",StringSubstr(s,5,2),".",StringSubstr(s,8,2)," ",StringSubstr(s,11,2),":",StringSubstr(s,14,4));

return((datetime)(StringToTime(time) + GMTplus*3600))

}

And where does it get the value of int nomf ? I couldn't find it.

 
novichok2018:

I inserted it at the beginningof Whileloop and got infiniteRange = 1000. Did I put it in the wrong place?

And what is this number (or function?): datetime TimeNewsFunck(int nomf)

{

string s=NewsArr[0][nomf];

string time=StringConcatenate(StringSubstr(s,0,4),".",StringSubstr(s,5,2),".",StringSubstr(s,8,2)," ",StringSubstr(s,11,2),":",StringSubstr(s,14,4));

return((datetime)(StringToTime(time) + GMTplus*3600))

}

And where does it get the value of int nomf ? I have not found it.

And then there is the function which I tried but failed to find out. May it be the source of the problem?

bool CheckInvestingNews(int &pwr,datetime &mintime)
  {

   bool CheckNews=false; pwr=0; int maxPower=0;
   if(MidleNews || HighNews)
     {
      if(TimeCurrent()-LastUpd>=Upd){Print("Investing.com News Loading...");UpdateNews();LastUpd=TimeCurrent();Comment("");}
      WindowRedraw();
      //---Draw a line on the chart news--------------------------------------------
      if(DrawNewsLines)
        {
         for(int i=0;i<NomNews;i++)
           {
            string Name=StringSubstr("NS_"+TimeToStr(TimeNewsFunck(i),TIME_MINUTES)+"_"+NewsArr[1][i]+"_"+NewsArr[3][i],0,63);
            if(NewsArr[3][i]!="")if(ObjectFind(Name)==0)continue;
            if(OnlySymbolNews && StringFind(ValStr,NewsArr[1][i])<0)continue;
            if(TimeNewsFunck(i)<TimeCurrent() && Next)continue;

            color clrf=clrNONE;
            if(HighNews && StringFind(NewsArr[2][i],"High")>=0)clrf=HighColor;
            if(MidleNews && StringFind(NewsArr[2][i],"Moderate")>=0)clrf=MidleColor;
   //         if(LowNews && StringFind(NewsArr[2][i],"Low")>=0)clrf=LowColor;

            if(clrf==clrNONE)continue;

            if(NewsArr[3][i]!="")
              {
               ObjectCreate(0,Name,OBJ_VLINE,0,TimeNewsFunck(i),0);
               ObjectSet(Name,OBJPROP_COLOR,clrf);
               ObjectSet(Name,OBJPROP_STYLE,LineStyle);
               ObjectSetInteger(0,Name,OBJPROP_WIDTH,LineWidth);
               ObjectSetInteger(0,Name,OBJPROP_BACK,true);
              }
           }
        }
      //---------------event Processing------------------------------------
      int ii;
      for(ii=0;ii<NomNews;ii++)
        {
         int power=0;
         if(HighNews && StringFind(NewsArr[2][ii],"High")>=0){ power=3; MinBefore=HighIndentBefore; MinAfter=HighIndentAfter; }
         if(MidleNews && StringFind(NewsArr[2][ii],"Moderate")>=0){ power=2; MinBefore=MidleIndentBefore; MinAfter=MidleIndentAfter; }
 //        if(LowNews && StringFind(NewsArr[2][ii],"Low")>=0){ power=1; MinBefore=LowIndentBefore; MinAfter=LowIndentAfter; }
         if(NFPNews && StringFind(NewsArr[3][ii],"Nonfarm Payrolls")>=0){ power=4; MinBefore=NFPIndentBefore; MinAfter=NFPIndentAfter; }
         if(power==0)continue;

         if(TimeCurrent()+MinBefore*60>TimeNewsFunck(ii) && TimeCurrent()-MinAfter*60<TimeNewsFunck(ii) && (!OnlySymbolNews || (OnlySymbolNews && StringFind(ValStr,NewsArr[1][ii])>=0)))
           {
            if(power>maxPower){   maxPower=power; mintime=TimeNewsFunck(ii); }
              }else{
            CheckNews=false;
           }
        }
      if(maxPower>0){ CheckNews=true; oppoz=true; }
     }
   pwr=maxPower; 
   return(CheckNews);
  }
 
novichok2018:

And then there's a function that I haven't been able to figure out, no matter how hard I've tried. Maybe that's where the problem lies?

Only the author will figure it out himself. You'd better send the code from OnTick()

 
novichok2018:

Yes, at the 11th minute it gave out print 1000.

Try replacing

while(!IsStopped())

with this line.

while(NomNews<300 && !IsStopped())
 
Ilya Prozumentov:

Excess((2*psd*usd)*((2*psd*usd)-C))/(C-1)) in the formula.

To exponentiate: ^0.5 is not *0.5

If there is not a single trade on the looked through symbol and majik, or there is not a single profit or loss, or there is only one pair (C=1), we will get the division by 0.

Before the formula itself, you should check that psd and usd are > 0, and C !=1

Profitable pairs are calculated with profit > 1, loss < 1, with profit=1 are not analyzed, i.e. 1 also has to be included somewhere in this or that group.

In your function, it would be better to first select transaction numbers matching the symbol and magic number and then check if their number has changed, if so - recalculate zn, if not - return zn (zn in this case do not zeroize and check != 0 will not be needed when printing)

Owl stops working, because it relies on variables ww and nn, and when your function works, they change and break the algorithm of the owl.

Nothing would have compiled if there had been a code design error.

I can only say thank you. This is the only place in runet where they helped me.

Now the printer generates the following "Stop_Ma_v_5.1 EURUSD,M15: == Z-count equals = -nan(ind)" . Could you please advise what it means and the code should return the number?

Code :

//+------------------------------------------------------------------+
//| Подсчёт z-вероятности. @axe44 Алексей Корольков                  |
//+------------------------------------------------------------------+
  
double Z()
  {
    zn=0;          // z-число
    psd=0;         // кол. положительных сделок
    usd=0;         // количество отрицательных сделок 
    www=0;         // боол переменная 
    nnn=0;         // боол переменная
    kolichestvo=0; // подсчёт закрытых ордеров открытых роботом
    C=0;          // C = количество чередований между отрицательными и положительными сделками
    index=OrdersHistoryTotal(); 
      if(OrdersHistoryTotal()>302) index=301; // берём не более 301 сделки
    //if(index<30) return(0);                 // берём не менее 30
    count=OrdersHistoryTotal();             // считаем от скольки 
    prom=count-index;                       // выделяем только последние сделки
    if (prom<0) prom=0;                     // исключаем ошибки
  
   for( i=prom;i<=count;i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {// далее магия
           pribul=OrderProfit(); 
           if (ww==0&&pribul>1){C++;www=1;nnn=0;}// подсчитываем смену тенденции
           if (nn==0&&pribul<1){C++;www=0;nnn=1;}// подсчитываем смену тенденции 
           if (pribul>1){psd++;}//прибыльные сделки
           if (pribul<1){usd++;}// убыточные сделки
           kolichestvo++;
           }
        }
     }
    /*
Величина Z = (A * (C — 0.5) — B)/   ((B*(B — C))/(C -1))^(1/2), где:
A = количество анализируемых сделок;
B = 2*количество прибыльных сделок * количество убыточных сделок;
C = количество чередований в выборке (чередованием считается каждая пара сделок, 
когда прибыльная сделка сменяет убыточную либо наоборот).
          */ 
            
            if(kolichestvo>30&&psd>0&&usd>0&&C!=1)
            zn=(index*(C-0.5)-2*psd*usd)  /  pow(((2*psd*usd*(2*psd*usd-C))/(C-1)),0.5);
      
     
     
   return(zn);
  }
Thank you
 
aleksandr bebishev:

Mql5 guys, can you help me make a request to close a position in a hedge account? Situation: opened BUY position, we need to close it with Sell Limit. Question: How do I correctly write a request, to close exactly chosen position, and not to open new SELL locking BUY? Please write a piece of code with comments! Thank you in advance!

Closing by one open order of another order opened at the same symbol but in opposite direction.

boolOrderCloseBy(
intticket,// number of order to close
intopposite,// number of the opposite order
colorarrow_color// colour
);

Parameters

ticket

[Unique order number of the order to be closed.

opposite

[A unique sequence number of the opposite order.

arrow_color

[The colour of the close arrow on the chart. If this parameter is not present or its value is CLR_NONE, the arrow is not shown in the chart.

Returned value

Returns true if the function succeeded or false if there was an error. To get the error information, call GetLastError().

Example:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderCloseBy(order_id,opposite_id;)
return(0);
}

P.S. This thread only parses MQL4

 
Aliaksei Karalkou:

I can only say thank you. This is the only place in runet, where they helped.

Now the printer generates the following "Stop_Ma_v_5.1 EURUSD,M15: == Z-Account Equals = -nan(ind)". Could you please advise what it means and the code should return the number?

Code :

Thank you
Nan - NaN - Not a Number - Not a Number. Try normalising the numbers in the Z-calculation
 
Aliaksei Karalkou:

The closing of one open order by another order open for the same instrument, but in the opposite direction.

boolOrderCloseBy(
intticket,// number of order to close
intopposite,// number of the opposite order
colorarrow_color// colour
);

Parameters

ticket

[A unique sequential number of the order being closed.

opposite

[A unique sequence number of the opposite order.

arrow_color

[The colour of the close arrow on the chart. If this parameter is missing or its value is CLR_NONE, the arrow is not shown in the chart.

Returned value

Returns true if the function succeeded or false if there was an error. To get the error information, call GetLastError().

Example:

if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderCloseBy(order_id,opposite_id;)
return(0);
}

P.S. This thread only parses MQL4

No. Any questions on mql4 as well as mal5 are handled here in this thread, because the main purpose was to help not only with algorithms and codes but also to facilitate migration from mql4 to mql5.