Useful features from KimIV - page 31

 
ShestkoFF писал (а) >>
Well I wouldn't block it of course. I would have passed the error up and decided what to do with it.

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

You have now answered your own question about the long pause. It is done to wait for the signal to open a position or set an order.

Thank you, Vasily, once again for having successfully led me astray. I almost rushed to fix the codes... And thank you again for bringing me back on my way :-)

 
KimIV писал (а) >>

:-) You have now answered your own question about the long pause. It is done in order to wait for the signal to open a position or set an order.

Thank you, Vasily, once again for having successfully led me astray. I almost rushed to fix the codes... And thank you again for bringing me back on my way :-)

To be honest, I don't understand the logic.
For example, we placed an order for 0.000001 lot. The server, of course, slaps us for it.
Instead of changing the lot (outside the function), we pause.
As a result of this break we may lose the signal to set an order, but we should change the lot instead of waiting.
That is why I do not agree with the pause. We should simply leave this function and pass the error code upwards and handle it there.
If we go my way, we might not miss a profitable trade! And we might even get a loss :)

PS: I'll lead you astray from the untrue path :)

 
I thought the lot calculation function should be called immediately (rather than going to the top), going to the top only after the error counter overflows
 
Prival писал (а) >>
and I thought, you need to call the function of lot calculation at once (and not to go to the top), going to the top only after the error counter overflow

Yes of course you need to call this function immediately, but if an error does occur!!!
Exit to the top I call a situation where you have to exit the function SetOrder.
I see it approximately as follows


int ticket = SetOrder(.....);

if (ticket > 0) {

// all ok

} else {

// correct logic error

}


int SetOrder(....) // returns either a ticket or an error number only with a negative sign.
{

int ticket = OrderSend(....)

if (ticket < 0) {

// correct set order errors

}

}


So I think we need to distinguish between logic errors and order setting errors. I hope I will give an example of an implementation today.
 
ShestkoFF писал (а) >>
To be honest, I don't understand the logic.

I have built the lot size calculation function in such a way that it will give an incorrect lot (zero) only if there is not enough money. In other cases, the lot is normalized and is driven within the limits between the minimum and maximum sizes. If there's not enough money, we have to wait for some position to close.

ShestkoFF wrote (a) >>
If you have ordered 0.000001 lot. Our server has surely given us a slap on the wrist.

Why did we do that? Why did we deliberately pass the wrong lot size? How can we justify this behaviour?

ShestkoFF wrote(a) >>.

We should simply leave this function and pass the error code upwards and handle it there.

What will it get us? Will we get a different lot size? Why didn't we get the right lot size right away? Give reasons. Let's analyse...
 

I just think that your function is a library function, i.e. universal, and therefore you should divide all errors into 2 categories:

  • errors which should be processed inside SetOrder function (connection errors, requotes...)
  • Errors that should be processed outside of the SetOrder function (wrong lot size, wrong stops...)

Функцию расчёта размера лота я строю таким образом, что неверный лот (ноль) она выдаст только в случае не хватки денег. В остальных случаях лот нормализуется и загоняется в рамки между минимальным и максимальным размерами. Если денег не хватает, то надо ждать, когда закроется какая-нибудь позиция.

This is the logic of your experts, other people may have different logic. That's why I would put the error with the wrong lots in the external

error checking block.

That's my vision of this case :) As I wrote above, I hope to give an example of implementation today.

 

My version of fashion:



int ModeInt(int array[])
{
   int size = ArraySize(array);
   
   if (size == 0) 
   {
      Print("Invalid parameter in function ModeInt(int array[]). It should be at least one element.");
      return(0);
   }
   
   int buffer[];
   ArrayCopy(buffer, array); 
   ArraySort(buffer);
   
   int max = 0;
   int maxValue = 0;
   
   int startIndex = 0;
   int startValue = buffer[0];
   
   for (int i = 1; i < size; i++)
   {
      if (buffer[i] > startValue)
      {
         if (max < i - startIndex)
         {
            max = i - startIndex;
            maxValue = buffer[startIndex];
         }
         
         startIndex = i;
         startValue = buffer[i];
      }
   }
   
   if (max < size - startIndex)
   {
      max = size - startIndex;
      maxValue = buffer[startIndex];
   }
   
   return (maxValue);
}
 
double ModeDouble(double array[], double interval)
{
   int size = ArraySize(array);
   
   if (size == 0) 
   {
      Print("Invalid first parameter in function ModeDouble(double array[], double interval). It should be at least one element.");
      return(0);
   }
   
   if (interval <= 0) 
   {
      Print("Invalid second parameter in function ModeDouble(double array[], double interval). It should be > 0 .");
      return(0);
   }
   
   double buffer[];
   ArrayCopy(buffer, array); 
   ArraySort(buffer);
   
   int max = 0;
   double maxValue = 0;
   
   int startIndex = 0;
   double startValue = buffer[0];
   
   double sum = startValue;
   
   for (int i = 1; i < size; i++)
   {
      if (buffer[i] >= startValue + interval)
      {
         if (max < i - startIndex)
         {
            max = i - startIndex;
            maxValue = (sum)/max;
         }
         
         startIndex = i;
         startValue = buffer[i];
         sum = 0;
      }
      sum += buffer[i];
   }
   
   if (max < size - startIndex)
   {
      max = size - startIndex;
      maxValue = (sum)/max;
   }
 
   return (maxValue);
}
 
TheXpert писал (а) >>

My version of the mod:


Dear TheXpert, your code looks very compact. Which of course is a fat plus! >> Thank you.

 
As promised, I'm posting my version of the function.
Attached is an Expert Advisor that uses the function. I have used AI Expert Advisor as a basis.
I have not had time to check the function by time. In other words, I believe that the signal should be checked again after 8 minutes.
Added generation of errors of the trade server that will allow to examine operation of the function in details and detect errors.
int errTest[] = {0, 128, 0, 142, 0, 143, 0, 4, 132};
errTest - sequence of errors generated, no error 0. This is a random sequence and there is no catch to be found in it.


I'm waiting for some criticism :)

Files:
 
ShestkoFF писал (а) >>
As promised, I'm posting my version of the function.
Attached file contains EA where this function is used. I have used AI Expert Advisor as the basis.
I have not had enough time to check how the function works by time. I.e. I believe the signal should be checked again after 8 minutes have passed.
Added generation of errors of the trade server that will allow to thoroughly study operation of the function and detect errors.
errTest - sequence of errors generated, no error 0. This is a random sequence and there is no catch to be found in it.


I'm waiting for criticism :)

I don't really care about the function, I can say one thing :), I'm not going to be original and say as always :) -- too overloaded.

As a result, the Expert Advisor has become a 32KB clean and clear code where I don't feel like messing around.


There are questions about the code.

1. If you disable the Expert Advisor, it won't work again until it is restarted. Why not make it wait for a relatively long period of time?

2. Neural network -- first of all it never outputs the signal of a flat. Secondly, how can you expect it to optimize something, if it has no threshold? By missing threshold you kill 80% of its already low efficiency (linear, though).



SZZH: Don't be offended, I'm moonlighting as a critic in this thread :) .