Useful features from KimIV - page 22

 
rid:

Now I've put a function in the comment - Comment (isCloseLastPosByStop());

Are you testing in the tester? If in the tester, then surely there may be a situation in which two or more last closed positions will not have a different OrderCloseTime().

 

I see. If several positions are closed simultaneously in the tester (according to the signal), then isCloseLastPosByStop() function may "glitch" and not work ? But online it seems to work.

Yes, - I checked it in the tester now when working with one position. Everything works correctly! Function correctly displays in Comment (isCloseLastPosByStop()) closing by Stop Loss and changes the flag in time when closing for another reason.

 
rid писал (а):
I see. If several positions are closed in the tester at the same time, then isCloseLastPosByStop() function may "glitch" and not work ?

Yes, because isCloseLastPosByStop() identifies the last closed position by the maximum closing time, which is measured in seconds. Therefore, we need more than one second to pass between the closing of multiple positions. In the tester, less than one second may pass.

rid wrote:
And online will apparently work.
There can also be glitches in the online mode, but much less often than in the tester. Even the automatic trading robot requires some time to close positions. If you have any ideas how to more reliably identify the last closed position, then I will gratefully accept them and try to modify the function.
 

Good afternoon, KimIV. I need your advice, or rather help. I need the start() function to work not tickwise, but to run every second, regardless of whether a new tick has come or not. Here is how I tried to implement this task:

int start()
  {
   if(first==true)return(0); 
   else 
   {   
      for(int j=0;j<10;j++)
         {
         RefreshRates();//обновляем котировки 

         //Код эксперта

         first=true;
         Sleep(1000);//задержка в 1 секунду
         j=0;
         }
   }
   return(0);
  }
 
StatBars писал (а):
I want the start() function to run every second, regardless of whether a new tick has arrived or not.

I've done it like this:

void start() {
  while (IsExpertEnabled() && !IsStopped()) {
    // код .............
    Sleep(1000);
  }
}
 

Thank you so much!!!! Can you still tell me if my code even works? Not in the tester... Does it work in the tester...? Or do I have to...

Void start()...

 
StatBars писал (а):
Can you also tell me if my code works at all?

I don't know... I haven't checked...

StatBars wrote (a):
Notin the tester... Will it work in real life...?

In the tester any looped stuff doesn't work. Only the ones on ticks work...

In online, your code should seem to work. At least it seems to work logically...

StatBars:

Or you have to...

Void start()...

No, it doesn't have to. Just why declare a typed function if it does not return any value, and if it does, that value is not used in any way?
 

I see. Thank you again.

 
KimIV:
. If you have any ideas how to more reliably identify the last closed position, I will gratefully accept them and try to redesign the function.

Thank you for your kind offer. Unfortunately, good ideas don't often (alas...) pop into my head! Not so long ago, for example, I noticed that your functions make almost no use of the "component" - OrderComment

However, perhaps, application of this function will give you new ideas (to the delight of all present).

For example, if (OrderComment()==" [sl]" && .... - might broaden the range of tasks you perform!

//---------------------------------------------------------------------------------

"More functions, - good and different!" (c)

 
rid:
KimIV:
. If you have any ideas how to more reliably identify the last closed position, I will gratefully accept them and try to revise the function.

For example, like if(OrderComment()==" [sl]" && .... - might expand the range of tasks to be performed!

rid, you suggested a way to identify the stop triggering by the entry in the order comments. Thank you, but there may be other entries besides [sl] in comments.

I solve the same problem by comparing the closing price with the stop price.

Reason: