Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1041

 
Igor Makanu:

Try asking the question differently, your question may not be clear

I'll try to explain. But bear in mind that I am not a programmer, practically.

We have a tick indicator that builds a curve on bid values.

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
double x[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,x);
   SetIndexDrawBegin(0,0);
   SetIndexLabel(0,"x");
   SetIndexShift(0,0);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double b=MarketInfo(Symbol(),MODE_BID);
   x[0]=b;
   for(int j=ArraySize(x)-1;j>=1;j--){x[j]=x[j-1];}
   return(0);
  }
//+------------------------------------------------------------------+

Now what I want to do.

Attach the indicator to the chart. Get the first value of bid1 on the first tick. Remember it (I did so - I enter the second buffer y[0] and record its value in init()).

On the second tick we obtain the second value of bid2.

Then we need to get the difference in points. delta=bid1-bid2 (I did it this way: delta=x[0]-x[1]).

Now add delta to y[0] and obtain the value of y[1], which actually corresponds to the value of bid2.

The indicator curve should be identical to the one we are looking for but it is plotted using the calculated values of bid differences.

This indicator is needed as a template for further calculations.

Do not throw stones. I explained it as best I could.

Thank you.

 
Oleg Bondarev:

I'll try to explain. But bear in mind that I am a novice programmer, practically.

We have a tick indicator, which builds a curve by bid values.

Now what I want to do.

Attach the indicator to the chart. Get the first value of bid1 on the first tick. Remember it (I did so - I enter the second buffer y[0] and record its value in init()).

On the second tick we obtain the second value of bid2.

Then we need to get the difference in points. delta=bid1-bid2 (I did it this way: delta=x[0]-x[1]).

Now add delta to y[0] and obtain the value of y[1], which actually corresponds to the value of bid2.

The indicator curve should be identical to the sought after indicator but it is plotted using the calculated values of bid differences.

This indicator is needed as a template for further calculations.

Do not throw stones. I tried to explain it as best I could.

Thank you.

It is not clear what you want to do

Here is the general problem - you use indicator buffers as an array for storing ticks (Bid), the size of the indicator buffer changes the terminal itself, and in addition - the terminal shifts the indicator buffers itself at appearance of a new bar

you should use an array for storing ticks, and use an indicator buffer for drawing

i have created a code similar to yours, where i save ticks in an array

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      TickCount=10;  //Размер массива тиков
//--- indicator buffers
double         Label1Buffer[];
double TickArr[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   ArrayResize(TickArr,TickCount);                                   //изменим размер массива
   ArrayInitialize(TickArr,SymbolInfoDouble(_Symbol,SYMBOL_BID));    // проинициализируем массив значением текущего Bid
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   for(int i=ArraySize(TickArr)-1;i>0;i--)
   {
      TickArr[i] = TickArr[i-1]; // сдвинули массив
   }
   TickArr[0] = SymbolInfoDouble(_Symbol,SYMBOL_BID); // в 0-й элемент массива запомнили новый Bid
   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Now, you should add your calculation to this code and draw it using the indicator buffer Label1Buffer as per your idea

 
It would be nice if they added the possibility to change properties of another indicator programmatically. Roughly speaking, after adding (programmatically) another indicator to the chart, you can set its colour, style and thickness of lines
 
Igor Makanu:

it is not clear what you want to do

here is the exact problem - you use indicator buffers as an array for storing ticks (Bid), the size of indicator buffer changes the terminal itself, and in addition - the terminal shifts the indicator buffers itself when a new bar appears

you should use an array for storing ticks, and use an indicator buffer for drawing

i have created a code similar to yours, where i save ticks in an array

Now, you have to add your calculation to this code and draw it using the indicator buffer Label1Buffer, as per your idea

Thank you for replying. I will torture you a bit more.

Do I add the calculation here?

int OnCalculate()

Here is my calculation.

   if(TickArr[0]>TickArr[1])
     {
      Label1Buffer[0]=Label1Buffer[1]+(TickArr[0]-TickArr[1]);
     }
   if(TickArr[0]<TickArr[1])
     {
      Label1Buffer[0]=Label1Buffer[1]-(TickArr[0]-TickArr[1]);
     }
   if(TickArr[0]==TickArr[1])
     {
      Label1Buffer[0]=Label1Buffer[1];
     }

Added it and nothing.

 
Yevhenii Levchenko:
It would be nice if they added the possibility to change properties of another indicator programmatically. Roughly speaking, after adding (programmatically) another indicator to the chart, you can set the colour, style and thickness of lines

Use Canvas and draw cartoons.

 

I'll attach a picture more.

ind

 
Oleg Bondarev:

Added and nothing.

that's not how it works ))))

To draw using indicator buffers in MQL, it means to put a value in the indicator buffer - in my example, it is Label1Buffer (assign a value)

in your example you assign values only when a condition is met and if the condition is not met? - So nothing will be printed.


And again, I created a "template" where the array TickArr contains the values of ticks Bid, but in your conditions you use the previous values of the indicator buffer - and who put what values in these buffers?


Try to draw a line by the indicator buffer, then you'll compare the ticks.

 
Oleg Bondarev:

I'll attach a picture more.


What if the angle is reversed? How would the calculation be done?

 
Oleg Bondarev:

I'll attach a picture more.


If you say that you are practically a zero in programming, then why are you taking on such non-standard tasks, maybe you should start with simple ones? Or to improve your knowledge of the basics? It's easier to get it done for you, yes.
 
Igor Makanu:

that's not going to work ))))

To draw using indicator buffers in MQL, it means to put a value (assign a value) to the indicator buffer - in my example, the Label1Buffer

in your example you assign values only when a condition is met and if the condition is not met? - So nothing will be printed.


And again, I created a "template" where the array TickArr contains the values of ticks Bid, but in your conditions you use the previous values of the indicator buffer - and who put what values in these buffers?


Try to draw a line by the indicator buffer, and then you will compare the ticks.

I warned that I'm a hacker.)

I did it that way.

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      TickCount=100000;  //Размер массива тиков
input int      TickCountb=100000;
//--- indicator buffers
double Label1Buffer[];
double TickArr[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
   ArrayResize(TickArr,TickCount);
   ArrayResize(Label1Buffer,TickCountb);                                   //изменим размер массива
   ArrayInitialize(TickArr,MarketInfo(Symbol(),MODE_BID));    // проинициализируем массив значением текущего Bid

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   for(int i=ArraySize(TickArr)-1;i>0;i--)
   {
      TickArr[i] = TickArr[i-1]; // сдвинули массив
   }
   TickArr[0] = MarketInfo(Symbol(),MODE_BID); // в 0-й элемент массива запомнили новый Bid
   
   for(int j=ArraySize(TickArr)-1;j>0;j--)
   {
      Label1Buffer[j] = Label1Buffer[j-1]; // сдвинули массив
   }
   
   Label1Buffer[0]= TickArr[0];   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Now it draws the tick chart but there are some line breaks.

I'm doing a 4.