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

 
Vitaly Muzichenko #:

I did it, it works.

---

Something tells me you can do without the cycle.

Is this true?

There seems to be no shift function in MQL, as far as I know. So, the shift can only be done with the help of a loop. Why doesn't it suit you?

P.S. About the extra array, it was not necessary. You correctly made the shift and write the bid value right in the buffer!

 
EVGENII SHELIPOV #:

Good afternoon .

I am displaying the value of the daily fractal in the form of its value or a vertical line. The line is not displayed and the value is 0.

Here is a piece of code


Please tell me what's wrong.

Why are you sure the fractal on the zero bar must be non-zero? When, it won't be 0 only if it is there!


Tretyakov Rostyslav #:

Because the value is 0. The fractal is formed after n candles

And this also happens farfrom always. Only in case if the n-th bar is a fractal!

 
Vitaly Muzichenko #:

Meaning, to see the last ticks on an open chart :)

P.S. * Change of Ask and Bid

As in Market Watch


I was thinking speed measures)))

 
Vitaly Muzichenko #:

Meaning, to see the last ticks on an open chart :)

P.S. * Change of Ask and Bid

As in Market Watch


What's wrong withArrayCopy()?
Документация по MQL5: Операции с массивами / ArrayCopy
Документация по MQL5: Операции с массивами / ArrayCopy
  • www.mql5.com
ArrayCopy - Операции с массивами - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin #:
ArrayCopy() is not a good solution?

ArrayCopy, this is for copying from one array to another. And here you need to shift the values before adding each tick. Therefore, it can only be solved by using a loop.

 
Artyom Trishkin #:
ArrayCopy() does not suit you?

How to use this, can you show me?

Here's the task.

Forum on trading, automated trading systems & strategy testing

Any questions from newbies on MQL4 and MQL5, help and discussion of algorithms and codes

Vitaly Muzichenko, 2022.02.13 15:42

I don't need an array for the entire available history.

I literally need 50-100 bars

Like this


Here is the ready code, but the loop is a bit scary

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDodgerBlue
#property indicator_label1  "Bid"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_label2  "Ask"

double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnInit()
{
  SetIndexBuffer(0,Buffer1);
  ArraySetAsSeries(Buffer1,true);
  SetIndexBuffer(1,Buffer2);
  ArraySetAsSeries(Buffer2,true);
  ArrayInitialize(Buffer1,EMPTY_VALUE);
  ArrayInitialize(Buffer2,EMPTY_VALUE);
  IndicatorSetInteger(INDICATOR_DIGITS,Digits());
  IndicatorSetString(INDICATOR_SHORTNAME,"Tick:");
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[])
{
  int H=100;
  if(prev_calculated==0) {
    ArrayInitialize(Buffer1,EMPTY_VALUE);
    ArrayInitialize(Buffer2,EMPTY_VALUE);
  }
  if(rates_total-prev_calculated==1) {
    Buffer1[H+1]=EMPTY_VALUE;
    Buffer2[H+1]=EMPTY_VALUE;
  }
  double b=SymbolInfoDouble(Symbol(),SYMBOL_BID);
  double a=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  Buffer1[0]=b;
  Buffer2[0]=a;
  for(int j=H; j>0; j--) {
    Buffer1[j]=Buffer1[j-1];
    Buffer2[j]=Buffer2[j-1];
  }
  return(rates_total);
}
//+------------------------------------------------------------------+

---

Again, there is a loop inside ArrayCopy() and probably more than one. So the code will hardly become lighter and faster due to this replacement

 
Vitaly Muzichenko #:

Why do you first record the data and then shift it?

  Buffer1[0]=b;
  Buffer2[0]=a;
  for(int j=H; j>0; j--) {
    Buffer1[j]=Buffer1[j-1];
    Buffer2[j]=Buffer2[j-1];
  }

This does not correspond to the actual tick chart!

This is the right way to do it.

  for(int j=H; j>0; j--) {
    Buffer1[j]=Buffer1[j-1];
    Buffer2[j]=Buffer2[j-1];
  }
  Buffer1[0]=b;
  Buffer2[0]=a;
 
Vitaly Muzichenko #:

Again, there is a loop inside ArrayCopy() and probably more than one. So the code will hardly become simpler and faster due to this replacement.

I've already said it many times above: you cannot do without a loop!

 
Mihail Matkovskij #:

Why do you first record the data and then shift it?

This does not correspond to the actual tick chart!

This is the right way to do it.

kasher of course, but the same).

Yes, and a short cycle of up to 1000 iterations with a couple of assignment comparisons is easy. so it shouldn't be daunting.

 
EVGENII SHELIPOV #:

A fractal is formed if there is no new extremum and after three bars those 0, 1, 2.

Nothing has changed.

Or something is wrong again

Run the fractal indicator on D1 and see if the fractal is there or not.
Reason: