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

 
Andrey Sokolov #:

Thank you. Does this not only work in indicators, but also in robots?

I don't know your problem, but it flips the array

 
Vitaly Muzichenko #:

I don't know your problem, but it flips the array

We need indexes in the array to coincide with the shift value relative to the current bar, like inindicator buffers.

You need the index values to match the candlesticks after the appearance of new candlesticks, like in indicators.

 
Andrey Sokolov #:

We need indexes in the array to coincide with the shift value relative to the current bar, like inindicator buffers.

You need to get the index values to match the candlesticks after the appearance of new candlesticks, like in indicators.

Try it, it should work

 
Vitaly Muzichenko #:

Try it, it should work.

It doesn't work like this. I write 300 in index 0, when a new candlestick appears it should be 300 in index 1, but no.

#property strict

int bars;
double arr[];

int OnInit()//////////////***OnInit()****///*************OnInit()*******/////////***/////////////////////OnInit()
{
   Comment("");
   
   bars = Bars(NULL, 0);
   bool series = ArraySetAsSeries(arr, true);
   int size = ArraySize(arr);
   int res = ArrayResize(arr, bars);
   arr[0] = 300;

   return(INIT_SUCCEEDED);
}//+------------------------------------------------------------------+
void OnDeinit(const int reason)//////////////**////////*OnDeinit()****////////////////////*************OnDeinit()
{       
        Comment("");  
}//+------------------------------------------------------------------+
void OnTick()//////////////***OnTick()****///*************OnTick()**********/////////////////////////////OnTick()
{
   if(bars!=Bars(NULL, 0))
   {
        bars=Bars(NULL, 0);
        int res = ArrayResize(arr, bars);
   }
   
   Comment(TimeCurrent(), "  ", bars, "  ", arr[0], "  ", arr[1], "  ", arr[2], "  " , arr[3]);
}//+------------------------------------------------------------------+

I can write myself "displacement" of the whole array in the loop at new candlesticks, but the language for working with charts, probably, there is something standard.

 
Andrey Sokolov #:

it doesn't work like this. I write 300 in the index 0, when a new candle appears it should be 300 in the index 1, but it is not.

I can write myself "displacement" of the whole array in the loop at new candlesticks, but in the language for working with charts, probably, there is something standard.

It flips, but there's no point.

#property strict

int bars;
double arr[]={};

int OnInit()//////////////***OnInit()****///*************OnInit()*******/////////***/////////////////////OnInit()
{
   Comment("");
   
   bars = Bars(NULL, 0);
   int size = ArraySize(arr);
   int res = ArrayResize(arr, bars);
   arr[res-1] = 300;
   ArraySetAsSeries(arr, true);
   return(INIT_SUCCEEDED);
}//+------------------------------------------------------------------+
void OnDeinit(const int reason)//////////////**////////*OnDeinit()****////////////////////*************OnDeinit()
{       
        Comment("");  
}//+------------------------------------------------------------------+
void OnTick()//////////////***OnTick()****///*************OnTick()**********/////////////////////////////OnTick()
{
static int res;
   if(bars!=Bars(NULL, 0))
   {
        bars=Bars(NULL, 0);
        res = ArrayResize(arr, bars);
   }
   
   Print(res, "  ", arr[0], "  ", arr[1], "  ", arr[2]);
}//+------------------------------------------------------------------+

It needs to be filled in another way

 
Andrey Sokolov #:

it doesn't work like this. I write 300 in the index 0, when a new candle appears it should be 300 in the index 1, but it is not.

I can write myself "displacement" of the whole array in the loop at new candlesticks, but in the language for working with charts, probably, there is something standard.

Yes, there is a standard one... Add to the array and remove from the array. The array should be dynamic. Look in the documentation for more details, I don't remember how they are written...

 
Vitaly Muzichenko #:

Turns it over, but there is no point

It needs to be filled in another way

does not work


 
Alexey Viktorov #:

Yes, there is a regular one... Add to array and remove from array. The array has to be dynamic. Look in the documentation for more details, I can't remember how they are written...

(May someone remember?))

 
Andrey Sokolov #:

(Who can remember?))

Something about arrays

 
Vitaly Muzichenko #:

Something on arrays

👍