Self-learning the MQL5 language from scratch - page 81

 
Alexey Viktorov #:

I really hope you didn't write this...

Here's a working function

All you have to do is enter the size of the risk, so that it doesn't count from the full free margin...

Thanks, Alexey, for your feedback! My version of lot calculation works, and only that part of the code where the array is written does not work.

Originally I designed it to be able to set different risk sizes for different currency pairs.

To be honest, I do not quite understand how to use your code for a multicurrency EA.

Regards, Vladimir.

 
MrBrooklin #:

Thank you, Alexey, for your feedback! The lot calculation in my version works, and only that part of the code, where the array is written, doesn't work.

It was originally designed to allow specifying different risk sizes for different currency pairs.

To be honest, I do not quite understand how to use your code for a multicurrency EA.

Sincerely, Vladimir.

Very simple. I didn't think that you would have difficulties with it after all you've learned.

/********************************************************************\
|   Calculate optimal lot size     Расчет объема лота                |
/********************************************************************/
//double contractSize(double Lot)
double contractSize(string symbol, double risk)
 {
//  double volume = Lot > 0.0 ? Lot : AccountInfoDouble(ACCOUNT_MARGIN_FREE)/10000,
  double volume = AccountInfoDouble(ACCOUNT_MARGIN_FREE)*risk/10000,
         v = volume,
         volumeStep = SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP),
         minLot = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN),
         maxLot = SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX);
  v = round(volume/volumeStep)*volumeStep;
  return(fmin(maxLot, fmax(minLot, v)));
 }/******************************************************************/

And the function is called

double lot = contractSize(symbol[Number], Risk[Number]);
 
Alexey Viktorov #:

Very simple. I didn't think, after all you've learned, that you'd have any trouble with this...

And the function is called.

Thanks again, Alexey! I will try to use it in my EA tonight.

I am rather new to arrays, hence the difficulties. Until now I did not need them, but now I realize that this is a big gap that I will have to fill in the near future. I began to study the article by Dmitry Fedoseyev, but so far there is much that is not clear. I need time to assimilate the material.

Regards, Vladimir.

 
SanAlex #:

Here's something I've been messing with.

Maybe you should get the gist of it first.
 
SanAlex #:

something - I've tried the code all over the place - it seems to work.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

It's about to start - I've got another bump in the road.

Sasha, do you also write such codes on demand in freelancing? I've always wondered how you write codes of 2 or more THOUSANDS of lines. But now I'm beginning to understand it... Calculate the number of lines in my code and yours... And checking the maximum spread, it's nonsense... It's much easier to use the "I don't know" option.

  MqlTick tick;
    if(!SymbolInfoTick(posSymbol, tick))
      return;
    if(tick.ask-tick.bid > inpSpred)
      return;

If you want it to work, but not everyone is able to understand what you've written, you can do with three lines

  MqlTick tick;
    if(!SymbolInfoTick(posSymbol, tick) || tick.ask-tick.bid > inpSpred)
      return;
 
SanAlex #:

this code is taken from the terminal

Keep up the good work.
 
SanAlex #:

I don't know how to write code myself - I take all functions from the documentation and with a bit of fiddling, I modify them for my own purposes.

\\\\\\\\\\\\\\\\\\\\

I also look at your codes and in the codebase. I am learning - I am not a theoretician - it is easier to dig myself than to explain - how to dig.

It's already clear that you can only dig. Why put the codes here?
 
SanAlex #:

just to - just to amuse you.

Who else are you going to ask your clever questions to?

They gave you ten years for a reason.
 
SanAlex #:

Leave the Gulf of Finland and come to the Black Sea with us

I'm in Kaliningrad actually
 
SanAlex #:

Leave the Gulf of Finland and come to the Black Sea with us