[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 25

 
Dear programmers. As a beginner it is difficult for me to write algorithm, I can edit it, so please help me. I would be very, very grateful!!!
Such a simple EA and it needs:

If condition1 is fulfilled, then:
-check for open SELL orders
-Check if there are any SELL orders open and close them.
check if there are any SELL orders opened - if there are, close them.
-open BUY order

The same if condition 2 is met, then
-check if there are any BUY orders opened
-if any, close them
check if there are any BUY orders opened - if there are, close them
-open a SELL order
+ error analysis (not the main thing, but it is possible)
This is all for the current currency pair.

int start()                       
  {
   double M_0, M_1,               // Значение MAIN на 0 и 1 барах
          S_0, S_1;               // Значение SIGNAL на 0 и 1барах
//--------------------------------------------------------------------
                                  // Обращение к функции техн.индикат.
   M_0 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,  0);// 0 бар
   M_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,  1);// 1 бар
   S_0 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0);// 0 бар
   S_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,1);// 1 бар
//--------------------------------------------------------------------
                                  
   if( M_1 < S_1 && M_0 >= S_0 )  // УСЛОВИЕ 1: Зеленая пересекает красную снизу
     
   if( M_1 > S_1 && M_0 <= S_0 )  // УСЛОВИЕ 2: Зеленая пересекает красную сверху
     
//--------------------------------------------------------------------
   return;                            // Выход из start()
  }
 
Hello! Could you please tell me if it is possible to assign a value to several global variables within a function, and where should these variables be declared in that case?
 
ideasforlife:
Dear programmers. As a beginner it is difficult for me to write algorithm, I can edit it, so please help me. I would be very, very grateful!!!
Such a simple EA and it needs:

If condition1 is fulfilled, then:
-check for open SELL orders
-Check if there are any SELL orders open and close them.
check if there are any SELL orders opened - if there are, close them.
-open BUY order

The same if condition 2 is met, then
-check if there are any BUY orders opened
-if any, close them
check if there are any BUY orders opened - if there are, close them
-open a SELL order
+ error analysis (not the main thing, but it is possible)
This is all for the current currency pair.

There are many Expert Advisors on stochastic in CodeBase. View and redo
 
ideasforlife:
Dear programmers. As a beginner it is difficult for me to write algorithm, I can edit it, so please help me. I would be very, very grateful!!!
Such a simple EA and it needs:

If condition1 is fulfilled, then:
-check for open SELL orders
-Check if there are any SELL orders open and close them.
check if there are any SELL orders opened - if there are, close them.
-open BUY order

The same if condition 2 is met, then
-check if there are any BUY orders opened
-if any, close them
check if there are any BUY orders opened - if there are, close them
-open a SELL order
+ error analysis (not the main thing, but it is possible)
That's all for the current currency pair.

And even easier would be an example from the textbook: https://book.mql4.com/ru/samples/expert.

Is it that hard to read a textbook from cover to cover?

 
ideasforlife:
Dear programmers. As a beginner it is difficult for me to write algorithm, I can edit it, so please help me. I would be very, very grateful!!!
Such a simple EA and it needs:

If condition1 is fulfilled, then:
-check for open SELL orders
-Check if there are any SELL orders open and close them.
check if there are any SELL orders opened - if there are, close them.
-open BUY order

The same if condition 2 is met, then
-check if there are any BUY orders opened
-if any, close them
check if there are any BUY orders opened - if there are, close them
-open a SELL order
+ error analysis (not the main thing, but it is possible)
This is all for the current currency pair.


Ready solution - in textbook version, here. Take away everything about MACD - here and that's it... :-Р

P.S. Even the variable names are almost the same. You may read our tutorial, it has both description and everything else. :-Р

 
Roman.:


Ready solution - in textbook version, here. Take away everything about MACD - here and that's it... :-Р

P.S. Even the variable names are practically the same. Read the textbook - there's a description and everything else. :-Р

Me first! :-P :-P
 
Code:

Hello, dear forum members.

Of course, I have some questions from a newcomer. I am trying to learn mql4, since I have never developed any program before, so the questions may be very primitive. But I've never been able to do it by myself.

I've decided to "mess up" with displaying volumes by drawing a line instead of a bar chart with some processing. The code should make the following sense. Starting from the second bar which is in the same direction as the previous bar (both bars are up), the volume is drawn from the second bar. As a result, I get a broken line in the indicator window, which is indeed drawn from the second bar upwards, but not in all cases for some reason. The line is interrupted because other conditions of its drawing are not defined at all, it is a thing of the future. But here myself to understand why the line is not drawn on every second bar upwards, I can not. Please help me.

Here is the code. If you have any other comments on other errors in the code, I would be glad.


What is the meaning of this indicator? Why do I need it at all?


Why would you need such a characterisation:

ExtVolumesBuffer[i]=dVolume+vteor12-vrealUP12;

Or it is, but it's already exposed:

ExtVolumesBuffer[i]=Volume[i]+(Volume[i]+Volume[i+1])/(2-(Close[i]-Open[i+1])*1000);

???


And about the blunders in the code. Your lines.

double dVolume=Volume[i];
double vback1=Volume[i+1];

         {
         double vteor12=(dVolume+vback1)/2;
            if (Close[i+1]>Open[i+1] && Close[i]>Open[i]) double UP12=(Close[i]-Open[i+1])*1000; else UP12=0;
            if (UP12!=0) double vrealUP12=(dVolume+vback1)/UP12; else vrealUP12=0;
            if (Close[i+1]>Open[i+1])
            if (Close[i]>Open[i])
            ExtVolumesBuffer[i]=dVolume+vteor12-vrealUP12;
            if (ExtVolumesBuffer[i]<0) ExtVolumesBuffer[i]=0;
              }

equivalents of the following:

double dVolume=Volume[i];
double vback1=Volume[i+1];

double vteor12=(dVolume+vback1)/2;
if (Close[i+1]>Open[i+1] && Close[i]>Open[i])
{
   double UP12=(Close[i]-Open[i+1])*1000;
   double vrealUP12=(dVolume+vback1)/(Close[i]-Open[i+1])*1000;
   ExtVolumesBuffer[i]=dVolume+vteor12-vrealUP12;
   if (ExtVolumesBuffer[i]<0)
      ExtVolumesBuffer[i]=0;
}
else
{
   UP12=0;
   vrealUP12=0;
}

You look at the optimised code and think why so many variables were introduced at all? And why would they be "otherwise" zeroed out?

If I understood the idea of the indicator, I would be able to help you.

 
MaxZ:

What would be the point of this indicator? Why do you need one at all?


Why would you need such a characteristic:

??? or is it, but already disclosed:

???


And about the blunders in the code. Your lines

are the equivalent of the following:

You look at the optimised code and you wonder why so many variables were entered in the first place? And why would they be "otherwise" zeroed out?

If I understood the idea of the indicator, I might be able to help you.


Thank you for your answer and I will answer your questions.

That very characteristic is just the whole idea of the indicator. I have also prepared an exercise on MQL. I have thought up a task and intuitively understand that its implementation in a language is not very difficult. I sit and try it.

So, the essence of the characteristic is that I compare a certain fixed theoretical level of two one-directional volumes with the actual level. That is, if the actual ratio of the sum of two volumes to the actual "open-close" interval is higher than the specified theoretical one, I add a "bonus" to the actual second volume in the form of the difference between the calculated theoretical and actual results. If the actual level is lower than the theoretical one, I subtract the same difference from the second bar volume. Can I explain it clearly?

Just in case, I will say that when revealing this characteristic, you put the brackets wrong, probably in a hurry.

Besides, it seems to me that those strings you consider equivalent to mine will lead to division by zero. I'll be checking now.

 

Hi all!

Thanks to the invaluable help of the experts of this branch (especially Roman) I managed to make a simple Expert Advisor, which is + on the tester. Question: How to determine whether it may be placed for real trading? Are there any criteria?

 
MaxZ:
Me first! :-P :-P

You're going the wrong way at all... Not to the right trading criteria at all, it's a question of STO-HAS-TO-KE... :-Р
Reason: