[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 324

 
TheXpert >> :

Alert, as an option. Comment -- is fine.

Replace while(true) by while(!IsStopped())

Late.)))

Yes, I forgot about IsStopped.

 
Svinozavr >> :

Late.)))

I can give you a head start next time :) .

Svinozavr >> :

Write the f-fi where the output will be made and write what you need through it.

Option.


 
TheXpert >> :

>> Thank you. Is it possible to change colour of Comment? Or only white?

 
TheXpert >> :
I can give you a head start next time :) .

By the way yes, thank you, very quick reply here :)

 
Mathers >> :

Thank you. Is it possible to change the colour of Comment? Or only white?

>>No, I don't.

 

When there is no need to process every tick, how can I make the code be processed only when a new bar appears?

Surely there must be a ready-made function. Throw me a link...


UPDATE

Thanks, found it (:

//+------------------------------------------------------------------+
//|  возвращает признак появления нового бара для указанного периода |
//+------------------------------------------------------------------+
bool isNewBar(int timeFrame)
   {
   bool res=false;
   
   // массив содержит время открытия текущего (нулевого) бара
   // по 7 (семь) таймфреймам
   static datetime _sTime[7];  
   int i=6;
 
   switch ( timeFrame) 
      {
      case 1  : i=0; break;
      case 5  : i=2; break;
      case 15 : i=3; break;
      case 30 : i=4; break;
      case 60 : i=5; break;
      case 240: break;
      case 1440:break;
      default:  timeFrame = 1440;
      }
//----
   if (_sTime[ i]==0 || _sTime[ i]!=iTime(Symbol(), timeFrame,0))
      {
      _sTime[ i] = iTime(Symbol(), timeFrame,0);
      res=true;
      }
      
//----
   return( res);   
   }
 

How do I use the script to set my own scale on the chart?

The functions that tell you which bar is displayed first are there, but how to reset it is not.

 

Hi all, who can explain? The RefreshRates() function, does it always need to be called or when an Expert Advisor or script performs long calculations, does it work automatically, for example, in error handling functions?
Second question: here is an example of code, I fixed an error, passed a parameter to switch operator...

int start()
  {
      int A = 1000;
      bool B=true;       // Условие успешной работы
//--------------------------------------------------------------
    if(Bars < A)         // Недостаточно баров
    {      
      Alert("Недостаточно баров в окне инструмента.");
      return;            // Выход из start()
    }
    if( B==false)         // Критическая ошибка   
      {      
      Alert("Эксперт не работает.");     
      return;            // Выход из start   
      }
//+-------------------------------------------------------------- 
  return(0);
  }
//--------------------------------------------------------------
    int Bloc_Error(int S)    // Пользовательская ф-ия обработки ошибок
    {   
      switch( S)    
      { 
      case 3:                // Неверные параметры:
      B=false;
      return(0);                                
      }  
    }

Well, now there's another error, it seems undefined variable B
, didn't I declare it?

bool B=true;

This is what the error message looks like :
'B' - variable not defined ----------------- C:\Program Files\MetaTrader - Masterforex\experts\scripts\2.mq4 (31, 7)

Here is another question, what are these numbers? (31, 7), they are always different for different errors, I looked at the same entries in the specified directory, it's just like an error name in a document... is it possible in MetaEditor 4, somewhere to see the description of the solution, for example, as in the Expert Advisor, the errors of execution and execution correspond to their values, where for each number a specific cause of error???

 
Daiver2 писал(а) >>

Hi all, who can explain? The RefreshRates() function, does it always need to be called or when Expert Advisor or script perform long calculations, it triggers automatically, e.g. in error handling functions?
Second question: here is an example of code, I fixed an error, passed a parameter to switch operator...

well, now there's another error, like undefined variable B
didn't I declare it?

This is what the error message looks like:
'B' - variable not defined ----------------- C:\Program Files\MetaTrader - Masterforex\experts\scripts\2.mq4 (31, 7)

Hence another question, what are these numbers? (31, 7), they are always different for different errors, I looked at the same entries in the specified directory, it's just like an error name in the document... is there somewhere in MetaEditor 4, somewhere to see the description of the solution, for example as in the Expert Advisor, execution and runtime errors correspond to their values, where for each number a specific cause of the error??

It should be defined outside the start() function, make it global. Then the variable will be available from any function

 
Vinin >> :

It should be defined outside of the start() function, make it global. Then the variable will be available from any function

Let me explain. Start is the same function as others, so all variable definitions within Start have no effect outside of it. The variable can be globally defined only in the Expert Advisor body, before the init. Then it will be visible to all functions.

Numbers are line number and number of character in the line, where the error occurred.

Reason: