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

 
yosuf:
It describes an option to stop the task running. I don't know if this will cause the platform to shut down, I'll give it a try.
I won't say anything about the platform (I don't know), but the terminal will shut down (theoretically). :)))
 
Can you tell me how to calculate the futures deposit?
 
Roman.:

" I want to do it in order not to get the same data in different f-functions. I do not think it is reasonable to calculate the same masks in 2 or more functions. It's easier to calculate once and that's it. Why waste additional resources on this?

Do as it says in the documentation and don't reinvent the wheel.

What does this cycle have to do with anything?

 for(int i=1;i<=Bars;i++)
   {
      double i_maFast1 = iMA(Symbol(),i_TF,i_maFastPeriod,i_maFastShift,i_maFastMethod,0,i);      // Вычисляем быстрые скользящие..
      double i_maFast2 = iMA(Symbol(),i_TF,i_maFastPeriod,i_maFastShift,i_maFastMethod,0,i+1);    //..средние
      double i_maSlow1 = iMA(Symbol(),i_TF,i_maSlowPeriod,i_maSlowShift,i_maSlowMethod,0,i);      // Вычисляем медленные скользящие..
      double i_maSlow2 = iMA(Symbol(),i_TF,i_maSlowPeriod,i_maSlowShift,i_maSlowMethod,0,i+1);    //..средние
      double stochD1 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,1,i);     // Вычисляем значения сигнальной линии..
      double stochD2 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,1,i+1);   //..стохастика
      double stochK1 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,0,i);     // Вычисляем значения главной линии..
      double stochK2 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,0,i+1);   //..стохастика
   }

Go through the steps yourself, what happens when you exit it and what do you do with it next? It's nonsense.

You do it like in the tutorial - all trade signals in this definition definition of trade criteria - in series (you can wrap them in different functions and then work with them when checking whether these trade criteria work), then the conditions for their work.

Regarding the cycle, it is because I will check the intersection of indicator parameters. It's all elementary here. I read it and it is written the way I think it is.

The textbook in general https://book.mql4.com/ru/build/conditions is all bunched up. I've got MACD and stochastic in one function, I don't need it.

In fact, all of the indicator values in the link should be transferred to the appropriate functions. Why not? This is logical.

 
TarasBY:
What you tell and what you "draw" - TWO BIG DIFFERENCES!!! :))

I'm getting a bit confused now. Here are 3 functions, each of which receives a specific signal for a specific indicator.

//+---------------------------------------------------------------------------------------+
//| Проверка пересечения скользящих средних                                               |
//+---------------------------------------------------------------------------------------+
int GetCrossingMa(double& i_maFast1, double& i_maFast2, double& i_maSlow1, double& i_maSlow2)
{
      if ((i_maFast2<i_maSlow2) && (i_maFast1>i_maSlow1))             // Если быстрая скользящая пересекла медленную снизу вверх..
      return(CROSSINGTOUP);                                           //.. значит, - пересечение вверх
                                                 
      if ((i_maFast2>i_maSlow2) && (i_maFast1<i_maSlow1))             // Если быстрая скользящая средняя пересекла медленную сверху вниз..
      return(CROSSINGTODOWN);                                         //..значит, - пересечение вниз
 
   return(CROSSINGWAIT);                                              // Ожидаем пересечения
}

//+---------------------------------------------------------------------------------------+
//| Получение сигнала от Стохастика                                                       |
//+---------------------------------------------------------------------------------------+
int GetStochSignal(double& stochD1, double& stochD2, double& stochK1, double& stochK2)
{
      if((stochD2<stochK2) && (stochD1>stochK1))                     // Если сигнальная линия пересекла главную снизу вверх..
      return(CROSSINGTOUP);                                          //..значит, - пересечение вверх
      if((stochD2>stochK2) && (stochD1<stochK1))                     // Если сигнальная линия пересекла главную сверху вниз..
      return(CROSSINGTODOWN);                                        // ..значит, - пересечение вниз
   return(CROSSINGWAIT);                                             // Ожидаем пересечения
}

//+---------------------------------------------------------------------------------------+
//| Получение сигнала от Моментума                                                        |
//+---------------------------------------------------------------------------------------+
void GetMomentumSignal()
{
   double momentum = iMomentum(Symbol(),i_TF,i_momPeriod,0,0);
}

This function receives general signal from all indices and makes decision to BUY or SELL.

//+---------------------------------------------------------------------------------------+
//| Получение общего сигнала для входа в рынок                                            |
//+---------------------------------------------------------------------------------------+
int GetSignal()
{
   for(int i=1;i<=Bars;i++)
   {
      double i_maFast1 = iMA(Symbol(),i_TF,i_maFastPeriod,i_maFastShift,i_maFastMethod,0,i);      // Вычисляем быстрые скользящие..
      double i_maFast2 = iMA(Symbol(),i_TF,i_maFastPeriod,i_maFastShift,i_maFastMethod,0,i+1);    //..средние
      double i_maSlow1 = iMA(Symbol(),i_TF,i_maSlowPeriod,i_maSlowShift,i_maSlowMethod,0,i);      // Вычисляем медленные скользящие..
      double i_maSlow2 = iMA(Symbol(),i_TF,i_maSlowPeriod,i_maSlowShift,i_maSlowMethod,0,i+1);    //..средние
      double stochD1 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,1,i);     // Вычисляем значения сигнальной линии..
      double stochD2 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,1,i+1);   //..стохастика
      double stochK1 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,0,i);     // Вычисляем значения главной линии..
      double stochK2 = iStochastic(Symbol(),i_TF,i_stoch_D,i_stoch_K,i_stoch_slowing,0,0,0,i+1);   //..стохастика
   }
      if( GetCrossingMa(i_maFast1, i_maFast2, i_maSlow1, i_maSlow2)==CROSSINGTOUP || i_maFast1>i_maSlow1 )
      return(SIGNAL_BUY);
}

This is the main function that receives the general signal; here we get the values of indices through the loop to go through all the bars, of course... And then the obtained values are passed by reference to the appropriate functions where these values are needed, i.e. to the functions:

int GetCrossingMa(double& i_maFast1, double& i_maFast2, double& i_maSlow1, double& i_maSlow2)

int GetStochSignal(double& stochD1, double& stochD2, double& stochK1, double& stochK2)

void GetMomentumSignal() , in principle, can also be put there.

Thus, all the calculations of the indices will be in one main function of getting the signal. Everything here is logical.

 

Immediately after attachment to the chart the program starts the init() function. Function init() of attached Advisor or custom indicator starts immediately after client terminal start and loading (it concerns only advisors and not indicators) of historical data, after a change of symbol and/or chart period, after recompiling the program in MetaEditor, after a change of input parameters from the EA or custom indicator settings window. The Expert Advisor is also initialized after a change of account.

Can you explain how it works? In the background, or can this be tracked somehow? Or the init function in the indicator, when I start the terminal after a long idle time will not start at all?

 
fore-x:

Immediately after attachment to the chart the program starts the init() function. Function init() of attached Advisor or custom indicator starts immediately after client terminal start and loading (it concerns only advisors and not indicators) of historical data, after a change of symbol and/or chart period, after recompiling the program in MetaEditor, after a change of input parameters from the EA or custom indicator settings window. The Expert Advisor is also initialized after a change of account.

Can you explain how it works? In the background, or can this be tracked somehow? Or the init function in indicator at the start of the terminal will not start after a long idle time?

The init function is intended for storing data that will not be changed during the whole running of the EA. This can be some data that will be calculated only once after the program is loaded and no more re-calculations are needed. This is how I understand it.

And if values of variables need to be recalculated, for example, with each arrival of a new bar, then we shouldn't declare such variables in the init function, since they won't be recalculated there.

To make it easier to understand, this is what can and should be declared in init:

   Tick = MarketInfo(Symbol(), MODE_TICKSIZE);                         // минимальный тик    
   Spread = ND(MarketInfo(Symbol(), MODE_SPREAD)*Point);                 // текущий спрэд
   StopLevel = ND(MarketInfo(Symbol(), MODE_STOPLEVEL)*Point);  // текущий уровень стопов
   MinLot = MarketInfo(Symbol(), MODE_MINLOT);    // минимальный разрешенный объем сделки
   MaxLot = MarketInfo(Symbol(), MODE_MAXLOT);   // максимальный разрешенный объем сделки
   LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);          // шаг приращения объема сделки

This is collection of data from the market, and this data is not changed. Although it's a question with Spread variable... if spread is not fixed, it's better to put it in separate functions.

 
hoz:

The init function is used to store data that will not be altered during the lifetime of the EA...

You're answering off-topic, once again - the init() functionis started afterloadinghistorical data (this only applies to Expert Advisors, not to indicators) - how do you understand that (I want to feel it)?


Taking a pawn on a pass - I know there is such a rule, but I don't know how to apply it (it's clearer)?

 
I answered above as I understand it. I didn't really understand your point of view. Maybe someone else will.
 

Good day everyone. please help, i have a combination of candlesticks and i would like them to work on different time scales. By way of example

if(iHigh("EURUSD",PERIOD_M5,1)>iLow("EURUSD",PERIOD_M5,1)+8*kio*Point)

{

go_s=true;

}

I thought I could bind my combination using iHigh, iLow, iOpen, etc. But when tested on M5 it shows one result but on other timeframes another. Please help what i am doing wrong. Thank you!

 
hoz:

...

The textbook https://book.mql4.com/ru/build/conditions is all bunched up. It has MACD and stochastic in one function, and I don't need it that way.

And in fact, all of the indicator values by the link should be passed to the appropriate functions. Why not? This is logical.

Thus, it turns out that all of the calculations of indices will be in one main f-function of getting the signal. It all makes sense.

Sorry, but it looks like you are still at the very beginning of the food chain, that's exactly where "everything is logical". :-)

Make it like a STUDY BOOK and DOCI, and then wrap it in separate functions and get a trading criterion in the result.

In the tutorial - all is at once registered in the resultant, you can register your f-i-tions - separately, and the RESULTING is drawn as in the tutorial! No loop or parameter value transfer by reference is needed here!

P.S. And in general, first disassemble the code expos - all in the tutorial and a few in kodobase - just everything falls into place.

Reason: