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

 

Hello.

Can you please tell me if it's possible to calculate the distance in points between two mashes.

My variant is given below, but it doesn't work as originally intended.

Thank you in advance.

  int g;
  double maHX_fast=iMA(NULL,fast_maHX_timeframe,fast_maHX_period,0,fast_maHX_method,fast_maHX_price,0);
  double maHX_slow=iMA(NULL,slow_maHX_timeframe,slow_maHX_period,0,slow_maHX_method,slow_maHX_price,0);
  g = maHX_slow - maHX_fast;
  Alert (g);
 
nemo811:

My variant is given below, but it doesn't work as originally intended.

Found a mistake. Here's a working version:

  double g;
  double maHX_fast=iMA(NULL,fast_maHX_timeframe,fast_maHX_period,0,fast_maHX_method,fast_maHX_price,0);
  double maHX_slow=iMA(NULL,slow_maHX_timeframe,slow_maHX_period,0,slow_maHX_method,slow_maHX_price,0);
  g = (maHX_slow - maHX_fast)/Point;
  Alert (g);
 

Afternoon....

How to transfer the close price value of an order from one terminal to another, trading on the same currency pair ?

 
TANKER:

Good afternoon....

How to transfer the close price value of an order from one terminal to another, trading on the same currency pair ?


If you are asking such a question then i don't think you can do it yourself.
 

Good evening everyone!

The following question about arrays arises.

Suppose we need to analyze n bars for a certain fluctuation, select it, put it into an array and work with this...

Below is some code; I think the comments will explain everything.

The logic is as follows:

1. We set the necessary number of bars.

2. Loop through the whole thing in the loop.

Look for fulfillment of the specified condition(close_1>close_2&close_2<close_3).

4. If the condition is met, then we calculate the difference diff between the closing price close_1 and close_2.

And then the questions themselves:

1. How to correctly form an array and write there values of diff (of course, the dimensionality of the array is determined depending on the number of obtained values)?

2. Calculate and display the number of elements in the array ???

3. Select e.g. 3, 6, 7 elements and calculate their sum ???

4. And finally, e.g., to Print/Alert directly to output the entire array instead of individual elements ???

#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
   //определяем переменные
   int i, bars;
   double close_1, close_2, close_3;//цена закрытия
   double diff;//вычисление разности close_1 и close_2
   double Mas[];//массив куда надо заносить данные
   
   
   //устанавливаем значения переменных
   bars=60;//количество баров для анализа
   
   for(i=1;i<=bars;i++)
   {
      close_1=iClose(NULL,PERIOD_M1,i);
      close_2=iClose(NULL,PERIOD_M1,i+1);
      close_3=iClose(NULL,PERIOD_M1,i+2);
      
      //условие для отбора в массив
      if(close_1>close_2&&close_2<close_3)//если выполняется это условие, тогда
      {
         diff=close_1-close_2; //считаем разность и записываем это дело в массив 
         
         /*
         Собственно вопросы:
         1. Как правильно сформировать массив и записать туда полученные значения diff ???
         2. Посчитать и вывести количество элементов в массиве ???
         3. Выбрать например 3, 6, 7 элемент и посчитать их сумму ???
         4. И последнее, непосредственно вывести например в Print/Alert весь полученный массив, а не только отдельно взятый элемент ???
         */
         
         //Это просто вывод, чтобы удостовериться что наше условие работает, можно потереть... 
         Alert("i ",i," diff: ",DoubleToStr(diff,5));
         
      }
   }


   return(0);
  }
//+------------------------------------------------------------------+
And here is a picture to make it clear, which condition we process. : ))

Thanks in advance everyone!

 
NickXXX:

Good evening everyone!

The following question about arrays has arisen.

Suppose we want to analyze n bars for a particular oscillation, select it, store in an array and work with this...

Laugh after the word indicator.

It's easier to create an indicator, it already has eight buffer arrays, put all the logic on it and then address the required elements through iCustom

In print/alert the whole array is somewhat unreadable, but through enumeration and creating a long string in the loop is quite possible.

3. Select e.g. 3, 6, 7 elements and calculate their sum ???

Either don't joke about this or read the documentation.

double Summa=Mas[3]+Mas[6]+Mas[7];

Recommended reading https://book.mql4.com/ru/variables/arrays

https://docs.mql4.com/ru/array

 
splxgf:

Laugh after the word indicator.

It's easier to create an indicator, it already has eight buffer arrays, transfer all logic to it, and then address the necessary elements via iCustom

In print/alert the whole array is a bit unreadable, but through enumeration and creating a long string in the loop is quite possible.

Either don't mess around like this, or read the documentation.

double Summa=Mas[3]+Mas[6]+Mas[7];

Recommended reading https://book.mql4.com/ru/variables/arrays

https://docs.mql4.com/ru/array

Yes, you don't need to ask about summa). And it's not about the indicator here. It is rather an example so that I could understand arrays properly.

I have already seen the recommended article but it did not help me to handle this question.

So my question is still relevant... How to build an array in this example? I would be very grateful if you could give me the code for clarity. It's easier to understand what we're talking about.

 

better to smoke indicators, all calculations are linked to bars, and the numbering of bars starts from zero and the array is shifted at each new bar. Using an indicator will allow you to transfer the logic of working with arrays to the system, plus it will add visual capabilities, plus easy use from an EA.

Make an indicator, otherwise it is very difficult to link the calculated elements of the array to the bars on the chart.

 
splxgf:

better to smoke indicators, all calculations are linked to bars, and the numbering of bars starts from zero and the array is shifted at each new bar. Using an indicator will allow you to transfer the logic of working with arrays to the system, plus it will add visual capabilities, plus easy to use from an EA.

Make the indicator, otherwise it will be very difficult to bind the calculated elements of the array to the bars on the chart.

Ok, I understand, it's better to read everything in the indicator and send values to the Expert Advisor.

But the issue here is a little different, I cannot fill the array with data, it displays zeros. I want to understand it.

Again, using this example. Binding to bars I have, just sequentially go to i and work out the right condition close_1>close_2&close_2<close_3 (just for example).

And now the most interesting thing is that we have calculated diff=close_1-close_2. How to put this value of diff into array?

I think with size we can make additional variable int n and increase it by 1 (n++) in if condition, we'll get how many times the condition worked and take this number as size.

But still, how to put the diff value into an array???

 
NickXXX:

I understand, it's better to read everything in the indicator and send the values to the Expert Advisor.

But the question is a bit different, I cannot fill the array with data, it outputs zeros to me. I want to understand it.

Again, using this example. Binding to bars I have, just sequentially go to i and work out the right condition close_1>close_2&close_2<close_3 (just for example).

And now the most interesting thing is that we have calculated diff=close_1-close_2. How to put this value of diff into array?

I think with size we can make additional variable int n and increase it by 1 (n++) in if condition, we'll get how many times the condition worked and take this number as size.

But still, how to put diff value into array???

Look, I'm probably a caper right now, but I take it you're baffled that I'm using a script in this example. Did you mean it when you wrote about the indicator? If I did, then I make all dynamic calculations in an indicator or in an Expert Advisor directly. I have just launched it once, looked at it and then corrected the code))).

The previous question is still relevant. The subject of the array is not solved).

Reason: