Features of the mql5 language, subtleties and tricks - page 266

 
Aleksey Vyazmikin #:

That's what I'm trying to understand - what's the point in increasing the array on demand, if you can immediately set the maximum required in the current situation...

You seem to be an accountant, I'll try to rephrase it in your language.
What's the point of taking out loans on demand if you can take out a big one for life.
 
Aleksei Beliakov #:
You seem to be an accountant, I'll try to rephrase it in your language.
What's the point of taking out loans when you can take out a big one for life?

You're an accountant? What makes you think you can get into another professional field and explain something there?

We are talking about programming here in the thread, so try to come up with your own example in the form of code - it will be more productive.

 
Aleksey Vyazmikin #:

That's what I'm trying to understand - what's the point in increasing the array on demand, if you can immediately set the maximum required in the current situation...

And what if you don't know what size array is required?

Example:

You fill the array with zeros and search the filled part until you encounter 0. But if the array is enlarged as needed, the loop will be terminated when the last element of the array is reached. Everything is clear...

 
Alexey Viktorov #:
And if you don't know what size array you need?

Then there's really no other way. I just haven't come across it.

In general, I see the sense when it is an EA code and using a large array is a rare event, then if you use a dozen EAs at once, you have a chance to execute the code with less memory than it would be required when allocating the maximum memory. And to the same topic - before creating a large array, wait in the code until the required amount of memory is freed. In general, the script is specific and it is more suitable for advisors or for those who make heavy calculations with scripts, running several of them at once on different charts.

 
Aleksey Vyazmikin #:

Then there's really no other way. I just haven't come across it.

In general, I see the sense when it is an EA code and using a large array is a rare event, then if a dozen EAs are used at once, there is a chance to execute the code with less memory than it would be required when allocating maximum memory. And to the same topic - before creating a large array, wait in the code until the required amount of memory is freed. In general, the script is specific and it is more suitable for advisors or for those who make heavy calculations with scripts, running several of them at once on different charts.

I almost always deal with large arrays (dozens of Mb), and, moreover, initially with an unknown size.
In the near future, I think, we will have to switch to ticks, and this is hundreds of Mb, and even, perhaps, gigabytes.
The third parameter in ArrayResize makes life much easier.
 
Now #-translate to string does not remove spaces.

Forum on trading, automated trading systems and testing trading strategies

What to do when spreads widen like this?

fxsaber, 2024.06.25 22:17

#define  PRINT(A) Print(#A + " = " + (string)(A))

void OnStart()
{
  // (1.46483 * 0.1 + 1.46484 * 1.0) / (1.0 + 0.1) =  1.4648390909090907
  PRINT((1.46483 * 0.1 + 1.46484 * 1.0) / (1.0 + 0.1));
}

Be careful, you can get caught in cross-platform code.

 

Trade server builds later than 12.06.2024 (e.g. b4410) fill the second byte of MqlTick.flags ticks(SymbolInfoTick and CopyTicks*).


void OnStart()
{
  MqlTick Ticks[];
  
  const int Amount = CopyTicksRange(_Symbol, Ticks, COPY_TICKS_ALL, D'2024.06.01' * 1000);
  
  Print(AccountInfoString(ACCOUNT_SERVER)); // MetaQuotes-Demo
  
  for (int i = 0; i < Amount; i++ )
    if ((bool)(Ticks[i].flags >> 8))
    {
      //  time = 2024.06.12 15:52:50.286 bid = 1.08241 ask = 1.08241 last = 0.00000 volume = 0 
      Print(Ticks[i].time);

      // 1158 TICK_FLAG_BID TICK_FLAG_ASK FLAG_UNKNOWN (1152)
      Print(Ticks[i].flags);

      break;
    }
}
 
Hello All, since you all are experts in here, i am just a beginner, i wanna ask what function do I use or even is it possible to code for lookback 5 candlestick see if condition has met then print a arrow? tks.
 

Today I suddenly found out that ME has such a clipboard.

Copying as usual by Ctrl+c and pasting by Alt+v and selecting the necessary....

I don't know how many things can be stored there. I thought it was 10, but I typed 11 and stopped.

 

In MM calculations, consider this possibility.