[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 789

 
Hedin:

Dear programmers,
Please advise why operators are not executed when the condition is true, or rather they are executed, but in a random mode (e.g., repeatedly). There are no errors in the logs.


Please correct your code:

if ( MathAbs( ord_sl - (ord_open+First_sell_limit_SL*Point) ) < Point / 2.0 && ...

And never compare variables of type double for equality.

 
PapaYozh:


Correct your code:

And never compare variables of type double for equality.


Why can't you compare variables of type double for equality?
 
Hedin:

Why can't variables like double be compared for equality?
And search doesn't work anymore?
 
Hedin:

Why can't variables of type double be compared for equality?
Take a look here.
 
Necron:
In deinit, write to a global variable and in init, read the value of that variable, what's the problem?

My understanding is that a Global Variable is a variable declared outside of all functions. Global variables are initialised once before special functions are started.

That is, global variables are declared at the beginning of the program before the start function, including the one I want to pass to the program at the next start. Then, according to your suggestion, I fix the value of this variable in deinit. I understand, that at start of program before init function is executed, all global variables, which are described at the beginning of program, including variable I am interested in, will be re-initialized. And when it comes to function init, my variable, registered earlier, will be lost! Or am I wrong?

 
No, he meant the GlobalVariable, which is stored in the file.
 
ikatsko:

My understanding is that a Global Variable is a variable declared outside of all functions. Global variables are initialised once before special functions are started.

That is, global variables are declared at the beginning of the program before the start function, including the one I want to pass to the program at the next start. Then, according to your suggestion, I fix the value of this variable in deinit. I understand, that at start of program before init function is executed, all global variables, which are described at the beginning of program, including variable I am interested in, will be re-initialized. And when it comes to function init, my variable, registered earlier, will be lost! Or am I wrong?

There are two kinds of global variables: global variables of your program, which you write about, and global variables of your terminal,
which are stored separately from your program for a fortnight if not accessed, if memory serves me correctly...
they are used, for example, to transfer data between different EAs working simultaneously on the same terminal, etc...
It is the global variables of the terminal that you need.
 
Roger:
No, he meant the GlobalVariable, which is stored in a file.
Yes, I meant the global variables of the terminal. There was already this question in a private message, I answered it.
 
Necron:
Yes, I meant the global terminal variables. There has already been this question in the private message, I answered it.
Already figured it out. It happens... didn't get it right... Sorry :)
 
вот, собственно код моментума стандартного из МТ4 - ии??? я не вижу тут 
double iMA(string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)
//+------------------------------------------------------------------+
//|                                                     Momentum.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int MomPeriod=14;
 
//---- buffers
double MomBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,MomBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="Mom("+MomPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,MomPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Momentum                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();
   
//----
   if(Bars<=MomPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=MomPeriod;i++) MomBuffer[Bars-i]=0.0;
      
//----
   
   i=Bars-MomPeriod-1;
   if(counted_bars>=MomPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      MomBuffer[i]=Close[i]*100/Close[i+MomPeriod];
      i--;
     }
   return(0);
  }
//+------------------------------------------------------------------+
Roger:

You have searched strangely for

double iMA(

string symbol, int timeframe, int period, int ma_shift, int ma_method, int applied_price, int shift)

The first element.

Reason: