[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 648

 
It still doesn't work... Can you give me some more details for the dumb ones? Let's see... What should I put in front of my code? What variables? I can't call the function... Did you write several ways of solving this problem or it's just one way? I'm a sucker for this...
 
r772ra:

You can do this.....
This variant will not work correctly, because NewBar gives true only on the first tick of the bar. For correct work it is necessary to place lines FunNewBar(); if(!NewBar) return; inside condition of trade opening, and after successful opening.
 
alsu:
This variant will not work correctly, because NewBar gives true only on the first tick of the bar. To work correctly, we should place the FunNewBar(); if(!NewBar) return; line inside the condition of trade opening, and after successful opening.
Although, it is not quite correct in this way too. In short, r772ra's variant must be corrected and, better, we should use a fundamentally different approach, for example, watch the time of the last order opened in the history and compare it with the time of the current bar - it will be much more reliable.
 
alsu:
Although it will not be quite correct. In short, r772ra's variant should be corrected, and better to use a fundamentally different approach, for example, to watch the time of opening of the last order in the history and compare it with the time of the current bar - it will be much more reliable

It goes something like this.

int BarOfLastOrder(int magic)
{
   int i,ot=OrdersTotal();
   
   for(i=ot-1; i>=0; i--);
   {
      OrderSelect(i,SELECT_BY_POS);
      if(OrderMagicNumber()==magic) return(iBarShift(0,0,OrderOpenTime()));
   }
   
   return(-1);
}

int start()
{

   ........

   int bar_of_last_order = BarOfLastOrder(magic); // указать магик, который использует советник

   switch(bar_of_last_order)
   {
      case 0:
         //последний ордер открыт на текущем баре
         ...
         break;
      case -1:
         //ордеров нет
         // здесь break не ставим, если ситуация "нет ордеров" и "последний ордер открыт не на текущем баре" нужно обрабатывать одинаково
         // в противном случае написать обработку и break;
      default:
         //последний ордер открыт не на текущем баре
         ...
         break;
   }

   .........

}
 
Thank you! I'll give it a try...
 
7sintez:
Thank you! I'll give it a try...
tweaked the code
 
alsu:
tweaked the code
Aha!!! I'm going to try and do something about it now...
 

Yay!!! I made it through

{
static datetime New_Time=0;
New_Bar=false;
if(New_Time!=Time[0])
{
New_Time=Time[0];
New_Bar=true;
}
}

 
7sintez:
Thank you so much!!! Will it work if I put the signal on the minus first bar from the open?

 
Thank you all so much for all your help! The codes I haven't used yet - copied them into notepad! I'll look into them when I have the time! Thanks again and again and again Friends!
Reason: