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

 
vasya_vasya:
by creating an errow object where you select the symbol code or by using a label object

Thanks) Eh, it's a pity there are just no dots(
 
FoxUA:
I'm not a worker, but I'm trying to write an Expert Advisor for the week I've been working on. I'm trying to write an EA for a job, but I've learned more than its name and application only a week ago, I don't know what it does, but I found it hard to take things apart without knowing what they're for, so I decided to try and make something new, but of course you can't see everything, I just did the one thing I wanted to do: I took the REMARKED ORDER OFF at the REMARKED price and it was no big deal. BUT THANK YOU FOR YOUR TIME,

No offense. Your code is complicated for a beginner. You have to go from the simple to the complex. There must be a systematic approach to learning, otherwise it won't do any good.
 
Can I use mql4 to find out the bar number or any price parameter of this bar not on the current chart period, if the time of its (this bar's) opening is known?
 
drknn:

Don't be offended. Your code is complicated for a beginner. You have to go from the simple to the complex. You must have a systematic approach to learning, otherwise there will be no use.

I don't agree with you there, you should have a goal in mind and the rest will follow, but you need help. As for the complexity, what's not so complicated and simple with the sample trading robot? I'm not making a big EA with complicated calculations but a simple one that opens the market one, pends, modifies and deletes the whole board to learn the operation and methods of affecting the other one!
 
FoxUA:

I don't agree with you there, you should have a purpose, everything else will follow, but, of course, you can't do without help. As for the complexity, what do you think is simple and easy to build? I'm not making a big EA with complex calculations and indicators but a simple one that opens market one, then modifies and deletes the whole board to learn the working principle and methods of affecting the other one!


Change the logic of code construction and the logic of variable naming. This is the first thing you should do. It's OK if a variable name is longer than 5 characters. In the fight for code clarity, the clarity of names, delimiting blocks with spaces, paragraph signs and comments is damn important. The more you learn a language (and not just MQL), the more complicated your code will become. If you don't make a habit of giving easy-to-read variable names, and if you don't make a habit of organizing code in blocks (with explanations), sooner or later you will create code where you will have a hard time finding the logical error, cursing yourself for making your code so unreadable.

If the code you've shown doesn't seem complicated to you as a beginner, that's just a plus for you.

 
FoxUA:
well, what do you recommend? i'd be very interested in your opinion!

Here is an example of code which is organised in blocks and where the names of variables do not cause doubts as to why a particular variable is applied - look at their names, at the comments to the blocks...

 
RekkeR:
Good evening everyone and have a good week ahead. I guess I'm being dumb with the heat, actually the question is how to determine the distance between the lines in pips?

Speed1=(Price12-Price11)/(Bar11-Bar12); Speed2=(Price22-Price21)/(Bar21-Bar22);

Price1=Price11+Speed1*Bar11; Price2=Price21+Speed2*Bar21;

Distance=(Price1-Price2)/Point;

This is if the distance between two lines at the current time is to be determined.

 
drknn:

Here is an example of code which is organized in blocks and in which the names of variables do not cause doubts as to why this or that variable is applied - look at their names, at the comments to the blocks...

I agree with the fact that sometimes you need to remember what you wanted to write there and do not remember, but it's more a working method, but not a study, it's so to say the brush in the hands of an artist, and I am interested in the choice of colors and techniques for writing a simple little picture, for I already have a landscape and it is clearly shaped, so i was wondering is it possible to have in hand an interesting book describing writing technique for in all the same on the internet and in the textbook, only in other words and what you wrote on the example of the roots, it is a technique of robotics so i would be happy to read if the examples and pictures!

 
tara:

Speed1=(Price12-Price11)/(Bar11-Bar12); Speed2=(Price22-Price21)/(Bar21-Bar22);

Price1=Price11+Speed1*Bar11; Price2=Price21+Speed2*Bar21;

Distance=(Price1-Price2)/Point;

This is if the distance between two lines at the current time is to be determined.

There are several horizontal lines, I need to determine the quotas between them in different combinations, in principle, at this stage I am quite satisfied with the determination between the two lines, the rest I will do manually. Maybe there is a ready-made script or such an indicator? Thank you for your feedback.
 
FoxUA:

...

that's the kind of thing I'd love to read with examples and pictures!

Well, let's do an experiment! Let's write two scripts. One will contain a correct description of the function. The other will contain the wrong one. So, this is the right script:

#property show_inputs //эта строка выводит окно пользовательских параметров на экран
extern double DlyaKornya=300; // величина. из которой нужно извлечь кв. корень
//+------------------------------------------------------------------+
//|                 Старт работы правильного скрипта                 |
//|                 вычисляющего квадратный корень                   |
//+------------------------------------------------------------------+
int start(){
  double Koren=0;
        Alert("--------------------------------------------");
  if(DlyaKornya<0){
    Alert("Ошибка! Переменная ",DlyaKornya," не может быть меньше нуля");
    return(0);
  }
  Koren=MyKoren(DlyaKornya);
  Alert("Наша подпрограмма выдала результат = ",Koren);
        Alert("На вход функции MyKoren() было подано число = ",DlyaKornya);
  Alert("---- Правильное применение функции ----");
        return(0);
}
//+------------------------------------------------------------------+
//|                  Пользовательские подпрограммы                   |
//+------------------------------------------------------------------+

// ------------ MyKoren() -------------------------------------
// функция возвращает квадратный корень числа
// ------------------------------------------
double MyKoren(double MyValue){
        double Rezult=0;
        Alert("Внутри функции переменная MyValue имеет значение = ",MyValue);
        Rezult=MathSqrt(MyValue);
        return(Rezult);
}

And this is the wrong script:

#property show_inputs //эта строка выводит окно пользовательских параметров на экран
extern double DlyaKornya=300; // величина. из которой нужно извлечь кв. корень
//+------------------------------------------------------------------+
//|                 Старт работы неправильного скрипта               |
//|                 вычисляющего квадратный корень                   |
//+------------------------------------------------------------------+
int start(){
  double Koren=0;
        Alert("--------------------------------------------");
  if(DlyaKornya<0){
    Alert("Ошибка! Переменная ",DlyaKornya," не может быть меньше нуля");
    return(0);
  }
  Koren=MyKoren(DlyaKornya);
  Alert("Наша подпрограмма выдала результат = ",Koren);
        Alert("На вход функции MyKoren() было подано число = ",DlyaKornya);
  Alert("----НЕправильное применение функции ----");
        return(0);
}
//+------------------------------------------------------------------+
//|                  Пользовательские подпрограммы                   |
//+------------------------------------------------------------------+

// ------------ MyKoren() -------------------------------------
// функция возвращает квадратный корень числа
// ------------------------------------------
double MyKoren(double MyValue=36){
        double Rezult=0;
        Alert("Внутри функции переменная MyValue имеет значение = ",MyValue);
        Rezult=MathSqrt(MyValue);
        return(Rezult);
}

It is incorrect because the line double MyKoren(double MyValue=36){ initializes variable MyValue with value = 36. It makes no sense because we pass value = to the DlyaKornya variable into the subroutine .

Now we throw both scripts sequentially to the chart. Here is what we see:

Alas, both scripts produced the same result.

The second (incorrect) script should have produced value = 6. The compiler most likely has built-in foolproof feature since the double MyKoren(double MyValue=36){ line has no sense. Initialization of the variable in it with value =36 will probably work only if the function is called without specifying parameters. In our case, the following must have happened - when calling the subroutine, the variable double MyValue was declared first, then it was assigned value = 36 and only after that it was assigned the value stored in variable DlyaKornya. I can't think of any other explanation.

Anyway, it's better not to use constructions like double MyKoren(double MyValue=36){ but write it as it should be - double MyKoren(double MyValue){, otherwise you will wonder why the subprogram does not work as it should.

Reason: