[ARCHIVE]Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Can't go anywhere without you - 5. - page 301

 
laveosa:

I've done everything exactly the same way and more than once, but there's still that hole.
Then look for Cheburashka in your dwelling! Surely his antics! ;)
 
laveosa.,keep the history up to yesterday eurusdm1 download via import in quotes.
Files:
eurusd1.zip  548 kb
 
I tried to check one indicator, I put the numbers on the chart but they don't change, I'll try to put it in another way, I need the attached indicator to fix the price as a cross that stands on a zigzag or alert or print but it freezes on the connection.
Files:
 

A question for the experts!

I often have wizards in my EAs. In order not to "litter" the code with repetitive moments, like:

double maFast = iMA(NULL, 0, i_maFastPeriod, 0, i_maMethod, i_maPrice, index);
double maSlow = iMA(NULL, 0, i_maSlowPeriod, 0, i_maMethod, i_maPrice, index);

Such repetitions can be in order. I wanted to get rid of them by writing separate functions.

Here is the beginning:

//+-------------------------------------------------------------------------------------+
//| Получаем машку с заданными параметрами                                              |
//+-------------------------------------------------------------------------------------+
double GetMA(double typeOfMA, int tf, int maPeriod, int maShift, int maMethod, int maApplied, int index)
{
   switch (typeOfMA)
   {
      case 1:      return (iMA(NULL, i_fastMATF, i_fastMAPeriod, i_fastMAShift, i_fastMAMethod, i_fastMAApplied, i_fastMAIndex));
      case 2:      return (iMA(NULL, i_slowMATF, i_slowMAPeriod, i_slowMAShift, i_slowMAMethod, i_slowMAApplied, i_slowMAIndex));
      case 3:      return (iMA(NULL, i_filtrMATF, i_filtrMAPeriod, i_filtrMAShift, i_filtrMAMethod, i_filtrMAApplied, i_filtrMAIndex));
   }
}
//+-------------------------------------------------------------------------------------+
//| Получаем сигнал от скользящих средних                                               |
//+-------------------------------------------------------------------------------------+
int GetStateOfMA()
{
   if (GetMA(1, i_fastMATF, i_fastMAPeriod, i_fastMAShift, i_fastMAMethod, i_fastMAApplied, i_fastMAIndex) > 
      GetMA(2, i_slowMATF, i_slowMAPeriod, i_slowMAShift, i_slowMAMethod, i_slowMAApplied, i_slowMAIndex))
      return (CROSS_UP);
}

We can go further, declaring globally variables for wipes, e.g. fastMA and slowMA, and return them by reference via function :

GetMA(double typeOfMA, int tf, int maPeriod, int maShift, int maMethod, int maApplied, int index)

You would get something like this:

//+-------------------------------------------------------------------------------------+
//| Получаем машку с заданными параметрами                                              |
//+-------------------------------------------------------------------------------------+
double GetMA(double typeOfMA, int tf, int maPeriod, int maShift, int maMethod, int maApplied, int index, double& fastMA, double& slowMA)
{
   switch (typeOfMA)
   {
      case 1:      return (iMA(NULL, i_fastMATF, i_fastMAPeriod, i_fastMAShift, i_fastMAMethod, i_fastMAApplied, i_fastMAIndex));
      case 2:      return (iMA(NULL, i_slowMATF, i_slowMAPeriod, i_slowMAShift, i_slowMAMethod, i_slowMAApplied, i_slowMAIndex));
      case 3:      return (iMA(NULL, i_filtrMATF, i_filtrMAPeriod, i_filtrMAShift, i_filtrMAMethod, i_filtrMAApplied, i_filtrMAIndex));
   }
}
//+-------------------------------------------------------------------------------------+
//| Получаем сигнал от скользящих средних                                               |
//+-------------------------------------------------------------------------------------+
int GetStateOfMA()
{
   GetMA(double typeOfMA, int tf, int maPeriod, int maShift, int maMethod, int maApplied, int index, double& fastMA, double& slowMA);
   if (fastMA > slowMA)
       return (CROSS_UP);
   if (fastMA < slowMA)
       return (CROSS_DN);
   return (CROSS_NO);
}

The question is this:

I've heard or read somewhere that switch operator is slow, won't it affect performance of EA in general in this case? In general, how slow is it?

Many parameters come out here, won't it slow down an Expert Advisor?

I am writing and thinking about productivity, so the question arises, as I am not a programmer by training, to understand it myself, not really comes out ...

 

Victor, the function call is much more of a brake than switch. You can check the speed yourself. Write a test code with a loop. Where you will check your code. Measure the time at the input. Then compare it with the output time.

The switch operator is one of the fastest operators. It's faster than running through the conditions.

Switch should be used with a default on exceptions. So that in case of an incorrect condition you would know why the code does not work.

 

Hmm. I guess you can't use a constant for case as a variable, according to the documentation. It says some kind of target constant, character constant or character expression.

It only works if you set a string-type letter, i.e. 1 character (if more than 1 character, the compiler swears) or a number.

Nothing else.
It says some target constants, character expressions and character constants.

 

Where can I read about using global terminal variables with practical examples? Specifically, I want to make each Expert Advisor trade only its share of the deposit and its profit/slippage does not affect the MM of other Expert Advisors.

 
Ekburg:

Hi all

Can you advise what may be the cause of the "shutdown by timeout" error, when running the Expert Advisor in the terminal and how to solve this problem?

 
[quote=Roman.]Change the kitchen.[/quote]That's the thing, the kitchen is not involved: the sell order is in the EA log. of course, you can assume that the broker has changed the code of the downloaded MT4 distributive and corrects the deal direction, but it would be too impudent, I think.
 
Can I attach program codes instead of copying the whole code here? Where are the admins looking?
Reason: