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

 
Hello! Please write why in the strategy tester does not open trades, writes in the log error: (2015.07.13 00:22:39.218 TestGenerator: unmatched data error (high value 1.31150 at 2013.07.11 05:00 is not reached from the lowest timeframe, high price 1.31140 mismatches) quotes updated. Here is the code of the Expert Advisor:
int ticket;
int init;

int start()
{

int bars0;
int bars1;
int bars2;
int bars3;
int   stoploss=50; 
int   takeprofit=30;
int       slipage=2;

//-------------------------------------------------------------------+
  
  if ( OrdersTotal()<1 &&  Open[bars0]<Close[bars0] && Open[bars1]<Close[bars1] )
      if (  Open[bars2]>Close[bars2]&& Open[bars3]>Close[bars3] )
      if(V1()==true) 
     
       ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,slipage,Ask-stoploss*Point,Ask+takeprofit*Point,"",123,0,Red);
     
//-------------------------------------------------------------------+ 
    if ( OrdersTotal()<1 &&  Open[bars0]>Close[bars0] && Open[bars1]>Close[bars1]&& Open[bars2]<Close[bars2])
     if (  Open[bars2]<Close[bars2]&& Open[bars3]<Close[bars3] )
      if(V2()==true) 
     
       ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,slipage,Bid+stoploss*Point,Bid-takeprofit*Point,"",123,0,Red);
      
    
         
//-------------------------------------------------------------------+                    
 return;}
//+------------------------------------------------------------------+
bool V1( ){
  int      i, k=OrdersTotal();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
     if (OrderType()==OP_BUY) {
      return(false);
   }
  }    
 }
 return(true); 
}

bool V2( ){
  int      i, k=OrdersTotal();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
     if(OrderType()==OP_SELL) {
      return(false);
   }
  }
 }
 return(true); 
}

)
 
rylay:
Hello! Please write why in the Strategy Tester does not open trades, writes in the log error: (2015.07.13 00:22:39.218 TestGenerator: unmatched data error (high value 1.31150 at 2013.07.11 05:00 is not reached from the lowest timeframe, high price 1.31140 mismatches) quotes updated. Here is the code of the Expert Advisor:
)

Regarding the mentioned tester error, this will always be the case when testing on ticks. The quotes history in MT4 is not perfect, there are always mismatches.

The code is full of errors. Variables are not initialized, the start function doesn't understand what it returns, there is no check of trading functions execution, so please fix it.

Add #property strict to the beginning of the code.

And since we have created two functions for defining order types, why not integrate the counter of orders of each type and write if ( OrdersBuy<1...), if ( OrdersSell<1...) instead of comparing if( OrdersTotal()<1...)? It would be more correct.

 

Please advise how to open only one trade in conditions of one bar, if the trade takes place inside the bar, but at the time of closing the signal to open appears immediately on the same bar.

In other words - the bar gave a signal to open an order. It was opened and a short take was triggered. The deal has been closed but the EA closes the first one and immediately opens the second one with the exact same order because we still have the condition to open it within the same bar. I need to open only one position on one bar. And to open the next trade we should wait for the opening of another bar.

 
Poinson:

Please advise how to open only one trade in conditions of one bar, if the trade takes place inside the bar, but at the time of closing the signal to open appears immediately on the same bar.

In other words - the bar gave a signal to open an order. It was opened and a short take was triggered. The deal has been closed but the EA closes the first one and immediately opens the second one with the exact same order because we still have the condition to open it within the same bar. I need to open only one position on one bar. And we wait for the opening of another bar to open the next trade.

The _already open = false;

if (isNewBar()){ _already opened = false;}

if (!OrderSend(...) ) { /* error handling */; } else { _already opened = true; }

isNewBar() - standard, as it is in the articles, using static datetime date = Time[0];

if (_already opened) { return; //does not send the warrant }

 
evillive:

Regarding the tester error mentioned, this will always be the case when testing on ticks. Quote history in MT4 is imperfect, there are always mismatches.

The code is full of errors. Variables are not initialized, the start function doesn't understand what it returns, there is no check of trading functions execution, so please fix it.

Add #property strict to the beginning of the code.

And since we have created two functions for defining order types, why not integrate the counter of orders of each type and write if ( OrdersBuy<1...), if ( OrdersSell<1...) instead of comparing if( OrdersTotal()<1...)? It would be more correct.

Thank you. I will correct it. It's just that when there was one condition:
if ( OrdersTotal()<1 &&  Open[bars0]<Close[bars0]
   ticket = OrderSend(Symbol(),OP_BUY,0.1,Ask,slipage,Ask-stoploss*Point,Ask+takeprofit*Point,"",123,0,Red);
it just wasn't working right, so I asked.
 
danik:

bool _already opened = false;

if (isNewBar()){ _already opened = false;}

if (!OrderSend(...) ) { /* error handling */; } else { _already opened = true; }

isNewBar() - standard, as it is in the articles, using static datetime date = Time[0];

if (_already opened) { return; //don't send the warrant }

it says 'isNewBar' - function not defined 2015

I'm not really a wizard. I'd like an exact copy and paste if you can please.

 
Poinson:

it says 'isNewBar' - function not defined 2015

I'm not really a craftsman. I'd like an exact copy and paste if possible please.

If it's a new bar, you can copy and paste the function isNewBar(), maybe you will get it right, it's not complicated - it compares opening time of a new bar (with index 0, i.e. the last one), if it is more than before it means a new bar has just appeared, and if it has appeared it means you can open a new trade if you have other conditions
 
Poinson:

it says 'isNewBar' - function not defined 2015

I'm not really a craftsman. I'd like an exact copy and paste if possible please.

Yes in any advisor in the kodobase would find it!

//в старте перед условиями входа:
      if(NewBar() == true)
      { 
//----------------------
  return(0);
}
// и вне старта:
//----------------------------//  NewBar  \\----------------------------\\
bool NewBar() 
{
  static datetime lastbar = 0;
  datetime curbar = iTime(NULL,15,0);
  if(lastbar != curbar) 
  {
    lastbar = curbar;
    return(true);
  }
  else return(false);
} 
 
borilunad:

Any councillor in a kodobase would have found it!

Thanks )) The strongest simply! everything worked from the 1st time!

Thank you all!

 

Please help me understand.

How do I write different lines from the indicator into the EA?

I have an indicator - MACD 2 Line. How can I register the lines from the indicator in my EA?

Reason: