Useful features from KimIV - page 30

 

If you're interested, check out what I've been up to in terms of fashion. I'm off to the garden to dip potatoes... I'll be there in the evening...

ZS. I've derived the value that occurs the maximum number of times in a number series.

Files:
 
KimIV писал (а) >>

If you're interested, check out what I've been up to in terms of fashion. I'm off to the garden to dip potatoes... I'll be there in the evening...

ZS. I deduced the value that occurs the maximum number of times in a number series.

Of course, interesting, thank you! We'll be testing.

 
KimIV писал (а) >>

If you're interested, check out what I've been up to in terms of fashion. I'm off to the garden to dip potatoes... I'll be there in the evening...

SZY. I've deduced the value that occurs in the numerical series the maximum number of times.

I also recommend that you add something like a margin of error (or hit interval) to calculate the mode of the real numbers, which you can adjust and thus tune the sampling accuracy.

2 Idalgo :

If you are doing statistical analysis (that's what I' m interested in at the moment), would you like to share your thoughts about its use? Feel free to create a separate thread. I would be happy to support the topic.


 
sergeev писал (а) >>
I also recommend to introduce to calculate the mode of real numbers something like an error (or another interval of hit), which can be adjusted and thus adjust the accuracy of sampling.

Formulas, drawings, explanations of how and what to do... :-) I hope you understand that there are several ways of doing what you suggest. Describe your variant.

And for the first time there is a parameter d - the accuracy of numerical values, the number of digits after the decimal point.

 

Yes, the accuracy of d values is an option, but in this case we have a number verified on an interval of 10^(-d).


// переменная exact определяет процент отклонения 
// элемента массива от требуемого числа e
// например для 40% exact=1.40; для 0% exact=1.0
int ArraySearchDouble(double& m[][], double e, double exact) 
{
    for (int i=0; i<ArrayRange(m, 0); i++) 
        if (m[i][1]<=e*exact && m[i][1]>=e/exact ) return(i);
    return(-1);
}
 
sergeev писал (а) >>

Yes, the accuracy of d values is an option, but in this case we have a number verified on the interval 10^(-d).


For float numbers, it's better to use a hardcoded value of the spread.

f1 + df > f2 > f1 - df ==> f1 == f2. Or use normalization.

Your code definitely has problems with numbers close to zero, as well as ALL negative numbers.

Revise the code.

 

Yeah, I forgot about the negative a bit, I was in a hurry.

// переменная exact определяет процент отклонения 
// элемента массива от требуемого числа e
// например для 40% exact=1.40; для 0% exact=1.0
int ArraySearchDouble(double& m[][], double e, double exact) 
{
    for (int i=0; i<ArrayRange(m, 0); i++) 
        if (MathAbs(m[i][1])<=MathAbs(e)*exact && MathAbs(m[i][1])>=MathAbs(e)/exact ) return(i);
    return(-1);
}

Or



// переменная dExact определяет величину отклонения
// значения элемента массива от требуемого числа e
// например dExact=0.055
int ArraySearchDouble2(double& m[][], double e, double dExact) 
{
    for (int i=0; i<ArrayRange(m, 0); i++) 
        if (MathAbs(m[i][1])<=MathAbs(e)+dExact && MathAbs(m[i][1])>=MathAbs(e)-dExact) return(i);
    return(-1);
}
 
Hello Igor. I am glad to follow the development of the branch. I've decided to look into your order setting function in details, or to be more precise, its block
error handling:
......
      err=GetLastError();
      if (err==128 || err==142 || err==143) {
        Sleep(1000*66);
        if (ExistOrders(sy, op, mn, ot)) {
          if (UseSound) PlaySound(NameFileSound); break;
        }
        Print("Error(",err,") set order: ",ErrorDescription(err),", try ",it);
        continue;
      }
      mp=MarketInfo(sy, MODE_POINT);
      pa=MarketInfo(sy, MODE_ASK);
      pb=MarketInfo(sy, MODE_BID);
      // Неправильные стопы
      if (err==130) {
        switch (op) {
          case OP_BUYLIMIT:
            if (pp>pa-msl*mp) pp=pa-msl*mp;
            if (sl>pp-(msl+1)*mp) sl=pp-(msl+1)*mp;
            if (tp>0 && tp<pp+(msl+1)*mp) tp=pp+(msl+1)*mp;
            break;
          case OP_BUYSTOP:
            if (pp<pa+(msl+1)*mp) pp=pa+(msl+1)*mp;
            if (sl>pp-(msl+1)*mp) sl=pp-(msl+1)*mp;
            if (tp>0 && tp<pp+(msl+1)*mp) tp=pp+(msl+1)*mp;
            break;
          case OP_SELLLIMIT:
            if (pp<pb+msl*mp) pp=pb+msl*mp;
            if (sl>0 && sl<pp+(msl+1)*mp) sl=pp+(msl+1)*mp;
            if (tp>pp-(msl+1)*mp) tp=pp-(msl+1)*mp;
            break;
          case OP_SELLSTOP:
            if (pp>pb-msl*mp) pp=pb-msl*mp;
            if (sl>0 && sl<pp+(msl+1)*mp) sl=pp+(msl+1)*mp;
            if (tp>pp-(msl+1)*mp) tp=pp-(msl+1)*mp;
            break;
        }
        Print("SetOrder(): Скорректированы ценовые уровни");
      }
      Print("Error(",err,") set order: ",ErrorDescription(err),", try ",it);
      Print("Ask=",pa,"  Bid=",pb,"  sy=",sy,"  ll=",ll,"  op=",GetNameOP(op),
            "  pp=",pp,"  sl=",sl,"  tp=",tp,"  mn=",mn);
      if (pa==0 && pb==0) Message("SetOrder(): Проверьте в обзоре рынка наличие символа "+sy);
      // Блокировка работы советника
      if (err==2 || err==64 || err==65 || err==133) {
        gbDisabled=True; break;
      }
      // Длительная пауза
      if (err==4 || err==131 || err==132) {
        Sleep(1000*300); break;
      }
      // Слишком частые запросы (8) или слишком много запросов (141)
      if (err==8 || err==141) Sleep(1000*100);
      if (err==139 || err==140 || err==148) break;
      // Ожидание освобождения подсистемы торговли
      if (err==146) while (IsTradeContextBusy()) Sleep(1000*11);
      // Обнуление даты истечения
      if (err==147) {
        ex=0; continue;
      }
      if (err!=135 && err!=138) Sleep(1000*7.7);
    }
  }
}

I have this question.

Why do you handle error 131 ( ERR_INVALID_TRADE_VOLUME: Incorrect volume) with a long pause.

Is it an error or I don't understand something.

 
ShestkoFF писал (а) >>
Hello Igor. I have been following this article with great pleasure. I have decided to examine in detail your function of order placing, or to be more precise, its error block.
error handling:

I have this question.

Why do you handle error 131 (ERR_INVALID_TRADE_VOLUME: Incorrect volume) with a long pause.

Is it an error or am I missing something?

Hello Vasily! You are absolutely right! It's my mistake due to my absent-mindedness. Thank you for pointing it out to me. Error 131 should be handled in the same way as errors 2, 64, 65 and 133, i.e. the EA should be disabled.

 
Well, I would not block it, of course. I would send the error to the top and decide what to do about it there.

If you block the EA at this point, there may be open positions left by the EA, which would be a disaster.