Download MetaTrader 5

Question: Bolinger bands - page 2

To add comments, please log in or register
Fernando Carreiro
3395
Fernando Carreiro  
steve_o:
you're right:-)- see below:

Yes, there are several logic problems in your code.

  1. You never call the function "CheckVolKatan()" anywhere in your code, so how do you expect it to have any influence?
  2. In the "OpenOredrsThisPair()" (which is a mistype I think), you never test the result of OrderSelect() and just assume that it always works.
  3. In the same "OpenOredrsThisPair()", you also do not check for your magic number, so the order count will be incorrect.
  4. Your IsNewCandle() is unreliable. You should not use Bars to check for a New Candle. It is a very old and a unreliable technique. Use the following instead:
    bool IsNewCandle()
    {
       static datetime last_time = WRONG_VALUE;
       datetime lastbar_time = (datetime) SeriesInfoInteger( _Symbol, _Period, SERIES_LASTBAR_DATE ); // to be compatible with MQL5
    
       if( last_time != WRONG_VALUE )
       {
          if( last_time != lastbar_time )
          {
             last_time = lastbar_time;
             return( true );
          }
       }
       else
          last_time = lastbar_time;
    
       return( false );
    }
whroeder1
16306
whroeder1  
  1. Bars is unreliable (a refresh/reconnect can change number of bars on chart) volume is unreliable (miss ticks) Always use time. New candle - MQL4 forum
  2. I disagree with make a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Steve_o
34
Steve_o  

All- thanks very much for your assistance and Important comments!

much appreciated!!!

Steve_o
34
Steve_o  
int OpenOrdersThisPair(string pair)
{
   int total=0;
   for(int i=OrdersTotal()-1; i>=0; i--)
   {
      bool succeed = OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(succeed && OrderSymbol()==pair) 
      {
         total++;
      }
   }
   return total;
}
FMIC
:

Yes, there are several logic problems in your code.

  1. You never call the function "CheckVolKatan()" anywhere in your code, so how do you expect it to have any influence?
  2. In the "OpenOredrsThisPair()" (which is a mistype I think), you never test the result of OrderSelect() and just assume that it always works.
  3. In the same "OpenOredrsThisPair()", you also do not check for your magic number, so the order count will be incorrect.
  4. Your IsNewCandle() is unreliable. You should not use Bars to check for a New Candle. It is a very old and a unreliable technique. Use the following instead:

Hi FMIC,

Do you think the below change Improve this function for #2 and 3 (mistype Indeed).

Thanks. 

Fernando Carreiro
3395
Fernando Carreiro  
steve_o: Do you think the below change Improve this function for #2 and 3 (mistype Indeed).
You are still missing Point 3 (magic number). As it is, it will return the wrong count because it will include in that count trades from other EAs (other magic numbers) and Manual Trades and not just trades from your specific EA (your magic number).
int OpenOrdersThisPairMagic( string pair, int magic )
{
   int total = 0;
   for( int i = OrdersTotal() - 1; i >= 0; i-- )
   {
      ResetLastError();
      if( OrderSelect( i, SELECT_BY_POS, MODE_TRADES ) )
      {
        if( ( OrderSymbol() == pair ) && ( OrderMagicNumber() == magic ) )
           total++;
      }
      else
         Print( "Select: ", i, "; Error: ", _LastError );
   }
   return total;
}
12
To add comments, please log in or register