Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 175

 
Forexman77:

The EA exits on 33 bars after a trade:

In the real and in the tester it exited on 43 bars. I tried to set the exit parameters on the fifth bar, all is normal. In your opinion, what may be the problem?


Maybe if (condition) was executed several times (once more at 10 bars, for example) and this execution delayed the life time?

 
ALXIMIKS:


Maybe if (condition) was executed several times (once more at 10 bars for example) ? and this execution delayed the life time

One trade: entry 15:37, exit 16:19. Exit on bar 41, to be more correct.
 
Forexman77:
One trade: entry 15:37, exit 16:19. Exit at 41 bars, to be more correct.


And if we replace it with iBarShift I wonder if the error will remain ??? Maybe missing bars in the history (surely there are no holes?) ?

Enter after the condition is fulfilled, count the open bars, see how many of them really opened, because referring to the time is not very correct.

 
ALXIMIKS:


If we replace it with iBarShift I wonder if the error will remain? Maybe the bars are missing in the history (surely there are no holes?) ?

After the condition is fulfilled, enter an open bar count and see how many bars are really open, because referring to time does not seem right

Should the code be like this?

static datetime t;
datetime s=Time[33]>t;

if (условие)
    {
      Opn_B = true; 
      t=Time[0];
      int shif= iBarShift(Symbol(),PERIOD_M1,t,false);
      minimum = iLow(Symbol(),Period(),0);
      }
if (iBarShift(Symbol(),PERIOD_M1,s,false)) 
    {                                      
     Cls_B=true;              
    }

This kind of code will lock the Expert Advisor.

 

Hello, can you please help me make the alert go through once per bar on each line, not just on the first,

I have limited the number of alerts by time, but I do not understand how to make a buffer for one bar

 datetime LastAlertTime = 0;
int start()
  {

  string namesymb=Symbol();
  string tf=Period();

       for(int i = ObjectsTotal()-1; i >= 0; i--)
      {
         string name = ObjectName(i);
         
         if(ObjectType(name) == OBJ_TREND)
         {
            double value = ObjectGetValueByShift(name, 0);                    
             if(Bid <= value + Point && Bid >= value - Point)          
            {
            if (LastAlertTime < Time[0]){
            LastAlertTime = Time[0];
            
               Alert(namesymb,"  M",tf,"   ",name);
             }
                Comment("\n\n Alert running \n ", TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS),"\n\n M",tf,"   ",name); 
            } 
         }      
}
 
Forexman77:

The EA exits on 33 bars after a trade:

In the real and in the tester it exited on 43 bars. I tried to set the exit parameters on the fifth bar, all is normal. What do you think the problem may be?


Let's start with a clear head.

The time of flag Opn_B = true does not mean anything, because the order may not open at the same second.

You can use the opening time of the order OrderOpenTime, or you can assign to the variable t the value of the time after the successful opening.

Next: you have used

minimum = iLow(Symbol(),Period(),0);

1) Do you need iLow, or would it be better to use just Low, if you use the same currency and timeframe?

2) Symbol() and Period() values are better to be put into variables when used repeatedly. Everything affects the performance - get used to it.

The minute chart - if for a minute there wasn't a single tick - a new bar is not drawn (may be a trick).

And what about iBarShift?

static datetime t;

if (условие)
      {
      Opn_B = true; 
      t=Time[0];
      minimum = iLow(Symbol(),Period(),0);
      }
if (iBarShift(Symbol(),1,t,false)>33) 
          {                                      
          Cls_B=true;              
          }

The most adequate at the moment seems to be

if ((TimeCurrent-t)/60)>33) Cls_B=true;
 
oleksaz:

Hello, can you please help me make the alert go through once per bar on each line, not just on the first,

I have limited the number of alerts by time, but I do not understand how to buffer for one bar

string namesymb=Symbol();
string tf=Period();

Is it worth re-valuing variables at every tick?

Does string tf = Period() affect the performance for 1000000 loop runs or is int tf = Period() more correct? I don't know myself.

 if(Bid <= value + Point && Bid >= value - Point)  

Is this condition correct? And what if the loop has 4 peaks?

if (LastAlertTime < Time[0])
LastAlertTime = Time[0];
          

Here we have one more issue. That is, if the condition for the first line holds, it will be obviously false for the second and the alert will not pop up,

It won't even pop up on the next tick, because the opening time of the candle will change only with the arrival of a new one.

 
ALXIMIKS:


The most appropriate option at the moment seems to be


Sorry, but trying to calculate the number of bars by time is a very inadequate approach.
 
ALXIMIKS:

Is it worth re-recoding the variables at every tick?

Does string tf = Period() affect performance in 1000000 loop runs, or is int tf = Period() more correct? I don't know myself.

Is this condition correct? And what if the loop has 4 peaks?

Here we have one more issue. That is, if the condition for the first line holds, it will be obviously false for the second and the alert will not pop up,

It will not even pop up on the next tick, because the opening time of the candle will only change with the arrival of a new one.


int start()
  {
string scrdate,nametf;

        if (Period()==PERIOD_M1)  nametf="9_M1";
        if (Period()==PERIOD_M5)  nametf="8_M5";
        if (Period()==PERIOD_M15) nametf="7_M15";
        if (Period()==PERIOD_M30) nametf="6_M30";
        if (Period()==PERIOD_H1)  nametf="5_H1";
        if (Period()==PERIOD_H4)  nametf="4_H4";
        if (Period()==PERIOD_D1)  nametf="3_D1";
        if (Period()==PERIOD_W1)  nametf="2_W1";
        if (Period()==PERIOD_MN1) nametf="1_Monthly";
/////////////////  
       for(int i = ObjectsTotal()-1; i >= 0; i--)//мониторим все объекты
      {
         string name = ObjectName(i);//имя объектов берем из i переменной
         
         scrdate=StringConcatenate(Symbol()," ",TimeToStr(TimeCurrent(), TIME_DATE),"_",Hour(),".",Minute()," ",nametf," ",".jpg");//,name

         if(ObjectType(name) == OBJ_TREND)//отбираем тип по имени 
         {
            double value = ObjectGetValueByShift(name, 0);//функция для объектов
            
            Comment("\n\n Alert running \n ", TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS),"\n\n M",Period(),"   ",name);           
            
             if(Bid <= value + Point && Bid >= value - Point)
             
            {
            if (LastAlertTime < Time[0]){
            LastAlertTime = Time[0];
            
               Alert(Symbol(),"  M",Period(),"   ",name);
               /////////////////////////////////////////////////
               WindowScreenShot(scrdate,1920,1200,0,-1,-1);
               ////////////////////////////////////////////////////////
             }               
            }
         }
}
   return(0);
  }

1. removed

2. i agree if the gap is not a signal (it should be) no signal -> no price -> no trade

3. this is what I said above, but what to do

PS thanks for the reply

 
Integer:

Sorry, but trying to count the number of bars by time is a very inadequate approach.


I understand time use is not very good in terms of performance + we need to check for weekends (Saturday, Sunday), other options?

If we count the number of bars. problems :

1) there was no tick, new bar has not formed at all although its time has come (on m1)

2) connection interruption - the counter of new bars is lying